Skip to content

Commit 8ed0f0e

Browse files
authored
Merge pull request #4191 from zac-nixon/main
[feat gw api] add support for infra labels + annotations
2 parents 72b5b14 + 08058f8 commit 8ed0f0e

File tree

3 files changed

+551
-6
lines changed

3 files changed

+551
-6
lines changed

pkg/deploy/elbv2/target_group_binding_manager.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/util/wait"
1313
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"
1416
"sigs.k8s.io/aws-load-balancer-controller/pkg/deploy/tracking"
1517
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
1618
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
@@ -68,12 +70,18 @@ func (m *defaultTargetGroupBindingManager) Create(ctx context.Context, resTGB *e
6870
return elbv2model.TargetGroupBindingResourceStatus{}, err
6971
}
7072

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+
7279
k8sTGB := &elbv2api.TargetGroupBinding{
7380
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,
7785
},
7886
Spec: k8sTGBSpec,
7987
}
@@ -96,16 +104,30 @@ func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *e
96104
if err != nil {
97105
return elbv2model.TargetGroupBindingResourceStatus{}, err
98106
}
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 {
100119
return buildResTargetGroupBindingStatus(k8sTGB), nil
101120
}
102121

103122
oldK8sTGB := k8sTGB.DeepCopy()
104123
k8sTGB.Spec = k8sTGBSpec
124+
k8sTGB.Annotations = resTGB.Spec.Template.Annotations
125+
k8sTGB.Labels = calculatedLabels
105126
m.logger.Info("modifying targetGroupBinding",
106127
"stackID", resTGB.Stack().StackID(),
107128
"resourceID", resTGB.ID(),
108129
"targetGroupBinding", k8s.NamespacedName(k8sTGB))
130+
109131
if err := m.k8sClient.Patch(ctx, k8sTGB, client.MergeFrom(oldK8sTGB)); err != nil {
110132
return elbv2model.TargetGroupBindingResourceStatus{}, err
111133
}
@@ -116,6 +138,7 @@ func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *e
116138
"stackID", resTGB.Stack().StackID(),
117139
"resourceID", resTGB.ID(),
118140
"targetGroupBinding", k8s.NamespacedName(k8sTGB))
141+
119142
return buildResTargetGroupBindingStatus(k8sTGB), nil
120143
}
121144

@@ -242,3 +265,17 @@ func buildResTargetGroupBindingStatus(k8sTGB *elbv2api.TargetGroupBinding) elbv2
242265
},
243266
}
244267
}
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

Comments
 (0)