@@ -63,8 +63,20 @@ const (
63
63
ActionRestart = "restart"
64
64
)
65
65
66
+ // PatchConstructorPatchT represents a 'patch' and (they way it is applied)
67
+ // returned by a PatchConstructorFuncPointerT
68
+ // TODO Move wherever it's better than here
69
+ type PatchConstructorPatchT struct {
70
+ // PatchType represents the type of patch to apply
71
+ PatchType types.PatchType
72
+
73
+ // Patch represents the patch desired to be applied
74
+ Patch []byte
75
+ }
76
+
66
77
// PatchConstructorFuncPointerT represents a pointer to a function for crafting a patch
67
- type PatchConstructorFuncPointerT func (obj * unstructured.Unstructured ) ([]byte , error )
78
+ // TODO Move wherever it's better than here
79
+ type PatchConstructorFuncPointerT func (obj * unstructured.Unstructured ) (PatchConstructorPatchT , error )
68
80
69
81
// HttpRequestAuth represents authentication params provided to a request
70
82
// TODO Move wherever it's better than here
@@ -296,18 +308,20 @@ func getPodTemplateAnnotations(obj *unstructured.Unstructured) (annotations []by
296
308
297
309
// defaultPatchConstructor return a patch valid for core workload resources (deployments, statefulsets, daemonsets)
298
310
// adding previously existing annotations from podTemplate
299
- func defaultPatchConstructor (obj * unstructured.Unstructured ) (patch [] byte , err error ) {
311
+ func defaultPatchConstructor (obj * unstructured.Unstructured ) (patch PatchConstructorPatchT , err error ) {
300
312
annotations , err := getPodTemplateAnnotations (obj )
301
313
if err != nil {
302
314
return patch , err
303
315
}
304
316
305
- patch = []byte (fmt .Sprintf (`{"spec":{"template":{"metadata":{"annotations":%s}}}}` , annotations ))
317
+ patch .Patch = []byte (fmt .Sprintf (`{"spec":{"template":{"metadata":{"annotations":%s}}}}` , annotations ))
318
+ patch .PatchType = types .StrategicMergePatchType
319
+
306
320
return patch , err
307
321
}
308
322
309
323
// deploymentPatchConstructor return a patch for deployment resources to be used in SetWorkloadRestartAnnotation
310
- func deploymentPatchConstructor (obj * unstructured.Unstructured ) (patch [] byte , err error ) {
324
+ func deploymentPatchConstructor (obj * unstructured.Unstructured ) (patch PatchConstructorPatchT , err error ) {
311
325
pausedValue , found , err := unstructured .NestedBool (obj .Object , "spec" , "paused" )
312
326
if err != nil {
313
327
return patch , err
@@ -345,13 +359,13 @@ func (r *WorkloadActionReconciler) SetWorkloadRestartAnnotation(ctx context.Cont
345
359
}
346
360
347
361
// 2. Construct the patch with related function
348
- patchBytes , err := patchConstructorMap [kind ](obj )
362
+ returnedPatch , err := patchConstructorMap [kind ](obj )
349
363
if err != nil {
350
364
return err
351
365
}
352
366
353
367
// 3. Execute the patch
354
- err = r .Patch (ctx , obj , client .RawPatch (types . StrategicMergePatchType , patchBytes ))
368
+ err = r .Patch (ctx , obj , client .RawPatch (returnedPatch . PatchType , returnedPatch . Patch ))
355
369
if err != nil {
356
370
err = fmt .Errorf (WorkloadActionAnnotationPatchErrorMessage , err )
357
371
}
0 commit comments