diff --git a/resource/composed/composed.go b/resource/composed/composed.go index 57495d8..0cce9e1 100644 --- a/resource/composed/composed.go +++ b/resource/composed/composed.go @@ -43,14 +43,10 @@ func New() *Unstructured { } // To converts a unstructured composed resource to the provided object. -func To(un *Unstructured, obj interface{}) error { - rt, ok := obj.(runtime.Object) - if !ok { - return errors.New("object is not a compatible runtime.Object") - } +func To[T runtime.Object](un *Unstructured, obj T) error { // Get known GVKs for the runtime object type - knownGVKs, _, err := Scheme.ObjectKinds(rt) + knownGVKs, _, err := Scheme.ObjectKinds(obj) if err != nil { return errors.Errorf("could not retrieve GVKs for the provided object: %v", err) } diff --git a/resource/composed/composed_test.go b/resource/composed/composed_test.go index 13c5ceb..ebf6241 100644 --- a/resource/composed/composed_test.go +++ b/resource/composed/composed_test.go @@ -241,7 +241,7 @@ func TestTo(t *testing.T) { v1beta1.AddToScheme(Scheme) type args struct { un *Unstructured - obj interface{} + obj runtime.Object } type want struct { obj interface{} @@ -316,23 +316,6 @@ func TestTo(t *testing.T) { err: errors.New("GVK /test.example.io, Kind=Unknown is not known by the scheme for the provided object type"), }, }, - "NoRuntimeObject": { - reason: "Should only convert to a object if the object is a runtime.Object", - args: args{ - un: &Unstructured{Unstructured: unstructured.Unstructured{Object: map[string]any{ - "apiVersion": v1beta1.CRDGroupVersion.String(), - "kind": v1beta1.Bucket_Kind, - "metadata": map[string]any{ - "name": "cool-bucket", - }, - }}}, - obj: "not-a-runtime-object", - }, - want: want{ - obj: string("not-a-runtime-object"), - err: errors.New("object is not a compatible runtime.Object"), - }, - }, } for name, tc := range cases {