diff --git a/api/filters/annotations/annotations_test.go b/api/filters/annotations/annotations_test.go index ee895ef9c..3f4fb9562 100644 --- a/api/filters/annotations/annotations_test.go +++ b/api/filters/annotations/annotations_test.go @@ -150,6 +150,42 @@ metadata: "2": "ford", }}, }, + + // test quoting of values which are not considered strings in yaml 1.1 + "yaml_1_1_compatibility": { + input: ` +apiVersion: example.com/v1 +kind: Foo +metadata: + name: instance + annotations: + hero: batman + fiend: riddler +`, + expectedOutput: ` +apiVersion: example.com/v1 +kind: Foo +metadata: + name: instance + annotations: + hero: batman + fiend: riddler + a: "y" + b: y1 + c: "yes" + d: yes1 + e: "true" + f: true1 +`, + filter: Filter{Annotations: annoMap{ + "a": "y", + "b": "y1", + "c": "yes", + "d": "yes1", + "e": "true", + "f": "true1", + }}, + }, } for tn, tc := range testCases { diff --git a/api/filters/fsslice/fsslice.go b/api/filters/fsslice/fsslice.go index 5c171a90b..e783c2860 100644 --- a/api/filters/fsslice/fsslice.go +++ b/api/filters/fsslice/fsslice.go @@ -20,14 +20,18 @@ func SetScalar(value string) SetFn { // SetEntry returns a SetFn to set an entry in a map func SetEntry(key, value, tag string) SetFn { + n := &yaml.Node{ + Kind: yaml.ScalarNode, + Value: value, + Tag: tag, + } + if tag == yaml.StringTag && yaml.IsYaml1_1NonString(n) { + n.Style = yaml.DoubleQuotedStyle + } return func(node *yaml.RNode) error { return node.PipeE(yaml.FieldSetter{ - Name: key, - Value: yaml.NewRNode(&yaml.Node{ - Kind: yaml.ScalarNode, - Value: value, - Tag: tag, - }), + Name: key, + Value: yaml.NewRNode(n), }) } diff --git a/api/filters/labels/labels_test.go b/api/filters/labels/labels_test.go index 878655406..46ffd3233 100644 --- a/api/filters/labels/labels_test.go +++ b/api/filters/labels/labels_test.go @@ -326,6 +326,50 @@ metadata: }, }, }, + + // test quoting of values which are not considered strings in yaml 1.1 + "yaml_1_1_compatibility": { + input: ` +apiVersion: example.com/v1 +kind: Foo +metadata: + name: instance + labels: + hero: batman + fiend: riddler +`, + expectedOutput: ` +apiVersion: example.com/v1 +kind: Foo +metadata: + name: instance + labels: + hero: batman + fiend: riddler + a: "y" + b: y1 + c: "yes" + d: yes1 + e: "true" + f: true1 +`, + filter: Filter{ + Labels: labelMap{ + "a": "y", + "b": "y1", + "c": "yes", + "d": "yes1", + "e": "true", + "f": "true1", + }, + FsSlice: []types.FieldSpec{ + { + Path: "metadata/labels", + CreateIfNotPresent: true, + }, + }, + }, + }, } for tn, tc := range testCases {