From c107d1ddfff9a27c37b2022720214dff0ebfce0e Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Sat, 20 Jun 2020 23:18:26 -0700 Subject: [PATCH] List setters should not alter resources Remove Dryrun flag --- .../internal/commands/cmdlistsetters_test.go | 48 +++++++++++++++++++ kyaml/setters2/list.go | 2 + 2 files changed, 50 insertions(+) diff --git a/cmd/config/internal/commands/cmdlistsetters_test.go b/cmd/config/internal/commands/cmdlistsetters_test.go index 4a1fc20d6..bd3c307f8 100644 --- a/cmd/config/internal/commands/cmdlistsetters_test.go +++ b/cmd/config/internal/commands/cmdlistsetters_test.go @@ -7,6 +7,7 @@ import ( "bytes" "io/ioutil" "os" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -48,6 +49,32 @@ spec: replicas 3 me hello world 1 `, }, + + { + name: "list-replicas inconsistent with openapi", + openapi: ` +openAPI: + definitions: + io.k8s.cli.setters.replicas: + x-k8s-cli: + setter: + name: replicas + value: "4" + setBy: me + description: "hello world" + `, + input: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment +spec: + replicas: 3 # {"$ref": "#/definitions/io.k8s.cli.setters.replicas"} + `, + expected: ` NAME VALUE SET BY DESCRIPTION COUNT + replicas 4 me hello world 1 +`, + }, { name: "list-multiple", openapi: ` @@ -407,6 +434,27 @@ openAPI: if !assert.Equal(t, test.expected, actual.String()) { t.FailNow() } + + // make sure that the resources are not altered + actualResources, err := ioutil.ReadFile(r.Name()) + if !assert.NoError(t, err) { + t.FailNow() + } + if !assert.Equal(t, + strings.TrimSpace(test.input), + strings.TrimSpace(string(actualResources))) { + t.FailNow() + } + + actualOpenAPI, err := ioutil.ReadFile(f.Name()) + if !assert.NoError(t, err) { + t.FailNow() + } + if !assert.Equal(t, + strings.TrimSpace(test.openapi), + strings.TrimSpace(string(actualOpenAPI))) { + t.FailNow() + } }) } } diff --git a/kyaml/setters2/list.go b/kyaml/setters2/list.go index 0a15ded99..33e2906a2 100644 --- a/kyaml/setters2/list.go +++ b/kyaml/setters2/list.go @@ -181,6 +181,8 @@ func (l *List) listSubst(object *yaml.RNode) error { } // count returns the number of fields set by the setter with name +// set filter is leveraged for this but the resources are not written +// back to files as only LocalPackageReader is invoked and not writer func (l *List) count(path, name string) (int, error) { s := &Set{Name: name} err := kio.Pipeline{