Skip to content

Commit ffb77a6

Browse files
committed
Adjust to DefaultUnstructuredConverter implementing omitzero
1 parent 4e8769f commit ffb77a6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

util/patch/patch.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,16 @@ func (h *Helper) Patch(ctx context.Context, obj client.Object, opts ...Option) e
143143
return errors.Wrapf(err, "failed to patch %s %s: failed to convert after object to Unstructured", h.gvk.Kind, klog.KObj(h.beforeObject))
144144
}
145145

146-
// Determine if the object has status.
147-
if unstructuredHasStatus(h.after) {
148-
if options.IncludeStatusObservedGeneration {
149-
// Set status.observedGeneration if we're asked to do so.
150-
if err := unstructured.SetNestedField(h.after.Object, h.after.GetGeneration(), "status", "observedGeneration"); err != nil {
151-
return errors.Wrapf(err, "failed to patch %s %s: failed to set .status.observedGeneration", h.gvk.Kind, klog.KObj(h.beforeObject))
152-
}
146+
// Include .status.observedGeneration if IncludeStatusObservedGeneration is set.
147+
if options.IncludeStatusObservedGeneration {
148+
// Set status.observedGeneration if we're asked to do so.
149+
if err := unstructured.SetNestedField(h.after.Object, h.after.GetGeneration(), "status", "observedGeneration"); err != nil {
150+
return errors.Wrapf(err, "failed to patch %s %s: failed to set .status.observedGeneration", h.gvk.Kind, klog.KObj(h.beforeObject))
151+
}
153152

154-
// Restore the changes back to the original object.
155-
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(h.after.Object, obj); err != nil {
156-
return errors.Wrapf(err, "failed to patch %s %s: failed to converted object from Unstructured", h.gvk.Kind, klog.KObj(h.beforeObject))
157-
}
153+
// Restore the changes back to the original object.
154+
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(h.after.Object, obj); err != nil {
155+
return errors.Wrapf(err, "failed to patch %s %s: failed to converted object from Unstructured", h.gvk.Kind, klog.KObj(h.beforeObject))
158156
}
159157
}
160158

0 commit comments

Comments
 (0)