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

@@ -44,6 +44,7 @@ func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
FsSlice: ns.FsSlice,
SetValue: fsslice.SetScalar(ns.Namespace),
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
CreateTag: yaml.StringTag,
})
return node, err
}

View File

@@ -44,6 +44,37 @@ metadata:
filter: namespace.Filter{Namespace: "foo"},
},
{
name: "null_ns",
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
namespace: null
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
namespace: null
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
namespace: foo
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
namespace: foo
`,
filter: namespace.Filter{Namespace: "foo"},
},
{
name: "add-recurse",
input: `