Set common labels and annotations as strings

This commit is contained in:
Phillip Wittrock
2020-05-13 16:52:44 -07:00
parent 0a8d367633
commit 0866e2a54b
5 changed files with 73 additions and 4 deletions

View File

@@ -31,7 +31,7 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
for _, k := range keys {
if err := node.PipeE(fsslice.Filter{
FsSlice: f.FsSlice,
SetValue: fsslice.SetEntry(k, f.Labels[k]),
SetValue: fsslice.SetEntry(k, f.Labels[k], yaml.StringTag),
CreateKind: yaml.MappingNode, // Labels are MappingNodes.
}); err != nil {
return nil, err

View File

@@ -291,6 +291,41 @@ metadata:
},
},
},
"number": {
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
1: emmett kelley
auto: "2"
`,
filter: Filter{
Labels: labelMap{
"1": "emmett kelley",
"auto": "2",
},
FsSlice: []types.FieldSpec{
{
Path: "metadata/labels",
CreateIfNotPresent: true,
},
},
},
},
}
for tn, tc := range testCases {