diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 837a0fd56..49eb6e219 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -21,7 +21,7 @@ import ( "runtime" "strings" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" @@ -142,7 +142,12 @@ func GVRFromType(resourceName string, expectedType interface{}) *schema.GroupVer // testUnstructuredMock.Foo is a mock type for testing return nil } - apiVersion := expectedType.(*unstructured.Unstructured).Object["apiVersion"].(string) + t, err := meta.TypeAccessor(expectedType) + if err != nil { + klog.ErrorS(err, "Failed to get type accessor", "expectedType", expectedType) + return nil + } + apiVersion := t.GetAPIVersion() g, v, found := strings.Cut(apiVersion, "/") if !found { g = "core"