change patches to patchesStrategicMerge in tests and examples

This commit is contained in:
Jingfang Liu
2018-08-28 09:36:45 -07:00
parent e11ba17248
commit b713d5a1cc
20 changed files with 40 additions and 28 deletions

View File

@@ -73,7 +73,7 @@ commonLabels:
who: alice who: alice
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- temperature.yaml - temperature.yaml
EOF EOF
@@ -96,7 +96,7 @@ commonLabels:
who: bob who: bob
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- topping.yaml - topping.yaml
EOF EOF

View File

@@ -67,7 +67,7 @@ commonAnnotations:
note: Hello, I am staging! note: Hello, I am staging!
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- map.yaml - map.yaml
EOF EOF

View File

@@ -156,7 +156,7 @@ commonAnnotations:
note: Hello, I am staging! note: Hello, I am staging!
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- map.yaml - map.yaml
EOF EOF
``` ```
@@ -197,7 +197,7 @@ commonAnnotations:
note: Hello, I am production! note: Hello, I am production!
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- deployment.yaml - deployment.yaml
EOF EOF
``` ```

View File

@@ -1,5 +1,5 @@
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- deployment.yaml - deployment.yaml
namePrefix: production- namePrefix: production-

View File

@@ -1,6 +1,6 @@
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- deployment.yaml - deployment.yaml
nameprefix: staging- nameprefix: staging-
configMapGenerator: configMapGenerator:

View File

@@ -150,7 +150,7 @@ Off the shelf MySQL uses `emptyDir` type volume, which
gets wiped away if the MySQL Pod is recreated, and that gets wiped away if the MySQL Pod is recreated, and that
is certainly not desirable for production is certainly not desirable for production
environment. So we want to use Persistent Disk in 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. resources.
<!-- @createPatchFile @test --> <!-- @createPatchFile @test -->
@@ -176,7 +176,7 @@ Add the patch file to `kustomization.yaml`:
<!-- @specifyPatch @test --> <!-- @specifyPatch @test -->
``` ```
cat <<'EOF' >> $DEMO_HOME/kustomization.yaml cat <<'EOF' >> $DEMO_HOME/kustomization.yaml
patches: patchesStrategicMerge:
- persistent-disk.yaml - persistent-disk.yaml
EOF EOF
``` ```
@@ -188,7 +188,7 @@ Lets break this down:
in deployment.yaml in deployment.yaml
- Then we added `persistent-disk.yaml` to list of - 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 will apply this patch to the deployment resource with
the name `mysql` as defined in the patch. the name `mysql` as defined in the patch.

View File

@@ -291,7 +291,7 @@ kustomize edit add patch healthcheck_patch.yaml
`kustomization.yaml` should have patches field: `kustomization.yaml` should have patches field:
> ``` > ```
> patches: > patchesStrategicMerge:
> - patch.yaml > - patch.yaml
> - memorylimit_patch.yaml > - memorylimit_patch.yaml
> - healthcheck_patch.yaml > - healthcheck_patch.yaml

View File

@@ -1,6 +1,6 @@
bases: bases:
- ../../base - ../../base
patches: patchesStrategicMerge:
- patch.yaml - patch.yaml
- healthcheck_patch.yaml - healthcheck_patch.yaml
- memorylimit_patch.yaml - memorylimit_patch.yaml

View File

@@ -53,7 +53,7 @@ bases:
- wordpress - wordpress
- mysql - mysql
namePrefix: demo- namePrefix: demo-
patches: patchesStrategicMerge:
- patch.yaml - patch.yaml
EOF EOF
``` ```

View File

@@ -1,7 +1,7 @@
bases: bases:
- wordpress - wordpress
- mysql - mysql
patches: patchesStrategicMerge:
- patch.yaml - patch.yaml
namePrefix: demo- namePrefix: demo-

View File

@@ -154,7 +154,7 @@ func (a *Application) loadCustomizedResMap() (resmap.ResMap, error) {
return nil, err 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) patches, err := resmap.NewResourceSliceFromPatches(a.ldr, a.kustomization.PatchesStrategicMerge)
if err != nil { if err != nil {
errs.Append(errors.Wrap(err, "NewResourceSliceFromPatches")) errs.Append(errors.Wrap(err, "NewResourceSliceFromPatches"))

View File

@@ -24,6 +24,7 @@ import (
"github.com/kubernetes-sigs/kustomize/pkg/constants" "github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/fs" "github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/patch"
) )
type addPatchOptions struct { type addPatchOptions struct {
@@ -88,12 +89,12 @@ func (o *addPatchOptions) RunAddPatch(fsys fs.FileSystem) error {
return err return err
} }
for _, patch := range patches { for _, p := range patches {
if stringInSlice(patch, m.Patches) { if patch.Exist(m.PatchesStrategicMerge, p) || stringInSlice(p, m.Patches) {
log.Printf("patch %s already in kustomization file", patch) log.Printf("patch %s already in kustomization file", p)
continue continue
} }
m.Patches = append(m.Patches, patch) m.PatchesStrategicMerge = patch.Append(m.PatchesStrategicMerge, p)
} }
return mf.write(m) return mf.write(m)

View File

@@ -47,6 +47,7 @@ var (
"CommonLabels", "CommonLabels",
"CommonAnnotations", "CommonAnnotations",
"Patches", "Patches",
"PatchesStrategicMerge",
"ConfigMapGenerator", "ConfigMapGenerator",
"SecretGenerator", "SecretGenerator",
"Vars", "Vars",

View File

@@ -109,7 +109,7 @@ vars:
bases: bases:
- ../namespaces - ../namespaces
# some descriptions for the patches # some descriptions for the patches
patches: patchesStrategicMerge:
- service.yaml - service.yaml
- pod.yaml - pod.yaml
`) `)
@@ -165,7 +165,7 @@ BASES:
# some descriptions for the patches # some descriptions for the patches
patches: patchesStrategicMerge:
- service.yaml - service.yaml
- pod.yaml - pod.yaml
`) `)
@@ -200,7 +200,7 @@ bases:
# some descriptions for the patches # some descriptions for the patches
patches: patchesStrategicMerge:
- service.yaml - service.yaml
- pod.yaml - pod.yaml
`) `)

View File

@@ -1,7 +1,7 @@
namePrefix: staging- namePrefix: staging-
commonLabels: commonLabels:
env: staging env: staging
patches: patchesStrategicMerge:
- deployment-patch2.yaml - deployment-patch2.yaml
- deployment-patch1.yaml - deployment-patch1.yaml
bases: bases:

View File

@@ -1,7 +1,7 @@
namePrefix: staging- namePrefix: staging-
commonLabels: commonLabels:
env: staging env: staging
patches: patchesStrategicMerge:
- patches/deployment-patch1.yaml - patches/deployment-patch1.yaml
- patches/deployment-patch2.yaml - patches/deployment-patch2.yaml
bases: bases:

View File

@@ -2,7 +2,7 @@ namePrefix: staging-
commonLabels: commonLabels:
env: staging env: staging
team: override-foo team: override-foo
patches: patchesStrategicMerge:
- deployment.yaml - deployment.yaml
bases: bases:
- ../package/ - ../package/

View File

@@ -7,7 +7,7 @@ commonAnnotations:
note: This is a test annotation note: This is a test annotation
bases: bases:
- ../../package/ - ../../package/
patches: patchesStrategicMerge:
- deployment/deployment.yaml - deployment/deployment.yaml
configMapGenerator: configMapGenerator:
- name: app-env - name: app-env

View File

@@ -22,9 +22,19 @@ package patch
type PatchStrategicMerge string type PatchStrategicMerge string
// Append appends a slice of patch paths to a PatchStategicMerge slice // 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 { for _, p := range paths {
patches = append(patches, PatchStrategicMerge(p)) patches = append(patches, PatchStrategicMerge(p))
} }
return patches 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
}

View File

@@ -62,7 +62,7 @@ type Kustomization struct {
// The patch files should be Stategic Merge Patch, the default patching behavior for kubectl. // 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 // https://github.com/kubernetes/community/blob/master/contributors/devel/strategic-merge-patch.md
Patches []string `json:"patches,omitempty" yaml:"patches,omitempty"` 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. // JSONPatches is a list of JSONPatch for applying JSON patch.
// The JSON patch is documented at https://tools.ietf.org/html/rfc6902 // The JSON patch is documented at https://tools.ietf.org/html/rfc6902