@@ -17,6 +17,15 @@ import (
1717 certsdk "github.com/stackitcloud/stackit-sdk-go/services/certificates/v2api"
1818)
1919
20+ const (
21+ // prefixCustomerLabel is the api prefix for all custom labels
22+ prefixCustomerLabel = "lb.customer.label/"
23+
24+ // LabelIngressClassUID is the unique key that identifies resources
25+ // owned by a specific IngressClass.
26+ LabelIngressClassUID = prefixCustomerLabel + "ingress-class-uid"
27+ )
28+
2029func (r * IngressClassReconciler ) getAlbSpecForIngressClass (ctx context.Context , class * networkingv1.IngressClass ) (* albsdk.CreateLoadBalancerPayload , []errorEvents , error ) {
2130 ingresses , err := r .getIngressesForIngressClass (ctx , class )
2231 if err != nil {
@@ -45,7 +54,7 @@ func (r *IngressClassReconciler) getAlbSpecForIngresses(ctx context.Context, cla
4554 errorList = append (errorList , listenerMergeError ... )
4655 }
4756
48- certNameToId , certificateErrorEvents := r .applyCertificates (ctx , certificates )
57+ certNameToId , certificateErrorEvents := r .applyCertificates (ctx , class , certificates )
4958 errorList = append (errorList , certificateErrorEvents ... )
5059
5160 alb , albSpecErrorList , err := r .getAlbSpecForResources (ctx , class , listeners , targetPools , certNameToId )
@@ -83,6 +92,28 @@ func (r *IngressClassReconciler) getAlbSpecForResources(ctx context.Context, cla
8392 alb .PlanId = & plan
8493 }
8594
95+ mergedLabels := make (map [string ]string )
96+
97+ // Add user labels, mind the limit
98+ for k , v := range class .Labels {
99+ if len (mergedLabels ) < 64 {
100+ mergedLabels [k ] = v
101+ }
102+ }
103+
104+ // Merge with existing global config labels
105+ if r .ALBConfig .ApplicationLoadBalancer .ExtraLabels != nil {
106+ for k , v := range r .ALBConfig .ApplicationLoadBalancer .ExtraLabels {
107+ if len (mergedLabels ) < 64 {
108+ mergedLabels [k ] = v
109+ }
110+ }
111+ }
112+
113+ // Add ownership label
114+ mergedLabels [LabelIngressClassUID ] = string (class .UID )
115+ alb .Labels = & mergedLabels
116+
86117 for port , listener := range listeners {
87118 albsdkListener := albsdk.Listener {
88119 Http : nil ,
@@ -379,7 +410,7 @@ func (r *IngressClassReconciler) getCertificateForSecretName(ctx context.Context
379410 }, nil
380411}
381412
382- func (r * IngressClassReconciler ) applyCertificates (ctx context.Context , certificates albCertificates ) (map [string ]string , []errorEvents ) {
413+ func (r * IngressClassReconciler ) applyCertificates (ctx context.Context , class * networkingv1. IngressClass , certificates albCertificates ) (map [string ]string , []errorEvents ) {
383414 errorList := []errorEvents {}
384415 nameToID := map [string ]string {}
385416 for name , certificate := range certificates {
@@ -388,6 +419,9 @@ func (r *IngressClassReconciler) applyCertificates(ctx context.Context, certific
388419 ProjectId : & r .ALBConfig .Global .ProjectID ,
389420 PrivateKey : new (string (certificate.privateKey )),
390421 PublicKey : new (string (certificate.publicKey )),
422+ Labels : & map [string ]string {
423+ LabelIngressClassUID : string (class .UID ),
424+ },
391425 }
392426 response , err := r .CertificateClient .CreateCertificate (ctx , r .ALBConfig .Global .ProjectID , r .ALBConfig .Global .Region , createCertificatePayload )
393427 if err != nil {
0 commit comments