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

@@ -39,6 +39,7 @@ func (rc Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
FsSlice: rc.FsSlice,
SetValue: rc.set,
CreateKind: yaml.ScalarNode, // replicas is a ScalarNode
CreateTag: yaml.IntTag,
})
return node, err
}

View File

@@ -61,6 +61,41 @@ spec:
expected: `
apiVersion: custom/v1
kind: Custom
metadata:
name: cus
spec:
template:
other: something
replicas: 42
`,
filter: Filter{
Replica: types.Replica{
Name: "cus",
Count: 42,
},
},
fsslice: types.FsSlice{
{
Path: "spec/template/replicas",
CreateIfNotPresent: true,
},
},
},
"add_field_null": {
input: `
apiVersion: custom/v1
kind: Custom
metadata:
name: cus
spec:
template:
other: something
replicas: null
`,
expected: `
apiVersion: custom/v1
kind: Custom
metadata:
name: cus
spec: