@@ -65,19 +65,12 @@ func NewHelper(obj client.Object, crClient client.Client) (*Helper, error) {
6565 return nil , errors .Wrapf (err , "failed to create patch helper for object %s" , klog .KObj (obj ))
6666 }
6767
68- // Convert the object to unstructured to compare against our before copy.
69- unstructuredObj , err := toUnstructured (obj , gvk )
70- if err != nil {
71- return nil , errors .Wrapf (err , "failed to create patch helper for %s %s: failed to convert object to Unstructured" , gvk .Kind , klog .KObj (obj ))
72- }
73-
7468 // Check if the object satisfies the Cluster API conditions contract.
7569 _ , canInterfaceConditions := obj .(conditions.Setter )
7670
7771 return & Helper {
7872 client : crClient ,
7973 gvk : gvk ,
80- before : unstructuredObj ,
8174 beforeObject : obj .DeepCopyObject ().(client.Object ),
8275 isConditionsSetter : canInterfaceConditions ,
8376 }, nil
@@ -105,10 +98,16 @@ func (h *Helper) Patch(ctx context.Context, obj client.Object, opts ...Option) e
10598 opt .ApplyToHelper (options )
10699 }
107100
108- // Convert the object to unstructured to compare against our before copy.
101+ // Convert the before object to unstructured.
102+ h .before , err = toUnstructured (h .beforeObject , gvk )
103+ if err != nil {
104+ return errors .Wrapf (err , "failed to patch %s %s: failed to convert before object to Unstructured" , h .gvk .Kind , klog .KObj (h .beforeObject ))
105+ }
106+
107+ // Convert the after object to unstructured.
109108 h .after , err = toUnstructured (obj , gvk )
110109 if err != nil {
111- return errors .Wrapf (err , "failed to patch %s %s: failed to convert object to Unstructured" , h .gvk .Kind , klog .KObj (h .beforeObject ))
110+ return errors .Wrapf (err , "failed to patch %s %s: failed to convert after object to Unstructured" , h .gvk .Kind , klog .KObj (h .beforeObject ))
112111 }
113112
114113 // Determine if the object has status.
0 commit comments