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

🐛 Fix namespaced GVK check to use version #2875

Merged
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pkg/client/apiutil/apimachinery.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func IsObjectNamespaced(obj runtime.Object, scheme *runtime.Scheme, restmapper m
// IsGVKNamespaced returns true if the object having the provided
// GVK is namespace scoped.
func IsGVKNamespaced(gvk schema.GroupVersionKind, restmapper meta.RESTMapper) (bool, error) {
restmapping, err := restmapper.RESTMapping(schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind})
restmapping, err := restmapper.RESTMapping(schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind}, gvk.Version)
Copy link
Member

Choose a reason for hiding this comment

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

Could we add a test case and the PR description reasoning as a comment above here?

Copy link
Contributor Author

@griffindvs griffindvs Jul 6, 2024

Choose a reason for hiding this comment

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

I added a comment and four unit tests in eb03471. If we compare the results of these tests with and without the change:

Without the change (no Version included):

--- FAIL: TestApiMachinery (3.70s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_GVK_registered_at_initialization (0.01s)
    --- FAIL: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_new_Kind_and_Version_added_to_existing_Group (0.03s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_new_Kind_added_to_existing_Group_and_Version (0.03s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_new_GVK (0.04s)

With the change (version included):

--- PASS: TestApiMachinery (3.63s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_GVK_registered_at_initialization (0.00s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_new_Kind_and_Version_added_to_existing_Group (0.02s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_new_Kind_added_to_existing_Group_and_Version (0.02s)
    --- PASS: TestApiMachinery/IsGVKNamespaced_should_report_scope_for_new_GVK (0.02s)

The test case that fails without the change mimics the linked issue where a new Kind and Version are added to a pre-existing Group.

if err != nil {
return false, fmt.Errorf("failed to get restmapping: %w", err)
}
Expand Down