mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
change patches to patchesStrategicMerge in tests and examples
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ commonAnnotations:
|
||||
note: Hello, I am staging!
|
||||
bases:
|
||||
- ../../base
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- map.yaml
|
||||
EOF
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
bases:
|
||||
- ../../base
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- deployment.yaml
|
||||
namePrefix: production-
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
bases:
|
||||
- ../../base
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- deployment.yaml
|
||||
nameprefix: staging-
|
||||
configMapGenerator:
|
||||
|
||||
@@ -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.
|
||||
|
||||
<!-- @createPatchFile @test -->
|
||||
@@ -176,7 +176,7 @@ Add the patch file to `kustomization.yaml`:
|
||||
<!-- @specifyPatch @test -->
|
||||
```
|
||||
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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
bases:
|
||||
- ../../base
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- patch.yaml
|
||||
- healthcheck_patch.yaml
|
||||
- memorylimit_patch.yaml
|
||||
|
||||
@@ -53,7 +53,7 @@ bases:
|
||||
- wordpress
|
||||
- mysql
|
||||
namePrefix: demo-
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- patch.yaml
|
||||
EOF
|
||||
```
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
bases:
|
||||
- wordpress
|
||||
- mysql
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- patch.yaml
|
||||
namePrefix: demo-
|
||||
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -47,6 +47,7 @@ var (
|
||||
"CommonLabels",
|
||||
"CommonAnnotations",
|
||||
"Patches",
|
||||
"PatchesStrategicMerge",
|
||||
"ConfigMapGenerator",
|
||||
"SecretGenerator",
|
||||
"Vars",
|
||||
|
||||
@@ -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
|
||||
`)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- deployment-patch2.yaml
|
||||
- deployment-patch1.yaml
|
||||
bases:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- patches/deployment-patch1.yaml
|
||||
- patches/deployment-patch2.yaml
|
||||
bases:
|
||||
|
||||
@@ -2,7 +2,7 @@ namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
team: override-foo
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- deployment.yaml
|
||||
bases:
|
||||
- ../package/
|
||||
|
||||
@@ -7,7 +7,7 @@ commonAnnotations:
|
||||
note: This is a test annotation
|
||||
bases:
|
||||
- ../../package/
|
||||
patches:
|
||||
patchesStrategicMerge:
|
||||
- deployment/deployment.yaml
|
||||
configMapGenerator:
|
||||
- name: app-env
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user