@@ -35,25 +35,38 @@ import (
35
35
func ApplyPatches (ctx context.Context , object declarative.DeclarativeObject , objects * manifest.Objects ) error {
36
36
log := log .Log
37
37
38
- p , ok := object .(addonsv1alpha1.Patchable )
39
- if ! ok {
40
- return fmt .Errorf ("provided object (%T) does not implement Patchable type" , object )
41
- }
42
-
38
+ var p addonsv1alpha1.Patchable
43
39
var patches []* unstructured.Unstructured
44
40
45
- for _ , p := range p .PatchSpec ().Patches {
46
- // Object is nil, Raw is populated (with json, even when input was yaml)
47
- r := bytes .NewReader (p .Raw )
48
- decoder := yaml .NewYAMLOrJSONDecoder (r , 1024 )
49
- patch := & unstructured.Unstructured {}
41
+ unstruct , ok := object .(* unstructured.Unstructured )
42
+ if ok {
43
+ patch , _ , err := unstructured .NestedSlice (unstruct .Object , "spec" , "patches" )
44
+ if err != nil {
45
+ return fmt .Errorf ("unable to get patches from unstruct: %v" , err )
46
+ }
50
47
51
- if err := decoder .Decode (patch ); err != nil {
52
- return fmt .Errorf ("error parsing json into unstructured object: %v" , err )
48
+ for _ , p := range patch {
49
+ m := p .(map [string ]interface {})
50
+ patches = append (patches , & unstructured.Unstructured {
51
+ Object : m ,
52
+ })
53
53
}
54
- log .WithValues ("patch" , patch ).V (1 ).Info ("parsed patch" )
54
+ } else if p , ok = object .(addonsv1alpha1.Patchable ); ok {
55
+ for _ , p := range p .PatchSpec ().Patches {
56
+ // Object is nil, Raw is populated (with json, even when input was yaml)
57
+ r := bytes .NewReader (p .Raw )
58
+ decoder := yaml .NewYAMLOrJSONDecoder (r , 1024 )
59
+ patch := & unstructured.Unstructured {}
55
60
56
- patches = append (patches , patch )
61
+ if err := decoder .Decode (patch ); err != nil {
62
+ return fmt .Errorf ("error parsing json into unstructured object: %v" , err )
63
+ }
64
+ log .WithValues ("patch" , patch ).V (1 ).Info ("parsed patch" )
65
+
66
+ patches = append (patches , patch )
67
+ }
68
+ } else {
69
+ return fmt .Errorf ("provided object (%T) does not implement Patchable type" , object )
57
70
}
58
71
59
72
return objects .Patch (patches )
0 commit comments