diff --git a/api/filters/annotations/example_test.go b/api/filters/annotations/example_test.go index 270193496..75eb51314 100644 --- a/api/filters/annotations/example_test.go +++ b/api/filters/annotations/example_test.go @@ -28,7 +28,9 @@ metadata: `)}}, Filters: []kio.Filter{Filter{ Annotations: map[string]string{ - "foo": "bar", + "foo": "bar", + "booleanValue": "true", + "numberValue": "42", }, FsSlice: fss, }}, @@ -44,12 +46,16 @@ metadata: // metadata: // name: instance // annotations: + // booleanValue: "true" // foo: bar + // numberValue: "42" // --- // apiVersion: example.com/v1 // kind: Bar // metadata: // name: instance // annotations: + // booleanValue: "true" // foo: bar + // numberValue: "42" } diff --git a/api/krusty/basic_io_test.go b/api/krusty/basic_io_test.go index 9700ec41a..1ed567605 100644 --- a/api/krusty/basic_io_test.go +++ b/api/krusty/basic_io_test.go @@ -4,7 +4,6 @@ package krusty_test import ( - "fmt" "testing" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" @@ -28,7 +27,8 @@ func TestBasicIO_1(t *testing.T) { // return an error (that is then ignored by GetAnnotations) // } // The error happens when any annotation value can be interpreted as - // a boolean or number. + // a boolean or number. Such annotations cannot be successfully applied + // to an object in a cluster unless they are quoted. t.SkipNow() } th.WriteK(".", ` @@ -49,6 +49,7 @@ spec: `) m := th.Run(".", opts) // The annotations are sorted by key, hence the order change. + // Quotes are added intentionally. th.AssertActualEqualsExpected( m, ` apiVersion: v1 @@ -56,8 +57,8 @@ kind: Service metadata: annotations: color: green - happy: true - port: 8080 + happy: "true" + port: "8080" name: demo spec: clusterIP: None @@ -71,9 +72,7 @@ func TestBasicIO_2(t *testing.T) { resources: - service.yaml `) - // All the annotation values are quoted. - // The apimachinery code path retains the quotes, the kyaml - // path drops them at the moment. + // All the annotation values are quoted in the input. th.WriteF("service.yaml", ` apiVersion: v1 kind: Service @@ -88,20 +87,16 @@ spec: `) m := th.Run(".", opts) // The annotations are sorted by key, hence the order change. - expFmt := ` + th.AssertActualEqualsExpected(m, ` apiVersion: v1 kind: Service metadata: annotations: color: green - happy: %s - port: %s + happy: "true" + port: "8080" name: demo spec: clusterIP: None -` - th.AssertActualEqualsExpected( - m, opts.IfApiMachineryElseKyaml( - fmt.Sprintf(expFmt, `"true"`, `"8080"`), - fmt.Sprintf(expFmt, `true`, `8080`))) +`) } diff --git a/api/krusty/fnplugin_test.go b/api/krusty/fnplugin_test.go index 97aa4b153..b45316a23 100644 --- a/api/krusty/fnplugin_test.go +++ b/api/krusty/fnplugin_test.go @@ -1,7 +1,6 @@ package krusty_test import ( - "fmt" "os/exec" "testing" @@ -129,9 +128,8 @@ stringData: bootcmd: - mkdir /mnt/vda `) - opts := th.MakeOptionsPluginsEnabled() - m := th.Run("/app", opts) - expFmt := ` + m := th.Run("/app", th.MakeOptionsPluginsEnabled()) + th.AssertActualEqualsExpected(m, ` apiVersion: v1 kind: Secret metadata: @@ -154,7 +152,7 @@ metadata: name: demo name: demo-budget spec: - minAvailable: 67%% + minAvailable: 67% selector: matchLabels: app: cockroachdb @@ -187,7 +185,9 @@ metadata: annotations: config.kubernetes.io/path: config/demo_service.yaml prometheus.io/path: _status/vars -%s + prometheus.io/port: "8080" + prometheus.io/scrape: "true" + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" labels: app: cockroachdb name: demo @@ -244,7 +244,7 @@ spec: - /bin/bash - -ecx - | - # The use of qualified ` + "`hostname -f`" + ` is crucial: + # The use of qualified `+"`hostname -f`"+` is crucial: # Other nodes aren't able to look up the unqualified hostname. CRARGS=("start" "--logtostderr" "--insecure" "--host" "$(hostname -f)" "--http-host" "0.0.0.0") # We only want to initialize a new cluster (by omitting the join flag) @@ -302,14 +302,7 @@ spec: resources: requests: storage: 1Gi -` - th.AssertActualEqualsExpected(m, opts.IfApiMachineryElseKyaml( - fmt.Sprintf(expFmt, ` prometheus.io/port: "8080" - prometheus.io/scrape: "true" - service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"`), - fmt.Sprintf(expFmt, ` prometheus.io/port: 8080 - prometheus.io/scrape: true - service.alpha.kubernetes.io/tolerate-unready-endpoints: true`))) +`) } func TestFnContainerTransformer(t *testing.T) { diff --git a/api/krusty/variableref_test.go b/api/krusty/variableref_test.go index 41b55ffcf..e2c95591d 100644 --- a/api/krusty/variableref_test.go +++ b/api/krusty/variableref_test.go @@ -757,9 +757,9 @@ kind: Service metadata: annotations: prometheus.io/path: _status/vars - prometheus.io/port: %s - prometheus.io/scrape: %s - service.alpha.kubernetes.io/tolerate-unready-endpoints: %s + prometheus.io/port: "8080" + prometheus.io/scrape: "true" + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" labels: app: cockroachdb name: dev-base-cockroachdb @@ -929,12 +929,8 @@ metadata: ` th.AssertActualEqualsExpected(m, opts.IfApiMachineryElseKyaml( - fmt.Sprintf( - expFmt, - `"8080"`, `"true"`, `"true"`, `8080`, `8080`, `8080`, `8080`), - fmt.Sprintf( - expFmt, - `8080`, `true`, `true`, `"8080"`, `"8080"`, `"8080"`, `"8080"`), + fmt.Sprintf(expFmt, `8080`, `8080`, `8080`, `8080`), + fmt.Sprintf(expFmt, `"8080"`, `"8080"`, `"8080"`, `"8080"`), )) }