diff --git a/examples/breakfast.md b/examples/breakfast.md index de902c885..a98fbb408 100644 --- a/examples/breakfast.md +++ b/examples/breakfast.md @@ -73,7 +73,7 @@ commonLabels: who: alice bases: - ../../base -patches: +patchesStrategicMerge: - temperature.yaml EOF @@ -96,7 +96,7 @@ commonLabels: who: bob bases: - ../../base -patches: +patchesStrategicMerge: - topping.yaml EOF diff --git a/examples/configGeneration.md b/examples/configGeneration.md index be61beb59..703e7bf95 100644 --- a/examples/configGeneration.md +++ b/examples/configGeneration.md @@ -67,7 +67,7 @@ commonAnnotations: note: Hello, I am staging! bases: - ../../base -patches: +patchesStrategicMerge: - map.yaml EOF diff --git a/examples/helloWorld/README.md b/examples/helloWorld/README.md index 390f90a30..0a6d3257e 100644 --- a/examples/helloWorld/README.md +++ b/examples/helloWorld/README.md @@ -156,7 +156,7 @@ commonAnnotations: note: Hello, I am staging! bases: - ../../base -patches: +patchesStrategicMerge: - map.yaml EOF ``` @@ -197,7 +197,7 @@ commonAnnotations: note: Hello, I am production! bases: - ../../base -patches: +patchesStrategicMerge: - deployment.yaml EOF ``` diff --git a/examples/ldap/overlays/production/kustomization.yaml b/examples/ldap/overlays/production/kustomization.yaml index a8dda51ca..84a159c96 100644 --- a/examples/ldap/overlays/production/kustomization.yaml +++ b/examples/ldap/overlays/production/kustomization.yaml @@ -1,5 +1,5 @@ bases: - ../../base -patches: +patchesStrategicMerge: - deployment.yaml namePrefix: production- diff --git a/examples/ldap/overlays/staging/kustomization.yaml b/examples/ldap/overlays/staging/kustomization.yaml index 7688bea73..18bbf920f 100644 --- a/examples/ldap/overlays/staging/kustomization.yaml +++ b/examples/ldap/overlays/staging/kustomization.yaml @@ -1,6 +1,6 @@ bases: - ../../base -patches: +patchesStrategicMerge: - deployment.yaml nameprefix: staging- configMapGenerator: diff --git a/examples/mySql/README.md b/examples/mySql/README.md index 1b68e0a17..c5b72a07c 100644 --- a/examples/mySql/README.md +++ b/examples/mySql/README.md @@ -150,7 +150,7 @@ Off the shelf MySQL uses `emptyDir` type volume, which gets wiped away if the MySQL Pod is recreated, and that is certainly not desirable for production environment. So we want to use Persistent Disk in -production. kustomize lets you apply `patches` to the +production. kustomize lets you apply `patchesStrategicMerge` to the resources. @@ -176,7 +176,7 @@ Add the patch file to `kustomization.yaml`: ``` cat <<'EOF' >> $DEMO_HOME/kustomization.yaml -patches: +patchesStrategicMerge: - persistent-disk.yaml EOF ``` @@ -188,7 +188,7 @@ Lets break this down: in deployment.yaml - Then we added `persistent-disk.yaml` to list of - `patches` in `kustomization.yaml`. `kustomize build` + `patchesStrategicMerge` in `kustomization.yaml`. `kustomize build` will apply this patch to the deployment resource with the name `mysql` as defined in the patch. diff --git a/examples/springboot/README.md b/examples/springboot/README.md index ca4dda4ae..a3f7e222b 100644 --- a/examples/springboot/README.md +++ b/examples/springboot/README.md @@ -291,7 +291,7 @@ kustomize edit add patch healthcheck_patch.yaml `kustomization.yaml` should have patches field: > ``` -> patches: +> patchesStrategicMerge: > - patch.yaml > - memorylimit_patch.yaml > - healthcheck_patch.yaml diff --git a/examples/springboot/overlays/production/kustomization.yaml b/examples/springboot/overlays/production/kustomization.yaml index 121f384b0..c892f877a 100644 --- a/examples/springboot/overlays/production/kustomization.yaml +++ b/examples/springboot/overlays/production/kustomization.yaml @@ -1,6 +1,6 @@ bases: - ../../base -patches: +patchesStrategicMerge: - patch.yaml - healthcheck_patch.yaml - memorylimit_patch.yaml diff --git a/examples/wordpress/README.md b/examples/wordpress/README.md index ce3f75efa..7746f0257 100644 --- a/examples/wordpress/README.md +++ b/examples/wordpress/README.md @@ -53,7 +53,7 @@ bases: - wordpress - mysql namePrefix: demo- -patches: +patchesStrategicMerge: - patch.yaml EOF ``` diff --git a/examples/wordpress/kustomization.yaml b/examples/wordpress/kustomization.yaml index c9d7c8dcd..cda9e01f0 100644 --- a/examples/wordpress/kustomization.yaml +++ b/examples/wordpress/kustomization.yaml @@ -1,7 +1,7 @@ bases: - wordpress - mysql -patches: +patchesStrategicMerge: - patch.yaml namePrefix: demo- diff --git a/pkg/app/application.go b/pkg/app/application.go index 8f8a9539f..f7c7a7b69 100644 --- a/pkg/app/application.go +++ b/pkg/app/application.go @@ -154,7 +154,7 @@ func (a *Application) loadCustomizedResMap() (resmap.ResMap, error) { return nil, err } - a.kustomization.PatchesStrategicMerge = patch.Append(a.kustomization.PatchesStrategicMerge, a.kustomization.Patches) + a.kustomization.PatchesStrategicMerge = patch.Append(a.kustomization.PatchesStrategicMerge, a.kustomization.Patches...) patches, err := resmap.NewResourceSliceFromPatches(a.ldr, a.kustomization.PatchesStrategicMerge) if err != nil { errs.Append(errors.Wrap(err, "NewResourceSliceFromPatches")) diff --git a/pkg/commands/addpatch.go b/pkg/commands/addpatch.go index 36b243889..e16698ea2 100644 --- a/pkg/commands/addpatch.go +++ b/pkg/commands/addpatch.go @@ -24,6 +24,7 @@ import ( "github.com/kubernetes-sigs/kustomize/pkg/constants" "github.com/kubernetes-sigs/kustomize/pkg/fs" + "github.com/kubernetes-sigs/kustomize/pkg/patch" ) type addPatchOptions struct { @@ -88,12 +89,12 @@ func (o *addPatchOptions) RunAddPatch(fsys fs.FileSystem) error { return err } - for _, patch := range patches { - if stringInSlice(patch, m.Patches) { - log.Printf("patch %s already in kustomization file", patch) + for _, p := range patches { + if patch.Exist(m.PatchesStrategicMerge, p) || stringInSlice(p, m.Patches) { + log.Printf("patch %s already in kustomization file", p) continue } - m.Patches = append(m.Patches, patch) + m.PatchesStrategicMerge = patch.Append(m.PatchesStrategicMerge, p) } return mf.write(m) diff --git a/pkg/commands/kustomizationfile.go b/pkg/commands/kustomizationfile.go index a386ebccf..383b3daa8 100644 --- a/pkg/commands/kustomizationfile.go +++ b/pkg/commands/kustomizationfile.go @@ -47,6 +47,7 @@ var ( "CommonLabels", "CommonAnnotations", "Patches", + "PatchesStrategicMerge", "ConfigMapGenerator", "SecretGenerator", "Vars", diff --git a/pkg/commands/kustomizationfile_test.go b/pkg/commands/kustomizationfile_test.go index 2b145cb3d..56e8970ab 100644 --- a/pkg/commands/kustomizationfile_test.go +++ b/pkg/commands/kustomizationfile_test.go @@ -109,7 +109,7 @@ vars: bases: - ../namespaces # some descriptions for the patches -patches: +patchesStrategicMerge: - service.yaml - pod.yaml `) @@ -165,7 +165,7 @@ BASES: # some descriptions for the patches -patches: +patchesStrategicMerge: - service.yaml - pod.yaml `) @@ -200,7 +200,7 @@ bases: # some descriptions for the patches -patches: +patchesStrategicMerge: - service.yaml - pod.yaml `) diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml b/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml index 173d1b050..2419b72af 100644 --- a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml +++ b/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml @@ -1,7 +1,7 @@ namePrefix: staging- commonLabels: env: staging -patches: +patchesStrategicMerge: - deployment-patch2.yaml - deployment-patch1.yaml bases: diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml b/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml index 555bda157..51e39c216 100644 --- a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml +++ b/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml @@ -1,7 +1,7 @@ namePrefix: staging- commonLabels: env: staging -patches: +patchesStrategicMerge: - patches/deployment-patch1.yaml - patches/deployment-patch2.yaml bases: diff --git a/pkg/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml b/pkg/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml index 42f80b67c..7538778f7 100644 --- a/pkg/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml +++ b/pkg/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml @@ -2,7 +2,7 @@ namePrefix: staging- commonLabels: env: staging team: override-foo -patches: +patchesStrategicMerge: - deployment.yaml bases: - ../package/ diff --git a/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml b/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml index 4426f5a9c..3741a2b52 100644 --- a/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml +++ b/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml @@ -7,7 +7,7 @@ commonAnnotations: note: This is a test annotation bases: - ../../package/ -patches: +patchesStrategicMerge: - deployment/deployment.yaml configMapGenerator: - name: app-env diff --git a/pkg/patch/strategicmergepatch.go b/pkg/patch/strategicmergepatch.go index a5cc89529..448a84530 100644 --- a/pkg/patch/strategicmergepatch.go +++ b/pkg/patch/strategicmergepatch.go @@ -22,9 +22,19 @@ package patch type PatchStrategicMerge string // Append appends a slice of patch paths to a PatchStategicMerge slice -func Append(patches []PatchStrategicMerge, paths []string) []PatchStrategicMerge { +func Append(patches []PatchStrategicMerge, paths ...string) []PatchStrategicMerge { for _, p := range paths { patches = append(patches, PatchStrategicMerge(p)) } return patches } + +// Exist determines if a patch path exists in a slice of PatchStategicMerge +func Exist(patches []PatchStrategicMerge, path string) bool { + for _, p := range patches { + if p == PatchStrategicMerge(path) { + return true + } + } + return false +} diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index 065d013bd..f9163035e 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -62,7 +62,7 @@ type Kustomization struct { // The patch files should be Stategic Merge Patch, the default patching behavior for kubectl. // https://github.com/kubernetes/community/blob/master/contributors/devel/strategic-merge-patch.md Patches []string `json:"patches,omitempty" yaml:"patches,omitempty"` - PatchesStrategicMerge []patch.PatchStrategicMerge `json:"patchesSrategicMerge,omitempty" yaml:"patchesStategicMerge,omitempty"` + PatchesStrategicMerge []patch.PatchStrategicMerge `json:"patchesStrategicMerge,omitempty" yaml:"patchesStrategicMerge,omitempty"` // JSONPatches is a list of JSONPatch for applying JSON patch. // The JSON patch is documented at https://tools.ietf.org/html/rfc6902