Merge pull request #2487 from pwittrock/master

Quote yaml 1.1 non-string values for commonlabels and commonAnnotations
This commit is contained in:
Kubernetes Prow Robot
2020-05-14 19:54:59 -07:00
committed by GitHub
3 changed files with 90 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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),
})
}

View File

@@ -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 {