Skip to content

Commit 4d2ac57

Browse files
dhaiducekopenshift-merge-bot[bot]
authored andcommitted
Fix PatchesStrategicMerge deprecation warning
ref: https://issues.redhat.com/browse/ACM-8984 Signed-off-by: Dale Haiducek <[email protected]>
1 parent ccf78c6 commit 4d2ac57

File tree

7 files changed

+35
-14
lines changed

7 files changed

+35
-14
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
13
resources:
24
- nginx-pod.yaml
35
labels:
4-
- pairs:
5-
app: myapp
6+
- pairs:
7+
app: myapp

examples/input-kustomize/dev/kustomization.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
13
resources:
24
- ../base
35
namePrefix: dev-

examples/input-kustomize/kustomization.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
13
resources:
24
- dev
35
- prod
4-

examples/input-kustomize/prod/kustomization.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
13
resources:
24
- ../base
35
namePrefix: prod-

examples/kustomization.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
14
generators:
25
- ./policyGenerator.yaml
36
- ./policyGenerator-kustomize.yaml
4-
patchesStrategicMerge:
5-
- input/patch.yaml
6-
commonLabels:
7-
custom: myApp
7+
8+
patches:
9+
- path: input/patch.yaml
10+
11+
labels:
12+
- includeSelectors: true
13+
pairs:
14+
custom: myApp

internal/patches.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func (m *manifestPatcher) ApplyPatches() ([]map[string]interface{}, error) {
175175
}
176176

177177
kustomizationYAMLFile := map[string][]interface{}{
178-
"resources": {},
179-
"patchesStrategicMerge": {},
178+
"resources": {},
179+
"patches": {},
180180
}
181181

182182
options := []struct {
@@ -185,7 +185,7 @@ func (m *manifestPatcher) ApplyPatches() ([]map[string]interface{}, error) {
185185
objects []map[string]interface{}
186186
}{
187187
{"manifest", "resources", m.manifests},
188-
{"patch", "patchesStrategicMerge", m.patches},
188+
{"patch", "patches", m.patches},
189189
}
190190
for _, option := range options {
191191
for i, object := range option.objects {
@@ -205,9 +205,15 @@ func (m *manifestPatcher) ApplyPatches() ([]map[string]interface{}, error) {
205205
return nil, fmt.Errorf(errTemplate, option.optionType, err)
206206
}
207207

208-
kustomizationYAMLFile[option.kustomizeKey] = append(
209-
kustomizationYAMLFile[option.kustomizeKey], manifestFileName,
210-
)
208+
if option.kustomizeKey != "patches" {
209+
kustomizationYAMLFile[option.kustomizeKey] = append(
210+
kustomizationYAMLFile[option.kustomizeKey], manifestFileName,
211+
)
212+
} else {
213+
kustomizationYAMLFile[option.kustomizeKey] = append(
214+
kustomizationYAMLFile[option.kustomizeKey], map[string]interface{}{"path": manifestFileName},
215+
)
216+
}
211217
}
212218
}
213219

internal/patches_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ func TestApplyPatchesInvalidPatch(t *testing.T) {
288288
patcher := manifestPatcher{manifests: manifests, patches: patches}
289289
_, err := patcher.ApplyPatches()
290290

291-
expected := "failed to apply the patch(es) to the manifest(s) using Kustomize: no matches " +
291+
expected := "failed to apply the patch(es) to the manifest(s) using Kustomize: no resource " +
292+
"matches strategic merge patch \"ToasterOven.v1.[noGrp]/configmap2.default\": no matches " +
292293
"for Id ToasterOven.v1.[noGrp]/configmap2.default; failed to find unique target for patch " +
293294
"ToasterOven.v1.[noGrp]/configmap2.default"
294295
assertEqual(t, err.Error(), expected)

0 commit comments

Comments
 (0)