From 54db9785d65d8a9dfc78d1cf230810b19f1abffb Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Thu, 15 Nov 2018 13:49:23 +0100 Subject: feat(main): Support specifying kubectl args in ResourceSets --- context/context.go | 3 +++ context/context_test.go | 36 +++++++++++++++++++++++++++++++ context/testdata/flat-with-args-test.yaml | 9 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 context/testdata/flat-with-args-test.yaml (limited to 'context') diff --git a/context/context.go b/context/context.go index 49de7f46957a..314fc3584545 100644 --- a/context/context.go +++ b/context/context.go @@ -28,6 +28,9 @@ type ResourceSet struct { // Values to include when interpolating resources from this resource set. Values map[string]interface{} `json:"values"` + // Args to pass on to kubectl for this resource set. + Args []string `json:"args"` + // Nested resource sets to include Include []ResourceSet `json:"include"` diff --git a/context/context_test.go b/context/context_test.go index 34c77cc9b7c6..d7fdc11e5718 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -54,6 +54,42 @@ func TestLoadFlatContextFromFile(t *testing.T) { } } +func TestLoadContextWithArgs(t *testing.T) { + ctx, err := LoadContext("testdata/flat-with-args-test.yaml", &noExplicitVars) + + if err != nil { + t.Error(err) + t.Fail() + } + + expected := Context{ + Name: "k8s.prod.mydomain.com", + ResourceSets: []ResourceSet{ + { + Name: "some-api", + Path: "some-api", + Values: make(map[string]interface{}, 0), + Args: []string{ + "--as=some-user", + "--as-group=hello:world", + "--as-banana", + "true", + }, + Include: nil, + Parent: "", + }, + }, + BaseDir: "testdata", + ImportedVars: make(map[string]interface{}, 0), + ExplicitVars: make(map[string]interface{}, 0), + } + + if !reflect.DeepEqual(*ctx, expected) { + t.Error("Loaded context and expected context did not match") + t.Fail() + } +} + func TestLoadContextWithResourceSetCollections(t *testing.T) { ctx, err := LoadContext("testdata/collections-test.yaml", &noExplicitVars) diff --git a/context/testdata/flat-with-args-test.yaml b/context/testdata/flat-with-args-test.yaml new file mode 100644 index 000000000000..29d3334fb54d --- /dev/null +++ b/context/testdata/flat-with-args-test.yaml @@ -0,0 +1,9 @@ +--- +context: k8s.prod.mydomain.com +include: + - name: some-api + args: + - --as=some-user + - --as-group=hello:world + - --as-banana + - "true" -- cgit 1.4.1