kustomize transformers to create fields if they are null

This commit is contained in:
Phillip Wittrock
2020-05-15 12:30:59 -07:00
parent dd3a79bcf7
commit 77b5a4a215
11 changed files with 143 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
FsSlice: f.FsSlice,
SetValue: fsslice.SetEntry(k, f.Labels[k], yaml.StringTag),
CreateKind: yaml.MappingNode, // Labels are MappingNodes.
CreateTag: "!!map",
}); err != nil {
return nil, err
}

View File

@@ -370,6 +370,35 @@ metadata:
},
},
},
"null_labels": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
labels: null
`,
expectedOutput: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
labels:
a: a1
`,
filter: Filter{
Labels: labelMap{
"a": "a1",
},
FsSlice: []types.FieldSpec{
{
Path: "metadata/labels",
CreateIfNotPresent: true,
},
},
},
},
}
for tn, tc := range testCases {