Skip to content

Commit be20318

Browse files
committed
secret-labels-annotations-comparison
1 parent b039190 commit be20318

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

pkg/k8s/secrets.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,35 @@ func EnsureSecretExist(ctx context.Context, secret corev1.Secret, namespaceOverr
120120
secretNotFound = true
121121
}
122122

123-
// TODO we should also compare labels and annotations
124-
if secretNotFound || !equality.Semantic.DeepDerivative(existingSecret.Data, secret.Data) {
125-
// Decide whether create or update
123+
labelsEqual := true
124+
annotationsEqual := true
125+
dataEqual := true
126+
127+
if !secretNotFound {
128+
dataEqual = equality.Semantic.DeepDerivative(existingSecret.Data, secret.Data)
129+
130+
existingLabels := existingSecret.Labels
131+
if existingLabels == nil {
132+
existingLabels = map[string]string{}
133+
}
134+
desiredLabels := secret.Labels
135+
if desiredLabels == nil {
136+
desiredLabels = map[string]string{}
137+
}
138+
labelsEqual = equality.Semantic.DeepEqual(existingLabels, desiredLabels)
139+
140+
existingAnnotations := existingSecret.Annotations
141+
if existingAnnotations == nil {
142+
existingAnnotations = map[string]string{}
143+
}
144+
desiredAnnotations := secret.Annotations
145+
if desiredAnnotations == nil {
146+
desiredAnnotations = map[string]string{}
147+
}
148+
annotationsEqual = equality.Semantic.DeepEqual(existingAnnotations, desiredAnnotations)
149+
}
150+
151+
if secretNotFound || !dataEqual || !labelsEqual || !annotationsEqual {
126152
if secretNotFound {
127153
_, err = client.CoreV1().Secrets(namespace).Create(ctx, &secret, metav1.CreateOptions{})
128154
} else {

0 commit comments

Comments
 (0)