Skip to content

Commit

Permalink
Merge pull request #241 from fluxcd/patch-tounstructured
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco authored Feb 21, 2022
2 parents ccbc687 + 5e55b75 commit 3c08fca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions runtime/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func NewHelper(obj client.Object, crClient client.Client) (*Helper, error) {
}

// Convert the object to unstructured to compare against our before copy.
unstructuredObj, err := toUnstructured(obj)
unstructuredObj, err := ToUnstructured(obj)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func (h *Helper) Patch(ctx context.Context, obj client.Object, opts ...Option) e
}

// Convert the object to unstructured to compare against our before copy.
h.after, err = toUnstructured(obj)
h.after, err = ToUnstructured(obj)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/patch/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func unstructuredHasStatus(u *unstructured.Unstructured) bool {
return ok
}

func toUnstructured(obj runtime.Object) (*unstructured.Unstructured, error) {
// ToUnstructured converts a runtime.Object into an Unstructured object.
func ToUnstructured(obj runtime.Object) (*unstructured.Unstructured, error) {
// If the incoming object is already unstructured, perform a deep copy first
// otherwise DefaultUnstructuredConverter ends up returning the inner map without
// making a copy.
Expand Down
4 changes: 2 additions & 2 deletions runtime/patch/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestToUnstructured(t *testing.T) {
"configmap": "true",
},
}
newObj, err := toUnstructured(obj)
newObj, err := ToUnstructured(obj)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(newObj.GetName()).To(Equal(obj.Name))
g.Expect(newObj.GetNamespace()).To(Equal(obj.Namespace))
Expand All @@ -69,7 +69,7 @@ func TestToUnstructured(t *testing.T) {
},
}

newObj, err := toUnstructured(obj)
newObj, err := ToUnstructured(obj)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(newObj.GetName()).To(Equal(obj.GetName()))
g.Expect(newObj.GetNamespace()).To(Equal(obj.GetNamespace()))
Expand Down

0 comments on commit 3c08fca

Please sign in to comment.