Skip to content

Commit e83396a

Browse files
committed
Adjust to DefaultUnstructuredConverter implementing omitzero
1 parent 5b49e6c commit e83396a

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
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

util/patch/utils.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ var (
4343
}
4444
)
4545

46-
func unstructuredHasStatus(u *unstructured.Unstructured) bool {
47-
_, ok := u.Object["status"]
48-
return ok
49-
}
50-
5146
// toUnstructured converts an object to Unstructured.
5247
// We have to pass in a gvk as we can't rely on GVK being set in a runtime.Object.
5348
func toUnstructured(obj runtime.Object, gvk schema.GroupVersionKind) (*unstructured.Unstructured, error) {

0 commit comments

Comments
 (0)