@@ -11,6 +11,8 @@ import (
11
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
12
"k8s.io/apimachinery/pkg/util/wait"
13
13
elbv2api "sigs.k8s.io/aws-load-balancer-controller/apis/elbv2/v1beta1"
14
+ "sigs.k8s.io/aws-load-balancer-controller/pkg/algorithm"
15
+ "sigs.k8s.io/aws-load-balancer-controller/pkg/annotations"
14
16
"sigs.k8s.io/aws-load-balancer-controller/pkg/deploy/tracking"
15
17
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
16
18
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
@@ -68,12 +70,18 @@ func (m *defaultTargetGroupBindingManager) Create(ctx context.Context, resTGB *e
68
70
return elbv2model.TargetGroupBindingResourceStatus {}, err
69
71
}
70
72
71
- stackLabels := m .trackingProvider .StackLabels (resTGB .Stack ())
73
+ labels := m .trackingProvider .StackLabels (resTGB .Stack ())
74
+
75
+ if resTGB .Spec .Template .Labels != nil {
76
+ labels = algorithm .MergeStringMap (labels , resTGB .Spec .Template .Labels )
77
+ }
78
+
72
79
k8sTGB := & elbv2api.TargetGroupBinding {
73
80
ObjectMeta : metav1.ObjectMeta {
74
- Namespace : resTGB .Spec .Template .Namespace ,
75
- Name : resTGB .Spec .Template .Name ,
76
- Labels : stackLabels ,
81
+ Namespace : resTGB .Spec .Template .Namespace ,
82
+ Name : resTGB .Spec .Template .Name ,
83
+ Annotations : resTGB .Spec .Template .Annotations ,
84
+ Labels : labels ,
77
85
},
78
86
Spec : k8sTGBSpec ,
79
87
}
@@ -96,16 +104,30 @@ func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *e
96
104
if err != nil {
97
105
return elbv2model.TargetGroupBindingResourceStatus {}, err
98
106
}
99
- if equality .Semantic .DeepEqual (k8sTGB .Spec , k8sTGBSpec ) {
107
+
108
+ calculatedLabels := m .trackingProvider .StackLabels (resTGB .Stack ())
109
+
110
+ if resTGB .Spec .Template .Labels != nil {
111
+ calculatedLabels = algorithm .MergeStringMap (calculatedLabels , resTGB .Spec .Template .Labels )
112
+ }
113
+
114
+ specSame := equality .Semantic .DeepEqual (k8sTGB .Spec , k8sTGBSpec )
115
+ labelsSame := equality .Semantic .DeepEqual (k8sTGB .Labels , calculatedLabels )
116
+ annotationsSame := tgbAnnotationsSame (resTGB , k8sTGB )
117
+
118
+ if specSame && labelsSame && annotationsSame {
100
119
return buildResTargetGroupBindingStatus (k8sTGB ), nil
101
120
}
102
121
103
122
oldK8sTGB := k8sTGB .DeepCopy ()
104
123
k8sTGB .Spec = k8sTGBSpec
124
+ k8sTGB .Annotations = resTGB .Spec .Template .Annotations
125
+ k8sTGB .Labels = calculatedLabels
105
126
m .logger .Info ("modifying targetGroupBinding" ,
106
127
"stackID" , resTGB .Stack ().StackID (),
107
128
"resourceID" , resTGB .ID (),
108
129
"targetGroupBinding" , k8s .NamespacedName (k8sTGB ))
130
+
109
131
if err := m .k8sClient .Patch (ctx , k8sTGB , client .MergeFrom (oldK8sTGB )); err != nil {
110
132
return elbv2model.TargetGroupBindingResourceStatus {}, err
111
133
}
@@ -116,6 +138,7 @@ func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *e
116
138
"stackID" , resTGB .Stack ().StackID (),
117
139
"resourceID" , resTGB .ID (),
118
140
"targetGroupBinding" , k8s .NamespacedName (k8sTGB ))
141
+
119
142
return buildResTargetGroupBindingStatus (k8sTGB ), nil
120
143
}
121
144
@@ -242,3 +265,17 @@ func buildResTargetGroupBindingStatus(k8sTGB *elbv2api.TargetGroupBinding) elbv2
242
265
},
243
266
}
244
267
}
268
+
269
+ // tgbAnnotationsSame performs map equality with the two sets of annotations. Will ignore the check point annotations inserted by the TGB reconciler.
270
+ func tgbAnnotationsSame (resTGB * elbv2model.TargetGroupBindingResource , k8sTGB * elbv2api.TargetGroupBinding ) bool {
271
+ annotationsNoCheckpoint := make (map [string ]string )
272
+
273
+ if k8sTGB .Annotations != nil {
274
+ for k , v := range k8sTGB .Annotations {
275
+ if k != annotations .AnnotationCheckPointTimestamp && k != annotations .AnnotationCheckPoint {
276
+ annotationsNoCheckpoint [k ] = v
277
+ }
278
+ }
279
+ }
280
+ return equality .Semantic .DeepEqual (annotationsNoCheckpoint , resTGB .Spec .Template .Annotations )
281
+ }
0 commit comments