Skip to content

Commit 9cef44a

Browse files
committed
revert: drop backwards compatibility
Signed-off-by: Bence Csati <bcsati@cisco.com>
1 parent 0e10325 commit 9cef44a

File tree

4 files changed

+20
-53
lines changed

4 files changed

+20
-53
lines changed

e2e/deploy/workloads/daemonset.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ spec:
1515
secrets-webhook.security.bank-vaults.io/provider: "vault"
1616
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
1717
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
18-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
1918
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
2019
spec:
2120
initContainers:

pkg/reloader/controller.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ const (
3939

4040
SecretReloadAnnotationName = "secrets-reloader.security.bank-vaults.io/reload-on-secret-change"
4141
ReloadCountAnnotationName = "secrets-reloader.security.bank-vaults.io/secret-reload-count"
42-
43-
DeprecatedSecretReloadAnnotationName = "alpha.vault.security.banzaicloud.io/reload-on-secret-change"
44-
DeprecatedReloadCountAnnotationName = "alpha.vault.security.banzaicloud.io/secret-reload-count"
4542
)
4643

4744
// Controller is the controller implementation for Foo resources
@@ -160,7 +157,7 @@ func (c *Controller) handleObject(obj interface{}) {
160157
}
161158

162159
// Process workload, skip if reload annotation not present
163-
if shouldProcessWorkload(podTemplateSpec.Annotations) {
160+
if podTemplateSpec.GetAnnotations()[SecretReloadAnnotationName] != "true" {
164161
return
165162
}
166163
c.logger.Debug(fmt.Sprintf("Processing workload: %#v", workloadData))
@@ -207,13 +204,9 @@ func (c *Controller) handleObjectDelete(obj interface{}) {
207204
}
208205

209206
// Delete workload, skip if reload annotation not present
210-
if shouldProcessWorkload(podTemplateSpec.Annotations) {
207+
if podTemplateSpec.GetAnnotations()[SecretReloadAnnotationName] != "true" {
211208
return
212209
}
213210
c.logger.Debug(fmt.Sprintf("Deleting workload from store: %#v", workloadData))
214211
c.workloadSecrets.Delete(workloadData)
215212
}
216-
217-
func shouldProcessWorkload(annotations map[string]string) bool {
218-
return annotations[SecretReloadAnnotationName] == "true" || annotations[DeprecatedSecretReloadAnnotationName] == "true"
219-
}

pkg/reloader/reloader.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,14 @@ func (c *Controller) reloadWorkload(workload workload) error {
154154

155155
func incrementReloadCountAnnotation(podTemplate *corev1.PodTemplateSpec) {
156156
version := "1"
157-
annotationName := ReloadCountAnnotationName
158-
159-
// check for the current annotation
160-
reloadCount, currentExists := podTemplate.GetAnnotations()[ReloadCountAnnotationName]
161-
if !currentExists {
162-
// check for deprecated annotation
163-
if deprecatedReloadCount, deprecatedExists := podTemplate.GetAnnotations()[DeprecatedReloadCountAnnotationName]; deprecatedExists {
164-
annotationName = DeprecatedReloadCountAnnotationName
165-
reloadCount = deprecatedReloadCount
166-
}
167-
}
168157

169-
// parse and increment the reload count
170-
if reloadCount != "" {
158+
if reloadCount := podTemplate.GetAnnotations()[ReloadCountAnnotationName]; reloadCount != "" {
171159
count, err := strconv.Atoi(reloadCount)
172160
if err == nil {
173161
count++
174162
version = strconv.Itoa(count)
175163
}
176164
}
177165

178-
podTemplate.GetAnnotations()[annotationName] = version
166+
podTemplate.GetAnnotations()[ReloadCountAnnotationName] = version
179167
}

pkg/reloader/reloader_test.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,40 @@ import (
2525
func TestIncrementReloadCountAnnotation(t *testing.T) {
2626
tests := []struct {
2727
name string
28-
annotation string
29-
annotationValue string
30-
expectedAnnoation string
31-
expectedValue string
28+
annotations map[string]string
29+
expectedAnnoation map[string]string
3230
}{
3331
{
34-
name: "no annotation should use the ReloadCountAnnotationName",
35-
annotation: "",
36-
annotationValue: "",
37-
expectedAnnoation: ReloadCountAnnotationName,
38-
expectedValue: "1",
32+
name: "no annotation should add annotation",
33+
annotations: map[string]string{},
34+
expectedAnnoation: map[string]string{
35+
ReloadCountAnnotationName: "1",
36+
},
3937
},
4038
{
41-
name: "declared annotation should use the same annotation",
42-
annotation: ReloadCountAnnotationName,
43-
annotationValue: "1",
44-
expectedAnnoation: ReloadCountAnnotationName,
45-
expectedValue: "2",
46-
},
47-
{
48-
name: "deprecated annotation should use the same annotation",
49-
annotation: DeprecatedReloadCountAnnotationName,
50-
annotationValue: "1",
51-
expectedAnnoation: DeprecatedReloadCountAnnotationName,
52-
expectedValue: "2",
39+
name: "existing annotation should increment annotation",
40+
annotations: map[string]string{
41+
ReloadCountAnnotationName: "1",
42+
},
43+
expectedAnnoation: map[string]string{
44+
ReloadCountAnnotationName: "2",
45+
},
5346
},
5447
}
5548

5649
for _, tt := range tests {
5750
ttp := tt
5851
t.Run(ttp.name, func(t *testing.T) {
59-
annotations := map[string]string{}
60-
if ttp.annotation != "" {
61-
annotations[ttp.annotation] = ttp.annotationValue
62-
}
6352

6453
podTemplateSpec := &corev1.PodTemplateSpec{
6554
ObjectMeta: metav1.ObjectMeta{
66-
Annotations: annotations,
55+
Annotations: ttp.annotations,
6756
},
6857
}
6958

7059
incrementReloadCountAnnotation(podTemplateSpec)
7160

72-
annotationValue, ok := podTemplateSpec.Annotations[ttp.expectedAnnoation]
73-
assert.True(t, ok)
74-
assert.Equal(t, ttp.expectedValue, annotationValue)
61+
assert.Equal(t, ttp.expectedAnnoation, podTemplateSpec.Annotations)
7562
})
7663
}
7764
}

0 commit comments

Comments
 (0)