@@ -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"
@@ -181,15 +218,15 @@ spec:
181
218
` ,
182
219
},
183
220
{
184
- name : "strategic merge with target test" ,
221
+ name : "targeted strategic merge test" ,
185
222
renderedManifests : strategicMergeMock ,
186
- patchesStrategicMerge : `
223
+ patches : `
187
224
- target:
188
225
group: apps
189
226
version: v1
190
227
kind: Deployment
191
228
name: nginx
192
- patch:
229
+ patch: |
193
230
apiVersion: apps/v1
194
231
kind: Deployment
195
232
metadata:
@@ -216,7 +253,11 @@ spec:
216
253
}
217
254
for _ , tt := range tests {
218
255
t .Run (tt .name , func (t * testing.T ) {
219
- 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
+ }
220
261
k := & postRendererKustomize {
221
262
spec : spec ,
222
263
}
@@ -232,7 +273,11 @@ spec:
232
273
}
233
274
}
234
275
235
- 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
+ }
236
281
b , err := yaml .YAMLToJSON ([]byte (patchesStrategicMerge ))
237
282
if err != nil {
238
283
return nil , err
@@ -250,6 +295,7 @@ func mockKustomize(patchesStrategicMerge, patchesJson6902, images string) (*v2.K
250
295
return nil , err
251
296
}
252
297
return & v2.Kustomize {
298
+ Patches : targeted ,
253
299
PatchesStrategicMerge : strategicMerge ,
254
300
PatchesJSON6902 : json6902 ,
255
301
Images : imgs ,
0 commit comments