Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime.Object apiVersion/kind is empty #3288

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/util/fedinformer/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ func ClusterWideKeyFunc(obj interface{}) (ClusterWideKey, error) {
return key, fmt.Errorf("object has no meta: %v", err)
}

// When using a typed client, decoding to a versioned struct (not an internal API type), the apiVersion/kind
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is APIVersion/Kind information of runtime.Object filled in when we using dynamic client?

// information will be dropped. Therefore, the APIVersion/Kind information of runtime.Object needs to be verified.
// See issue: https://github.com/kubernetes/kubernetes/issues/80609
gvk := runtimeObject.GetObjectKind().GroupVersionKind()
if len(gvk.Kind) == 0 {
return key, fmt.Errorf("runtime object has no kind")
}

if len(gvk.Version) == 0 {
return key, fmt.Errorf("runtime object has no version")
}

key.Group = gvk.Group
key.Version = gvk.Version
key.Kind = gvk.Kind
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/fedinformer/keys/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -50,6 +51,12 @@ var (
Name: "bar",
},
}
deploymentObj = appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
Name: "bar",
},
}
)

func TestClusterWideKeyFunc(t *testing.T) {
Expand Down Expand Up @@ -93,6 +100,11 @@ func TestClusterWideKeyFunc(t *testing.T) {
object: nil,
expectErr: true,
},
{
name: "non APIVersion and kind runtime object should be error",
object: deploymentObj,
expectErr: true,
},
}

for _, test := range tests {
Expand Down