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

@@ -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"))

View File

@@ -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)

View File

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

View File

@@ -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
`)

View File

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

View File

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

View File

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

View File

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

View File

@@ -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
}

View File

@@ -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