mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Quote yaml 1.1 non-string values for commonlabels and commonAnnotations
This commit is contained in:
@@ -150,6 +150,42 @@ metadata:
|
|||||||
"2": "ford",
|
"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 {
|
for tn, tc := range testCases {
|
||||||
|
|||||||
@@ -20,14 +20,18 @@ func SetScalar(value string) SetFn {
|
|||||||
|
|
||||||
// SetEntry returns a SetFn to set an entry in a map
|
// SetEntry returns a SetFn to set an entry in a map
|
||||||
func SetEntry(key, value, tag string) SetFn {
|
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 func(node *yaml.RNode) error {
|
||||||
return node.PipeE(yaml.FieldSetter{
|
return node.PipeE(yaml.FieldSetter{
|
||||||
Name: key,
|
Name: key,
|
||||||
Value: yaml.NewRNode(&yaml.Node{
|
Value: yaml.NewRNode(n),
|
||||||
Kind: yaml.ScalarNode,
|
|
||||||
Value: value,
|
|
||||||
Tag: tag,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
for tn, tc := range testCases {
|
||||||
|
|||||||
Reference in New Issue
Block a user