From aafeb75ef1dd9c6a5da92ba10c477b557382efeb Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Fri, 20 Dec 2019 03:43:11 -0800 Subject: [PATCH 1/7] Rebase merge3 branch into master --- cmd/config/configcobra/cmds.go | 1 + cmd/config/docs/commands/merge3.md | 25 +++ cmd/config/internal/commands/merge3.go | 56 +++++ cmd/config/internal/commands/merge3_test.go | 236 ++++++++++++++++++++ 4 files changed, 318 insertions(+) create mode 100644 cmd/config/docs/commands/merge3.md create mode 100644 cmd/config/internal/commands/merge3.go create mode 100644 cmd/config/internal/commands/merge3_test.go diff --git a/cmd/config/configcobra/cmds.go b/cmd/config/configcobra/cmds.go index 0fd9c86bd..3e1126e1d 100644 --- a/cmd/config/configcobra/cmds.go +++ b/cmd/config/configcobra/cmds.go @@ -74,6 +74,7 @@ func NewConfigCommand(name string) *cobra.Command { root.AddCommand(commands.CatCommand(name)) root.AddCommand(commands.FmtCommand(name)) root.AddCommand(commands.MergeCommand(name)) + root.AddCommand(commands.Merge3Command(name)) root.AddCommand(commands.CountCommand(name)) root.AddCommand(commands.RunFnCommand(name)) root.AddCommand(commands.SubCommand(name)) diff --git a/cmd/config/docs/commands/merge3.md b/cmd/config/docs/commands/merge3.md new file mode 100644 index 000000000..7991e5290 --- /dev/null +++ b/cmd/config/docs/commands/merge3.md @@ -0,0 +1,25 @@ +## merge3 + +[Alpha] Merge Resource configuration files (3-way) + +### Synopsis + +[Alpha] Merge Resource configuration files (3-way) + +Merge (3-way) reads Kubernetes Resource yaml configuration files from source packages and updated +packages then writes the result to stdout and a destination package. + +Resources are merged using the Resource [apiVersion, kind, name, namespace] as the key. If any of +these are missing, merge will default the missing values to empty. + +Resources specified in the updated packages have higher-precedence and Resources specified +in the original packages have lower-precedence. Resources specified in the destination +packages either keep, clear, or recursively merge their values. + +For information on merge rules, run: + + kustomize config docs merge3 + +### Examples + + kustomize config merge3 --ancestor a/ --from b/ --to c/ \ No newline at end of file diff --git a/cmd/config/internal/commands/merge3.go b/cmd/config/internal/commands/merge3.go new file mode 100644 index 000000000..6ef234a35 --- /dev/null +++ b/cmd/config/internal/commands/merge3.go @@ -0,0 +1,56 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package commands + +import ( + "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/cmd/config/cmddocs/commands" + "sigs.k8s.io/kustomize/kyaml/kio/filters" +) + +func GetMerge3Runner(name string) *Merge3Runner { + r := &Merge3Runner{} + c := &cobra.Command{ + Use: "merge3 --ancestor [ORIGINAL_DIR] --from [UPDATED_DIR] --to [DESTINATION_DIR]", + Short: commands.Merge3Short, + Long: commands.Merge3Long, + Example: commands.Merge3Examples, + RunE: r.runE, + } + fixDocs(name, c) + //r.Command = c + c.Flags().StringVar(&r.ancestor, "ancestor", "", + "Path to original package") + c.Flags().StringVar(&r.fromDir, "from", "", + "Path to updated package") + c.Flags().StringVar(&r.toDir, "to", "", + "Path to destination package") + + r.Command = c + return r +} + +func Merge3Command(name string) *cobra.Command { + return GetMerge3Runner(name).Command +} + +// Merge3Runner contains the run function +type Merge3Runner struct { + Command *cobra.Command + ancestor string + fromDir string + toDir string +} + +func (r *Merge3Runner) runE(c *cobra.Command, args []string) error { + err := filters.Merge3{ + OriginalPath: r.ancestor, + UpdatedPath: r.fromDir, + DestPath: r.toDir, + }.Merge() + if err != nil { + return err + } + return nil +} diff --git a/cmd/config/internal/commands/merge3_test.go b/cmd/config/internal/commands/merge3_test.go new file mode 100644 index 000000000..7b28d1513 --- /dev/null +++ b/cmd/config/internal/commands/merge3_test.go @@ -0,0 +1,236 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package commands + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "sigs.k8s.io/kustomize/cmd/config/internal/commands" + "sigs.k8s.io/kustomize/kyaml/copyutil" +) + +// TestMerge3Command verifies the merge3 correctly applies the diff between 2 sets of resources into another +func TestMerge3Command(t *testing.T) { + datadir, err := ioutil.TempDir("", "test-data") + defer os.RemoveAll(datadir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(datadir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java +spec: + replicas: 1 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 5 +`), 0600) + if !assert.NoError(t, err) { + return + } + + expected_dir, err := ioutil.TempDir("", "test-data-expected") + defer os.RemoveAll(expected_dir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(expected_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java + new-local: label + new-remote: label +spec: + replicas: 3 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + - otherstuff + args: + - foo + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 20 +`), 0600) + if !assert.NoError(t, err) { + return + } + + updated_dir, err := ioutil.TempDir("", "test-data-updated") + defer os.RemoveAll(updated_dir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(updated_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java + new-remote: label +spec: + replicas: 3 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + - otherstuff + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 5 +`), 0600) + if !assert.NoError(t, err) { + return + } + + dest_dir, err := ioutil.TempDir("", "test-data-dest") + defer os.RemoveAll(dest_dir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(dest_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java + new-local: label +spec: + replicas: 2 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + args: + - foo + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 20 +`), 0600) + if !assert.NoError(t, err) { + return + } + + // Perform merge3 with newly created sets + r := commands.GetMerge3Runner("") + r.Command.SetArgs([]string{ + "--ancestor", + datadir, + "--from", + updated_dir, + "--to", + dest_dir, + }) + if !assert.NoError(t, r.Command.Execute()) { + return + } + + diffs, err := copyutil.Diff(dest_dir, expected_dir) + if !assert.NoError(t, err) { + t.FailNow() + } + + // Verify there are no diffs + if !assert.Empty(t, diffs.List()) { + t.FailNow() + } +} \ No newline at end of file From d04b4a289990e974efc7208818110314987221ad Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Wed, 4 Dec 2019 20:57:21 -0800 Subject: [PATCH 2/7] Remove unnecessary 1-line comment --- cmd/config/internal/commands/merge3.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/config/internal/commands/merge3.go b/cmd/config/internal/commands/merge3.go index 6ef234a35..ad71dca83 100644 --- a/cmd/config/internal/commands/merge3.go +++ b/cmd/config/internal/commands/merge3.go @@ -19,7 +19,6 @@ func GetMerge3Runner(name string) *Merge3Runner { RunE: r.runE, } fixDocs(name, c) - //r.Command = c c.Flags().StringVar(&r.ancestor, "ancestor", "", "Path to original package") c.Flags().StringVar(&r.fromDir, "from", "", From 8095b16c9a301eb864d64027579b96485364a15b Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Fri, 13 Dec 2019 04:15:36 -0800 Subject: [PATCH 3/7] Add test for merge3 command --- cmd/config/cmd/merge3_test.go | 236 ++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 cmd/config/cmd/merge3_test.go diff --git a/cmd/config/cmd/merge3_test.go b/cmd/config/cmd/merge3_test.go new file mode 100644 index 000000000..761739144 --- /dev/null +++ b/cmd/config/cmd/merge3_test.go @@ -0,0 +1,236 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package cmd_test + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "sigs.k8s.io/kustomize/cmd/config/cmd" + "sigs.k8s.io/kustomize/kyaml/copyutil" +) + +// TestMerge3Command verifies the merge3 correctly applies the diff between 2 sets of resources into another +func TestMerge3Command(t *testing.T) { + datadir, err := ioutil.TempDir("", "test-data") + defer os.RemoveAll(datadir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(datadir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java +spec: + replicas: 1 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 5 +`), 0600) + if !assert.NoError(t, err) { + return + } + + expected_dir, err := ioutil.TempDir("", "test-data-expected") + defer os.RemoveAll(expected_dir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(expected_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java + new-local: label + new-remote: label +spec: + replicas: 3 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + - otherstuff + args: + - foo + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 20 +`), 0600) + if !assert.NoError(t, err) { + return + } + + updated_dir, err := ioutil.TempDir("", "test-data-updated") + defer os.RemoveAll(updated_dir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(updated_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java + new-remote: label +spec: + replicas: 3 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + - otherstuff + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 5 +`), 0600) + if !assert.NoError(t, err) { + return + } + + dest_dir, err := ioutil.TempDir("", "test-data-dest") + defer os.RemoveAll(dest_dir) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(dest_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: java + new-local: label +spec: + replicas: 2 + selector: + matchLabels: + app: java + template: + metadata: + labels: + app: java + spec: + restartPolicy: Always + containers: + - name: app + image: gcr.io/project/app:version + command: + - java + - -jar + - /app.jar + args: + - foo + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: app-config + env: + - name: JAVA_OPTS + value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap + -Djava.security.egd=file:/dev/./urandom + imagePullPolicy: Always + minReadySeconds: 20 +`), 0600) + if !assert.NoError(t, err) { + return + } + + // Perform merge3 with newly created sets + r := cmd.GetMerge3Runner("") + r.Command.SetArgs([]string{ + "--ancestor", + datadir, + "--from", + updated_dir, + "--to", + dest_dir, + }) + if !assert.NoError(t, r.Command.Execute()) { + return + } + + diffs, err := copyutil.Diff(dest_dir, expected_dir) + if !assert.NoError(t, err) { + t.FailNow() + } + + // Verify there are no diffs + if !assert.Empty(t, diffs.List()) { + t.FailNow() + } +} \ No newline at end of file From e35e0bff600f2f592faee472ca9ea125ce583732 Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Fri, 13 Dec 2019 04:16:02 -0800 Subject: [PATCH 4/7] Update docs for merge3 --- cmd/config/docs/commands/merge3.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/config/docs/commands/merge3.md b/cmd/config/docs/commands/merge3.md index 7991e5290..7774a17d0 100644 --- a/cmd/config/docs/commands/merge3.md +++ b/cmd/config/docs/commands/merge3.md @@ -1,24 +1,22 @@ ## merge3 -[Alpha] Merge Resource configuration files (3-way) +[Alpha] Merge diff of Resource configuration files into a destination (3-way) ### Synopsis -[Alpha] Merge Resource configuration files (3-way) +[Alpha] Merge diff of Resource configuration files into a destination (3-way) -Merge (3-way) reads Kubernetes Resource yaml configuration files from source packages and updated -packages then writes the result to stdout and a destination package. +Merge3 performs a 3-way merge by applying the diff between 2 sets of Resources to a 3rd set. -Resources are merged using the Resource [apiVersion, kind, name, namespace] as the key. If any of -these are missing, merge will default the missing values to empty. +Merge3 may be for rebasing changes to a forked set of configuration -- e.g. compute the difference between the original +set of Resources that was forked and an updated set of those Resources, then apply that difference to the fork. -Resources specified in the updated packages have higher-precedence and Resources specified -in the original packages have lower-precedence. Resources specified in the destination -packages either keep, clear, or recursively merge their values. +If a field value differs between the ORIGINAL_DIR and UPDATED_DIR, the value from the UPDATED_DIR is taken and applied +to the Resource in the DEST_DIR. For information on merge rules, run: - kustomize config docs merge3 + kustomize config docs-merge3 ### Examples From 4bdfb1c511d57e46fc710ec7e014e021889c70bb Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Tue, 24 Dec 2019 21:14:27 -0800 Subject: [PATCH 5/7] Remove refactored cmd directory --- cmd/config/cmd/merge3_test.go | 236 ---------------------------------- 1 file changed, 236 deletions(-) delete mode 100644 cmd/config/cmd/merge3_test.go diff --git a/cmd/config/cmd/merge3_test.go b/cmd/config/cmd/merge3_test.go deleted file mode 100644 index 761739144..000000000 --- a/cmd/config/cmd/merge3_test.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2019 The Kubernetes Authors. -// SPDX-License-Identifier: Apache-2.0 - -package cmd_test - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - "sigs.k8s.io/kustomize/cmd/config/cmd" - "sigs.k8s.io/kustomize/kyaml/copyutil" -) - -// TestMerge3Command verifies the merge3 correctly applies the diff between 2 sets of resources into another -func TestMerge3Command(t *testing.T) { - datadir, err := ioutil.TempDir("", "test-data") - defer os.RemoveAll(datadir) - if !assert.NoError(t, err) { - return - } - - err = ioutil.WriteFile(filepath.Join(datadir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 -kind: Deployment -metadata: - name: app - labels: - app: java -spec: - replicas: 1 - selector: - matchLabels: - app: java - template: - metadata: - labels: - app: java - spec: - restartPolicy: Always - containers: - - name: app - image: gcr.io/project/app:version - command: - - java - - -jar - - /app.jar - ports: - - containerPort: 8080 - envFrom: - - configMapRef: - name: app-config - env: - - name: JAVA_OPTS - value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap - -Djava.security.egd=file:/dev/./urandom - imagePullPolicy: Always - minReadySeconds: 5 -`), 0600) - if !assert.NoError(t, err) { - return - } - - expected_dir, err := ioutil.TempDir("", "test-data-expected") - defer os.RemoveAll(expected_dir) - if !assert.NoError(t, err) { - return - } - - err = ioutil.WriteFile(filepath.Join(expected_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 -kind: Deployment -metadata: - name: app - labels: - app: java - new-local: label - new-remote: label -spec: - replicas: 3 - selector: - matchLabels: - app: java - template: - metadata: - labels: - app: java - spec: - restartPolicy: Always - containers: - - name: app - image: gcr.io/project/app:version - command: - - java - - -jar - - /app.jar - - otherstuff - args: - - foo - ports: - - containerPort: 8080 - envFrom: - - configMapRef: - name: app-config - env: - - name: JAVA_OPTS - value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap - -Djava.security.egd=file:/dev/./urandom - imagePullPolicy: Always - minReadySeconds: 20 -`), 0600) - if !assert.NoError(t, err) { - return - } - - updated_dir, err := ioutil.TempDir("", "test-data-updated") - defer os.RemoveAll(updated_dir) - if !assert.NoError(t, err) { - return - } - - err = ioutil.WriteFile(filepath.Join(updated_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 -kind: Deployment -metadata: - name: app - labels: - app: java - new-remote: label -spec: - replicas: 3 - selector: - matchLabels: - app: java - template: - metadata: - labels: - app: java - spec: - restartPolicy: Always - containers: - - name: app - image: gcr.io/project/app:version - command: - - java - - -jar - - /app.jar - - otherstuff - ports: - - containerPort: 8080 - envFrom: - - configMapRef: - name: app-config - env: - - name: JAVA_OPTS - value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap - -Djava.security.egd=file:/dev/./urandom - imagePullPolicy: Always - minReadySeconds: 5 -`), 0600) - if !assert.NoError(t, err) { - return - } - - dest_dir, err := ioutil.TempDir("", "test-data-dest") - defer os.RemoveAll(dest_dir) - if !assert.NoError(t, err) { - return - } - - err = ioutil.WriteFile(filepath.Join(dest_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1 -kind: Deployment -metadata: - name: app - labels: - app: java - new-local: label -spec: - replicas: 2 - selector: - matchLabels: - app: java - template: - metadata: - labels: - app: java - spec: - restartPolicy: Always - containers: - - name: app - image: gcr.io/project/app:version - command: - - java - - -jar - - /app.jar - args: - - foo - ports: - - containerPort: 8080 - envFrom: - - configMapRef: - name: app-config - env: - - name: JAVA_OPTS - value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap - -Djava.security.egd=file:/dev/./urandom - imagePullPolicy: Always - minReadySeconds: 20 -`), 0600) - if !assert.NoError(t, err) { - return - } - - // Perform merge3 with newly created sets - r := cmd.GetMerge3Runner("") - r.Command.SetArgs([]string{ - "--ancestor", - datadir, - "--from", - updated_dir, - "--to", - dest_dir, - }) - if !assert.NoError(t, r.Command.Execute()) { - return - } - - diffs, err := copyutil.Diff(dest_dir, expected_dir) - if !assert.NoError(t, err) { - t.FailNow() - } - - // Verify there are no diffs - if !assert.Empty(t, diffs.List()) { - t.FailNow() - } -} \ No newline at end of file From fc57f530ee5a7fdc7493689e37d96b6fbda94142 Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Tue, 24 Dec 2019 21:18:40 -0800 Subject: [PATCH 6/7] Clean up merge3 changes --- cmd/config/internal/commands/merge3.go | 14 +++++++------- cmd/config/internal/commands/merge3_test.go | 5 +++-- .../internal/generateddocs/commands/docs.go | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cmd/config/internal/commands/merge3.go b/cmd/config/internal/commands/merge3.go index ad71dca83..405638463 100644 --- a/cmd/config/internal/commands/merge3.go +++ b/cmd/config/internal/commands/merge3.go @@ -5,7 +5,7 @@ package commands import ( "github.com/spf13/cobra" - "sigs.k8s.io/kustomize/cmd/config/cmddocs/commands" + "sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands" "sigs.k8s.io/kustomize/kyaml/kio/filters" ) @@ -36,17 +36,17 @@ func Merge3Command(name string) *cobra.Command { // Merge3Runner contains the run function type Merge3Runner struct { - Command *cobra.Command - ancestor string - fromDir string - toDir string + Command *cobra.Command + ancestor string + fromDir string + toDir string } func (r *Merge3Runner) runE(c *cobra.Command, args []string) error { err := filters.Merge3{ OriginalPath: r.ancestor, - UpdatedPath: r.fromDir, - DestPath: r.toDir, + UpdatedPath: r.fromDir, + DestPath: r.toDir, }.Merge() if err != nil { return err diff --git a/cmd/config/internal/commands/merge3_test.go b/cmd/config/internal/commands/merge3_test.go index 7b28d1513..de33ce7d3 100644 --- a/cmd/config/internal/commands/merge3_test.go +++ b/cmd/config/internal/commands/merge3_test.go @@ -1,7 +1,8 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package commands +package commands_test + import ( "io/ioutil" @@ -233,4 +234,4 @@ spec: if !assert.Empty(t, diffs.List()) { t.FailNow() } -} \ No newline at end of file +} diff --git a/cmd/config/internal/generateddocs/commands/docs.go b/cmd/config/internal/generateddocs/commands/docs.go index ef0013e83..ae10bdc21 100644 --- a/cmd/config/internal/generateddocs/commands/docs.go +++ b/cmd/config/internal/generateddocs/commands/docs.go @@ -136,6 +136,25 @@ For information on merge rules, run: var MergeExamples = ` cat resources_and_patches.yaml | kustomize config merge > merged_resources.yaml` +var Merge3Short = `[Alpha] Merge diff of Resource configuration files into a destination (3-way)` +var Merge3Long = ` +[Alpha] Merge diff of Resource configuration files into a destination (3-way) + +Merge3 performs a 3-way merge by applying the diff between 2 sets of Resources to a 3rd set. + +Merge3 may be for rebasing changes to a forked set of configuration -- e.g. compute the difference between the original +set of Resources that was forked and an updated set of those Resources, then apply that difference to the fork. + +If a field value differs between the ORIGINAL_DIR and UPDATED_DIR, the value from the UPDATED_DIR is taken and applied +to the Resource in the DEST_DIR. + +For information on merge rules, run: + + kustomize config docs-merge3 +` +var Merge3Examples = ` + kustomize config merge3 --ancestor a/ --from b/ --to c/` + var RunFnsShort = `[Alpha] Reoncile config functions to Resources.` var RunFnsLong = ` [Alpha] Reconcile config functions to Resources. From ef82c736b95dbb25adf9cfe2482c2dd9d6c928ad Mon Sep 17 00:00:00 2001 From: Jonathan Wong Date: Tue, 24 Dec 2019 21:46:59 -0800 Subject: [PATCH 7/7] Remove newline --- cmd/config/internal/commands/merge3_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/config/internal/commands/merge3_test.go b/cmd/config/internal/commands/merge3_test.go index de33ce7d3..171aec4d7 100644 --- a/cmd/config/internal/commands/merge3_test.go +++ b/cmd/config/internal/commands/merge3_test.go @@ -3,7 +3,6 @@ package commands_test - import ( "io/ioutil" "os"