diff --git a/pkg/kinflate/commands/commands.go b/pkg/kinflate/commands/commands.go index 434bf9be3..378140a17 100644 --- a/pkg/kinflate/commands/commands.go +++ b/pkg/kinflate/commands/commands.go @@ -41,7 +41,7 @@ Find more information at: } c.AddCommand( - newCmdInflate(stdOut, stdErr), + newCmdInflate(stdOut, stdErr, fsys), newCmdDiff(stdOut, stdErr, fsys), newCmdInit(stdOut, stdErr, fsys), // 'add' sub command diff --git a/pkg/kinflate/commands/diff.go b/pkg/kinflate/commands/diff.go index dcd38eb74..ba53c1881 100644 --- a/pkg/kinflate/commands/diff.go +++ b/pkg/kinflate/commands/diff.go @@ -19,10 +19,13 @@ package commands import ( "errors" "io" + "path/filepath" "github.com/spf13/cobra" + "k8s.io/kubectl/pkg/kinflate/app" + "k8s.io/kubectl/pkg/kinflate/types" + "k8s.io/kubectl/pkg/loader" - "k8s.io/kubectl/pkg/kinflate/tree" "k8s.io/kubectl/pkg/kinflate/util" "k8s.io/kubectl/pkg/kinflate/util/fs" "k8s.io/utils/exec" @@ -72,7 +75,7 @@ func (o *diffOptions) Complete(cmd *cobra.Command, args []string) error { return nil } -// RunInit writes a manifest file. +// RunDiff gets the differences between Application.Resources() and Application.RawResources(). func (o *diffOptions) RunDiff(out, errOut io.Writer, fs fs.FileSystem) error { printer := util.Printer{} diff := util.DiffProgram{ @@ -81,23 +84,38 @@ func (o *diffOptions) RunDiff(out, errOut io.Writer, fs fs.FileSystem) error { Stderr: errOut, } - inflateOp := inflateOptions{manifestPath: o.manifestPath, mode: tree.ModeNormal} - kobj1, err := inflateOp.runInflate(fs) + l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)}) + + absPath, err := filepath.Abs(o.manifestPath) if err != nil { return err } - transformedDir, err := util.WriteToDir(kobj1, "transformed", printer) + + rootLoader, err := l.New(absPath) + if err != nil { + return err + } + + application, err := app.New(rootLoader) + if err != nil { + return err + } + resources, err := application.Resources() + if err != nil { + return err + } + rawResources, err := application.RawResources() + if err != nil { + return err + } + + transformedDir, err := util.WriteToDir(types.KObject(resources), "transformed", printer) if err != nil { return err } defer transformedDir.Delete() - inflateNoOp := inflateOptions{manifestPath: o.manifestPath, mode: tree.ModeNoop} - kobj2, err := inflateNoOp.runInflate(fs) - if err != nil { - return err - } - noopDir, err := util.WriteToDir(kobj2, "noop", printer) + noopDir, err := util.WriteToDir(types.KObject(rawResources), "noop", printer) if err != nil { return err } diff --git a/pkg/kinflate/commands/diff_test.go b/pkg/kinflate/commands/diff_test.go new file mode 100644 index 000000000..96185a866 --- /dev/null +++ b/pkg/kinflate/commands/diff_test.go @@ -0,0 +1,114 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package commands + +import ( + "bytes" + "io/ioutil" + "os" + "path/filepath" + "reflect" + "regexp" + "strings" + "testing" + + "github.com/ghodss/yaml" + + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/kubectl/pkg/kinflate/util/fs" +) + +type DiffTestCase struct { + Description string `yaml:"description"` + Args []string `yaml:"args"` + Filename string `yaml:"filename"` + // path to the file that contains the expected output + ExpectedDiff string `yaml:"expectedDiff"` +} + +func TestDiff(t *testing.T) { + const updateEnvVar = "UPDATE_KINFLATE_EXPECTED_DATA" + updateKinflateExpected := os.Getenv(updateEnvVar) == "true" + + noopDir, _ := regexp.Compile(`/tmp/noop-[0-9]*/`) + transformedDir, _ := regexp.Compile(`/tmp/transformed-[0-9]*/`) + timestamp, _ := regexp.Compile(`[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9].[0-9]* [+-]{1}[0-9]{4}`) + + fs := fs.MakeRealFS() + + testcases := sets.NewString() + filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if path == "testdata" { + return nil + } + name := filepath.Base(path) + if info.IsDir() { + if strings.HasPrefix(name, "testcase-") { + testcases.Insert(strings.TrimPrefix(name, "testcase-")) + } + return filepath.SkipDir + } + return nil + }) + // sanity check that we found the right folder + if !testcases.Has("simple") { + t.Fatalf("Error locating kinflate inflate testcases") + } + + for _, testcaseName := range testcases.List() { + t.Run(testcaseName, func(t *testing.T) { + name := testcaseName + testcase := DiffTestCase{} + testcaseDir := filepath.Join("testdata", "testcase-"+name) + testcaseData, err := ioutil.ReadFile(filepath.Join(testcaseDir, "test.yaml")) + if err != nil { + t.Fatalf("%s: %v", name, err) + } + if err := yaml.Unmarshal(testcaseData, &testcase); err != nil { + t.Fatalf("%s: %v", name, err) + } + + diffOps := &diffOptions{ + manifestPath: testcase.Filename, + } + buf := bytes.NewBuffer([]byte{}) + err = diffOps.RunDiff(buf, os.Stderr, fs) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + actualString := string(buf.Bytes()) + actualString = noopDir.ReplaceAllString(actualString, "/tmp/noop/") + actualString = transformedDir.ReplaceAllString(actualString, "/tmp/transformed/") + actualString = timestamp.ReplaceAllString(actualString, "YYYY-MM-DD HH:MM:SS") + actualBytes := []byte(actualString) + if !updateKinflateExpected { + expectedBytes, err := ioutil.ReadFile(testcase.ExpectedDiff) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if !reflect.DeepEqual(actualBytes, expectedBytes) { + t.Errorf("%s\ndoesn't equal expected:\n%s\n", actualBytes, expectedBytes) + } + } else { + ioutil.WriteFile(testcase.ExpectedDiff, actualBytes, 0644) + } + + }) + } +} diff --git a/pkg/kinflate/commands/inflate.go b/pkg/kinflate/commands/inflate.go index 8d4f57cff..c154ac0e1 100644 --- a/pkg/kinflate/commands/inflate.go +++ b/pkg/kinflate/commands/inflate.go @@ -23,23 +23,20 @@ import ( "path/filepath" "github.com/spf13/cobra" + "k8s.io/kubectl/pkg/kinflate/types" "k8s.io/kubectl/pkg/kinflate/app" - "k8s.io/kubectl/pkg/kinflate/tree" - "k8s.io/kubectl/pkg/kinflate/types" kutil "k8s.io/kubectl/pkg/kinflate/util" "k8s.io/kubectl/pkg/kinflate/util/fs" "k8s.io/kubectl/pkg/loader" ) type inflateOptions struct { - outputdir string manifestPath string - mode tree.ModeType } // newCmdInflate creates a new inflate command. -func newCmdInflate(out, errOut io.Writer) *cobra.Command { +func newCmdInflate(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command { var o inflateOptions cmd := &cobra.Command{ @@ -60,7 +57,7 @@ func newCmdInflate(out, errOut io.Writer) *cobra.Command { fmt.Fprintf(errOut, "error: %v\n", err) os.Exit(1) } - err = o.RunInflate(out, errOut) + err = o.RunInflate(out, errOut, fs) if err != nil { fmt.Fprintf(errOut, "error: %v\n", err) os.Exit(1) @@ -80,54 +77,36 @@ func (o *inflateOptions) Validate(cmd *cobra.Command, args []string) error { // Complete completes inflate command. func (o *inflateOptions) Complete(cmd *cobra.Command, args []string) error { - o.mode = tree.ModeNormal return nil } -// runInflate does the real transformation. -func (o *inflateOptions) runInflate(fs fs.FileSystem) (types.KObject, error) { +// RunInflate runs inflate command (do real work). +func (o *inflateOptions) RunInflate(out, errOut io.Writer, fs fs.FileSystem) error { l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)}) absPath, err := filepath.Abs(o.manifestPath) if err != nil { - return nil, err + return err } rootLoader, err := l.New(absPath) if err != nil { - return nil, err + return err } application, err := app.New(rootLoader) if err != nil { - return nil, err + return err } - allResources := types.ResourceCollection{} - switch o.mode { - case tree.ModeNormal: - allResources, err = application.Resources() - case tree.ModeNoop: - allResources, err = application.RawResources() - } - if err != nil { - return nil, err - } + allResources, err := application.Resources() - return types.KObject(allResources), nil -} - -// RunInflate runs inflate command (do real work). -func (o *inflateOptions) RunInflate(out, errOut io.Writer) error { - fs := fs.MakeRealFS() - - kobj, err := o.runInflate(fs) if err != nil { return err } // Output the objects. - res, err := kutil.Encode(kobj) + res, err := kutil.Encode(types.KObject(allResources)) if err != nil { return err } diff --git a/pkg/kinflate/commands/inflate_test.go b/pkg/kinflate/commands/inflate_test.go index 4708981c4..ca6bc469f 100644 --- a/pkg/kinflate/commands/inflate_test.go +++ b/pkg/kinflate/commands/inflate_test.go @@ -28,14 +28,13 @@ import ( "github.com/ghodss/yaml" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/kubectl/pkg/kinflate/tree" + "k8s.io/kubectl/pkg/kinflate/util/fs" ) type InflateTestCase struct { - Description string `yaml:"description"` - Args []string `yaml:"args"` - Filename string `yaml:"filename"` - Mode tree.ModeType `yaml:"mode"` + Description string `yaml:"description"` + Args []string `yaml:"args"` + Filename string `yaml:"filename"` // path to the file that contains the expected output ExpectedStdout string `yaml:"expectedStdout"` } @@ -43,11 +42,7 @@ type InflateTestCase struct { func TestInflate(t *testing.T) { const updateEnvVar = "UPDATE_KINFLATE_EXPECTED_DATA" updateKinflateExpected := os.Getenv(updateEnvVar) == "true" - - var ( - name string - testcase InflateTestCase - ) + fs := fs.MakeRealFS() testcases := sets.NewString() filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error { @@ -73,8 +68,8 @@ func TestInflate(t *testing.T) { for _, testcaseName := range testcases.List() { t.Run(testcaseName, func(t *testing.T) { - name = testcaseName - testcase = InflateTestCase{} + name := testcaseName + testcase := InflateTestCase{} testcaseDir := filepath.Join("testdata", "testcase-"+name) testcaseData, err := ioutil.ReadFile(filepath.Join(testcaseDir, "test.yaml")) if err != nil { @@ -84,15 +79,11 @@ func TestInflate(t *testing.T) { t.Fatalf("%s: %v", name, err) } - if testcase.Mode == "" { - testcase.Mode = tree.ModeNormal - } ops := &inflateOptions{ manifestPath: testcase.Filename, - mode: testcase.Mode, } buf := bytes.NewBuffer([]byte{}) - err = ops.RunInflate(buf, os.Stderr) + err = ops.RunInflate(buf, os.Stderr, fs) if err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/pkg/kinflate/commands/testdata/testcase-base-only/expected.diff b/pkg/kinflate/commands/testdata/testcase-base-only/expected.diff new file mode 100644 index 000000000..de911f805 --- /dev/null +++ b/pkg/kinflate/commands/testdata/testcase-base-only/expected.diff @@ -0,0 +1,58 @@ +diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml +--- /tmp/noop/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS +@@ -1,14 +1,27 @@ + apiVersion: apps/v1beta2 + kind: Deployment + metadata: ++ annotations: ++ note: This is a test annotation + labels: +- app: nginx +- name: nginx ++ app: mynginx ++ org: example.com ++ team: foo ++ name: team-foo-nginx + spec: ++ selector: ++ matchLabels: ++ app: mynginx ++ org: example.com ++ team: foo + template: + metadata: ++ annotations: ++ note: This is a test annotation + labels: +- app: nginx ++ app: mynginx ++ org: example.com ++ team: foo + spec: + containers: + - image: nginx +diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml +--- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS +@@ -1,11 +1,17 @@ + apiVersion: v1 + kind: Service + metadata: ++ annotations: ++ note: This is a test annotation + labels: +- app: nginx +- name: nginx ++ app: mynginx ++ org: example.com ++ team: foo ++ name: team-foo-nginx + spec: + ports: + - port: 80 + selector: +- app: nginx ++ app: mynginx ++ org: example.com ++ team: foo diff --git a/pkg/kinflate/commands/testdata/testcase-base-only/test.yaml b/pkg/kinflate/commands/testdata/testcase-base-only/test.yaml index 6400b0df7..61d6d0a07 100644 --- a/pkg/kinflate/commands/testdata/testcase-base-only/test.yaml +++ b/pkg/kinflate/commands/testdata/testcase-base-only/test.yaml @@ -2,3 +2,4 @@ description: base only args: [] filename: testdata/testcase-base-only/in expectedStdout: testdata/testcase-base-only/expected.yaml +expectedDiff: testdata/testcase-base-only/expected.diff diff --git a/pkg/kinflate/commands/testdata/testcase-noop/Kube-manifest.yaml b/pkg/kinflate/commands/testdata/testcase-noop/Kube-manifest.yaml deleted file mode 100644 index eb43086a1..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/Kube-manifest.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: mysql-wordpress -description: wordpress app with mysql -namePrefix: my-awesome-app- -objectAnnotations: - note: This is a test annotation -packages: - - mysql/ - - wordpress/ -patches: - - patch.yaml -configmaps: - - name: app-env - env: configmap/app.env - - name: app-config - files: - - configmap/app-init.ini diff --git a/pkg/kinflate/commands/testdata/testcase-noop/configmap/app-init.ini b/pkg/kinflate/commands/testdata/testcase-noop/configmap/app-init.ini deleted file mode 100644 index 8ebb8fcb3..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/configmap/app-init.ini +++ /dev/null @@ -1,2 +0,0 @@ -FOO=bar -BAR=baz diff --git a/pkg/kinflate/commands/testdata/testcase-noop/configmap/app.env b/pkg/kinflate/commands/testdata/testcase-noop/configmap/app.env deleted file mode 100644 index c4032090a..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/configmap/app.env +++ /dev/null @@ -1,2 +0,0 @@ -DB_USERNAME=admin -DB_PASSWORD=somepw diff --git a/pkg/kinflate/commands/testdata/testcase-noop/expected.yaml b/pkg/kinflate/commands/testdata/testcase-noop/expected.yaml deleted file mode 100644 index 4b3cf0dad..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/expected.yaml +++ /dev/null @@ -1,81 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mysql - component: mysql - name: mysql -spec: - ports: - - port: 3306 - selector: - app: mysql - component: mysql ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: wordpress - component: wordpress - name: wordpress -spec: - ports: - - port: 80 - selector: - app: wordpress - component: wordpress ---- -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - annotations: - note: This is a test annotation - labels: - app: mysql - component: mysql - name: mysql -spec: - selector: - matchLabels: - component: mysql - template: - metadata: - annotations: - note: This is a test annotation - labels: - app: mysql - component: mysql - spec: - containers: - - image: mysql - name: mysql ---- -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - annotations: - note: This is a test annotation - labels: - app: wordpress - component: wordpress - name: wordpress -spec: - selector: - matchLabels: - component: wordpress - template: - metadata: - annotations: - note: This is a test annotation - labels: - app: wordpress - component: wordpress - spec: - containers: - - image: wordpress - name: wordpress diff --git a/pkg/kinflate/commands/testdata/testcase-noop/mysql/Kube-manifest.yaml b/pkg/kinflate/commands/testdata/testcase-noop/mysql/Kube-manifest.yaml deleted file mode 100644 index 7c6edc354..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/mysql/Kube-manifest.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: mysql-app -description: mysql app for team foo -objectLabels: - component: mysql -objectAnnotations: - note: This is a test annotation -resources: - - deployment.yaml - - service.yaml diff --git a/pkg/kinflate/commands/testdata/testcase-noop/mysql/deployment.yaml b/pkg/kinflate/commands/testdata/testcase-noop/mysql/deployment.yaml deleted file mode 100644 index 5a40824c6..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/mysql/deployment.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: mysql - labels: - app: mysql -spec: - template: - metadata: - labels: - app: mysql - spec: - containers: - - name: mysql - image: mysql diff --git a/pkg/kinflate/commands/testdata/testcase-noop/mysql/service.yaml b/pkg/kinflate/commands/testdata/testcase-noop/mysql/service.yaml deleted file mode 100644 index aa3f970b6..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/mysql/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: mysql - labels: - app: mysql -spec: - ports: - - port: 3306 - selector: - app: mysql diff --git a/pkg/kinflate/commands/testdata/testcase-noop/patch.yaml b/pkg/kinflate/commands/testdata/testcase-noop/patch.yaml deleted file mode 100644 index f96417288..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/patch.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2 -kind: Deployment -metadata: - name: wordpress -spec: - template: - spec: - containers: - - name: wordpress - env: - - name: WORDPRESS_DB_HOST - value: mysql - - name: WORDPRESS_DB_PASSWORD - valueFrom: - secretKeyRef: - name: mysql-pass - key: password diff --git a/pkg/kinflate/commands/testdata/testcase-noop/test.yaml b/pkg/kinflate/commands/testdata/testcase-noop/test.yaml deleted file mode 100644 index f1dba4d74..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -description: noop -args: [] -filename: testdata/testcase-noop/ -mode: noop_mode -expectedStdout: testdata/testcase-noop/expected.yaml diff --git a/pkg/kinflate/commands/testdata/testcase-noop/wordpress/Kube-manifest.yaml b/pkg/kinflate/commands/testdata/testcase-noop/wordpress/Kube-manifest.yaml deleted file mode 100644 index b28a74785..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/wordpress/Kube-manifest.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: wordpress -description: wordpress app -objectLabels: - component: wordpress -objectAnnotations: - note: This is a test annotation -resources: - - deployment.yaml - - service.yaml diff --git a/pkg/kinflate/commands/testdata/testcase-noop/wordpress/deployment.yaml b/pkg/kinflate/commands/testdata/testcase-noop/wordpress/deployment.yaml deleted file mode 100644 index d83d51097..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/wordpress/deployment.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: wordpress - labels: - app: wordpress -spec: - template: - metadata: - labels: - app: wordpress - spec: - containers: - - name: wordpress - image: wordpress diff --git a/pkg/kinflate/commands/testdata/testcase-noop/wordpress/service.yaml b/pkg/kinflate/commands/testdata/testcase-noop/wordpress/service.yaml deleted file mode 100644 index d1708ad21..000000000 --- a/pkg/kinflate/commands/testdata/testcase-noop/wordpress/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: wordpress - labels: - app: wordpress -spec: - ports: - - port: 80 - selector: - app: wordpress diff --git a/pkg/kinflate/commands/testdata/testcase-simple/expected.diff b/pkg/kinflate/commands/testdata/testcase-simple/expected.diff new file mode 100644 index 000000000..9f6586908 --- /dev/null +++ b/pkg/kinflate/commands/testdata/testcase-simple/expected.diff @@ -0,0 +1,154 @@ +diff -u -N /tmp/noop/extensions_v1beta1_Deployment_mungebot.yaml /tmp/transformed/extensions_v1beta1_Deployment_mungebot.yaml +--- /tmp/noop/extensions_v1beta1_Deployment_mungebot.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/extensions_v1beta1_Deployment_mungebot.yaml YYYY-MM-DD HH:MM:SS +@@ -3,28 +3,68 @@ + metadata: + annotations: + baseAnno: This is an base annotation ++ note: This is a test annotation + labels: + app: mungebot + foo: bar +- name: baseprefix-mungebot ++ org: kubernetes ++ repo: test-infra ++ name: test-infra-baseprefix-mungebot + spec: +- replicas: 1 ++ replicas: 2 + selector: + matchLabels: ++ app: mungebot + foo: bar ++ org: kubernetes ++ repo: test-infra + template: + metadata: + annotations: + baseAnno: This is an base annotation ++ note: This is a test annotation + labels: + app: mungebot + foo: bar ++ org: kubernetes ++ repo: test-infra + spec: + containers: + - env: ++ - name: FOO ++ valueFrom: ++ configMapKeyRef: ++ key: somekey ++ name: test-infra-app-env-hf26mf2f2f ++ - name: BAR ++ valueFrom: ++ secretKeyRef: ++ key: somekey ++ name: test-infra-app-tls-4d47hbbh9m + - name: foo + value: bar +- image: nginx ++ image: nginx:1.7.9 + name: nginx + ports: + - containerPort: 80 ++ - envFrom: ++ - configMapRef: ++ name: someConfigMap ++ - configMapRef: ++ name: test-infra-app-env-hf26mf2f2f ++ - secretRef: ++ name: test-infra-app-tls-4d47hbbh9m ++ image: busybox ++ name: busybox ++ volumeMounts: ++ - mountPath: /tmp/env ++ name: app-env ++ - mountPath: /tmp/tls ++ name: app-tls ++ volumes: ++ - configMap: ++ name: test-infra-app-env-hf26mf2f2f ++ name: app-env ++ - name: app-tls ++ secret: ++ secretName: test-infra-app-tls-4d47hbbh9m +diff -u -N /tmp/noop/v1_ConfigMap_app-config.yaml /tmp/transformed/v1_ConfigMap_app-config.yaml +--- /tmp/noop/v1_ConfigMap_app-config.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/v1_ConfigMap_app-config.yaml YYYY-MM-DD HH:MM:SS +@@ -0,0 +1,15 @@ ++apiVersion: v1 ++data: ++ app-init.ini: | ++ FOO=bar ++ BAR=baz ++kind: ConfigMap ++metadata: ++ annotations: ++ note: This is a test annotation ++ creationTimestamp: null ++ labels: ++ app: mungebot ++ org: kubernetes ++ repo: test-infra ++ name: test-infra-app-config-ht8ck65bcg +diff -u -N /tmp/noop/v1_ConfigMap_app-env.yaml /tmp/transformed/v1_ConfigMap_app-env.yaml +--- /tmp/noop/v1_ConfigMap_app-env.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/v1_ConfigMap_app-env.yaml YYYY-MM-DD HH:MM:SS +@@ -0,0 +1,14 @@ ++apiVersion: v1 ++data: ++ DB_PASSWORD: somepw ++ DB_USERNAME: admin ++kind: ConfigMap ++metadata: ++ annotations: ++ note: This is a test annotation ++ creationTimestamp: null ++ labels: ++ app: mungebot ++ org: kubernetes ++ repo: test-infra ++ name: test-infra-app-env-hf26mf2f2f +diff -u -N /tmp/noop/v1_Secret_app-tls.yaml /tmp/transformed/v1_Secret_app-tls.yaml +--- /tmp/noop/v1_Secret_app-tls.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/v1_Secret_app-tls.yaml YYYY-MM-DD HH:MM:SS +@@ -0,0 +1,15 @@ ++apiVersion: v1 ++data: ++ tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIwekNDQVgyZ0F3SUJBZ0lKQUkvTTdCWWp3Qit1TUEwR0NTcUdTSWIzRFFFQkJRVUFNRVV4Q3pBSkJnTlYKQkFZVEFrRlZNUk13RVFZRFZRUUlEQXBUYjIxbExWTjBZWFJsTVNFd0h3WURWUVFLREJoSmJuUmxjbTVsZENCWAphV1JuYVhSeklGQjBlU0JNZEdRd0hoY05NVEl3T1RFeU1qRTFNakF5V2hjTk1UVXdPVEV5TWpFMU1qQXlXakJGCk1Rc3dDUVlEVlFRR0V3SkJWVEVUTUJFR0ExVUVDQXdLVTI5dFpTMVRkR0YwWlRFaE1COEdBMVVFQ2d3WVNXNTAKWlhKdVpYUWdWMmxrWjJsMGN5QlFkSGtnVEhSa01Gd3dEUVlKS29aSWh2Y05BUUVCQlFBRFN3QXdTQUpCQU5MSgpoUEhoSVRxUWJQa2xHM2liQ1Z4d0dNUmZwL3Y0WHFoZmRRSGRjVmZIYXA2TlE1V29rLzR4SUErdWkzNS9NbU5hCnJ0TnVDK0JkWjF0TXVWQ1BGWmNDQXdFQUFhTlFNRTR3SFFZRFZSME9CQllFRkp2S3M4UmZKYVhUSDA4VytTR3YKelF5S24wSDhNQjhHQTFVZEl3UVlNQmFBRkp2S3M4UmZKYVhUSDA4VytTR3Z6UXlLbjBIOE1Bd0dBMVVkRXdRRgpNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUZCUUFEUVFCSmxmZkpIeWJqREd4Uk1xYVJtRGhYMCs2djAyVFVLWnNXCnI1UXVWYnBRaEg2dSswVWdjVzBqcDlRd3B4b1BUTFRXR1hFV0JCQnVyeEZ3aUNCaGtRK1YKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= ++ tls.key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlCT3dJQkFBSkJBTkxKaFBIaElUcVFiUGtsRzNpYkNWeHdHTVJmcC92NFhxaGZkUUhkY1ZmSGFwNk5RNVdvCmsvNHhJQSt1aTM1L01tTmFydE51QytCZFoxdE11VkNQRlpjQ0F3RUFBUUpBRUoyTit6c1IwWG44L1E2dHdhNEcKNk9CMU0xV08rayt6dG5YLzFTdk5lV3U4RDZHSW10dXBMVFlnalpjSHVmeWtqMDlqaUhtakh4OHU4WlpCL28xTgpNUUloQVBXK2V5Wm83YXkzbE16MVYwMVdWak5LSzlRU24xTUpsYjA2aC9MdVl2OUZBaUVBMjVXUGVkS2dWeUNXClNtVXdiUHc4Zm5UY3BxRFdFM3lUTzN2S2NlYnFNU3NDSUJGM1VtVnVlOFlVM2p5YkMzTnh1WHEzd05tMzRSOFQKeFZMSHdEWGgvNk5KQWlFQWwyb0hHR0x6NjRCdUFmaktycXd6N3FNWXI5SENMSWUvWXNvV3Evb2x6U2NDSVFEaQpEMmxXdXNvZTIvbkVxZkRWVldHV2x5Sjd5T21xYVZtL2lOVU45QjJOMmc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo= ++kind: Secret ++metadata: ++ annotations: ++ note: This is a test annotation ++ creationTimestamp: null ++ labels: ++ app: mungebot ++ org: kubernetes ++ repo: test-infra ++ name: test-infra-app-tls-4d47hbbh9m ++type: kubernetes.io/tls +diff -u -N /tmp/noop/v1_Service_mungebot-service.yaml /tmp/transformed/v1_Service_mungebot-service.yaml +--- /tmp/noop/v1_Service_mungebot-service.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/v1_Service_mungebot-service.yaml YYYY-MM-DD HH:MM:SS +@@ -3,13 +3,18 @@ + metadata: + annotations: + baseAnno: This is an base annotation ++ note: This is a test annotation + labels: + app: mungebot + foo: bar +- name: baseprefix-mungebot-service ++ org: kubernetes ++ repo: test-infra ++ name: test-infra-baseprefix-mungebot-service + spec: + ports: + - port: 7002 + selector: + app: mungebot + foo: bar ++ org: kubernetes ++ repo: test-infra diff --git a/pkg/kinflate/commands/testdata/testcase-simple/test.yaml b/pkg/kinflate/commands/testdata/testcase-simple/test.yaml index 0ba295193..e9185c012 100644 --- a/pkg/kinflate/commands/testdata/testcase-simple/test.yaml +++ b/pkg/kinflate/commands/testdata/testcase-simple/test.yaml @@ -2,3 +2,4 @@ description: simple args: [] filename: ../examples/simple/instances/exampleinstance/ expectedStdout: testdata/testcase-simple/expected.yaml +expectedDiff: testdata/testcase-simple/expected.diff diff --git a/pkg/kinflate/commands/testdata/testcase-single-overlay/expected.diff b/pkg/kinflate/commands/testdata/testcase-single-overlay/expected.diff new file mode 100644 index 000000000..9b5b81f27 --- /dev/null +++ b/pkg/kinflate/commands/testdata/testcase-single-overlay/expected.diff @@ -0,0 +1,56 @@ +diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml +--- /tmp/noop/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS +@@ -5,13 +5,15 @@ + note: This is a test annotation + labels: + app: mynginx ++ env: staging + org: example.com + team: foo +- name: team-foo-nginx ++ name: staging-team-foo-nginx + spec: + selector: + matchLabels: + app: mynginx ++ env: staging + org: example.com + team: foo + template: +@@ -20,6 +22,7 @@ + note: This is a test annotation + labels: + app: mynginx ++ env: staging + org: example.com + team: foo + spec: +@@ -30,5 +33,6 @@ + - mountPath: /tmp/ps + name: nginx-persistent-storage + volumes: +- - emptyDir: {} ++ - gcePersistentDisk: ++ pdName: nginx-persistent-storage + name: nginx-persistent-storage +diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml +--- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS +@@ -5,13 +5,15 @@ + note: This is a test annotation + labels: + app: mynginx ++ env: staging + org: example.com + team: foo +- name: team-foo-nginx ++ name: staging-team-foo-nginx + spec: + ports: + - port: 80 + selector: + app: mynginx ++ env: staging + org: example.com + team: foo diff --git a/pkg/kinflate/commands/testdata/testcase-single-overlay/test.yaml b/pkg/kinflate/commands/testdata/testcase-single-overlay/test.yaml index aec1475e5..1af80f52c 100644 --- a/pkg/kinflate/commands/testdata/testcase-single-overlay/test.yaml +++ b/pkg/kinflate/commands/testdata/testcase-single-overlay/test.yaml @@ -2,3 +2,4 @@ description: single overlay args: [] filename: testdata/testcase-single-overlay/in/overlay/ expectedStdout: testdata/testcase-single-overlay/expected.yaml +expectedDiff: testdata/testcase-single-overlay/expected.diff