Skip to content

Commit 8859a42

Browse files
committed
Fix a panic in GVRFromType for structured types
1 parent 110f03d commit 8859a42

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/util/utils.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"runtime"
2222
"strings"
2323

24-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24+
"k8s.io/apimachinery/pkg/api/meta"
2525
"k8s.io/apimachinery/pkg/runtime/schema"
2626
"k8s.io/client-go/discovery"
2727
"k8s.io/client-go/dynamic"
@@ -142,7 +142,11 @@ func GVRFromType(resourceName string, expectedType interface{}) *schema.GroupVer
142142
// testUnstructuredMock.Foo is a mock type for testing
143143
return nil
144144
}
145-
apiVersion := expectedType.(*unstructured.Unstructured).Object["apiVersion"].(string)
145+
t, err := meta.TypeAccessor(expectedType)
146+
if err != nil {
147+
panic(err)
148+
}
149+
apiVersion := t.GetAPIVersion()
146150
g, v, found := strings.Cut(apiVersion, "/")
147151
if !found {
148152
g = "core"

0 commit comments

Comments
 (0)