@@ -63,6 +63,7 @@ func Test_postRendererKustomize_Run(t *testing.T) {
63
63
tests := []struct {
64
64
name string
65
65
renderedManifests string
66
+ patches string
66
67
patchesStrategicMerge string
67
68
patchesJson6902 string
68
69
images string
@@ -146,6 +147,42 @@ spec:
146
147
` ,
147
148
expectManifests : `apiVersion: v1
148
149
kind: Pod
150
+ metadata:
151
+ annotations:
152
+ d: "42"
153
+ e: "42"
154
+ name: json6902
155
+ ` ,
156
+ },
157
+ {
158
+ name : "targeted json 6902" ,
159
+ renderedManifests : json6902Mock ,
160
+ patches : `
161
+ - target:
162
+ version: v1
163
+ kind: Pod
164
+ name: json6902
165
+ patch: |
166
+ - op: test
167
+ path: /metadata/annotations/c
168
+ value: foo
169
+ - op: remove
170
+ path: /metadata/annotations/c
171
+ - op: add
172
+ path: /metadata/annotations/c
173
+ value: [ "foo", "bar" ]
174
+ - op: replace
175
+ path: /metadata/annotations/c
176
+ value: 42
177
+ - op: move
178
+ from: /metadata/annotations/c
179
+ path: /metadata/annotations/d
180
+ - op: copy
181
+ from: /metadata/annotations/d
182
+ path: /metadata/annotations/e
183
+ ` ,
184
+ expectManifests : `apiVersion: v1
185
+ kind: Pod
149
186
metadata:
150
187
annotations:
151
188
d: "42"
@@ -170,6 +207,39 @@ metadata:
170
207
` ,
171
208
expectManifests : `apiVersion: apps/v1
172
209
kind: Deployment
210
+ metadata:
211
+ name: nginx
212
+ spec:
213
+ template:
214
+ spec:
215
+ containers:
216
+ - image: nignx:latest
217
+ name: nginx
218
+ ` ,
219
+ },
220
+ {
221
+ name : "targeted strategic merge test" ,
222
+ renderedManifests : strategicMergeMock ,
223
+ patches : `
224
+ - target:
225
+ group: apps
226
+ version: v1
227
+ kind: Deployment
228
+ name: nginx
229
+ patch: |
230
+ apiVersion: apps/v1
231
+ kind: Deployment
232
+ metadata:
233
+ name: nginx
234
+ spec:
235
+ template:
236
+ spec:
237
+ containers:
238
+ - name: nginx
239
+ image: nignx:latest
240
+ ` ,
241
+ expectManifests : `apiVersion: apps/v1
242
+ kind: Deployment
173
243
metadata:
174
244
name: nginx
175
245
spec:
@@ -183,7 +253,11 @@ spec:
183
253
}
184
254
for _ , tt := range tests {
185
255
t .Run (tt .name , func (t * testing.T ) {
186
- spec , err := mockKustomize (tt .patchesStrategicMerge , tt .patchesJson6902 , tt .images )
256
+ spec , err := mockKustomize (tt .patches , tt .patchesStrategicMerge , tt .patchesJson6902 , tt .images )
257
+ if err != nil {
258
+ t .Errorf ("Run() mockKustomize returned %v" , err )
259
+ return
260
+ }
187
261
k := & postRendererKustomize {
188
262
spec : spec ,
189
263
}
@@ -199,7 +273,11 @@ spec:
199
273
}
200
274
}
201
275
202
- func mockKustomize (patchesStrategicMerge , patchesJson6902 , images string ) (* v2.Kustomize , error ) {
276
+ func mockKustomize (patches , patchesStrategicMerge , patchesJson6902 , images string ) (* v2.Kustomize , error ) {
277
+ var targeted []kustomize.Patch
278
+ if err := yaml .Unmarshal ([]byte (patches ), & targeted ); err != nil {
279
+ return nil , err
280
+ }
203
281
b , err := yaml .YAMLToJSON ([]byte (patchesStrategicMerge ))
204
282
if err != nil {
205
283
return nil , err
@@ -217,6 +295,7 @@ func mockKustomize(patchesStrategicMerge, patchesJson6902, images string) (*v2.K
217
295
return nil , err
218
296
}
219
297
return & v2.Kustomize {
298
+ Patches : targeted ,
220
299
PatchesStrategicMerge : strategicMerge ,
221
300
PatchesJSON6902 : json6902 ,
222
301
Images : imgs ,
0 commit comments