Skip to content

Commit ce69a18

Browse files
authored
Merge pull request #679 from weaveworks/feature/optimized-config-disabled
pkg/canary: add unit test of configIsDisabled and its optimization
2 parents b6d6f32 + 87c090a commit ce69a18

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pkg/canary/config_tracker.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type ConfigRefType string
3030
const (
3131
ConfigRefMap ConfigRefType = "configmap"
3232
ConfigRefSecret ConfigRefType = "secret"
33+
34+
configTrackingDisabledAnnotationKey = "flagger.app/config-tracking"
3335
)
3436

3537
// ConfigRef holds the reference to a tracked Kubernetes ConfigMap or Secret
@@ -52,12 +54,7 @@ func checksum(data interface{}) string {
5254
}
5355

5456
func configIsDisabled(annotations map[string]string) bool {
55-
for k, v := range annotations {
56-
if k == "flagger.app/config-tracking" && strings.HasPrefix(v, "disable") {
57-
return true
58-
}
59-
}
60-
return false
57+
return strings.HasPrefix(annotations[configTrackingDisabledAnnotationKey], "disable")
6158
}
6259

6360
// getRefFromConfigMap transforms a Kubernetes ConfigMap into a ConfigRef

pkg/canary/config_tracker_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
)
1212

13+
func TestConfigIsDisabled(t *testing.T) {
14+
for _, c := range []struct {
15+
annotations map[string]string
16+
exp bool
17+
}{
18+
{annotations: map[string]string{configTrackingDisabledAnnotationKey: "disable"}, exp: true},
19+
{annotations: map[string]string{"app": "disable"}, exp: false},
20+
{annotations: map[string]string{}, exp: false},
21+
} {
22+
assert.Equal(t, configIsDisabled(c.annotations), c.exp)
23+
}
24+
}
25+
1326
func TestConfigTracker_ConfigMaps(t *testing.T) {
1427
t.Run("deployment", func(t *testing.T) {
1528
mocks := newDeploymentFixture()

0 commit comments

Comments
 (0)