Skip to content

🐛 Restmapper: Respect preferred version #3151

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

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

alvaroaleman
Copy link
Member

When requesting a resource without version through methods such as RESTMapping, the mapper would previously return a random version rather than the preferred one, this change fixes that.

Fixes #3133
/cherrypick release-0.20

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 9, 2025
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 9, 2025
@@ -246,10 +246,18 @@ func (m *mapper) addGroupVersionResourcesToCacheAndReloadLocked(gvr map[schema.G
}

if !found {
groupResources.Group.Versions = append(groupResources.Group.Versions, metav1.GroupVersionForDiscovery{
doc := metav1.GroupVersionForDiscovery{
Copy link
Contributor

Choose a reason for hiding this comment

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

What is doc a short-name for?

Copy link
Member Author

Choose a reason for hiding this comment

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

document

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
doc := metav1.GroupVersionForDiscovery{
gv := metav1.GroupVersionForDiscovery{

Short for GroupVersion. Just a suggestion. A short variable name makes sense here since the scope of the variable is short. Curious to know what doc/document has to do with this. 🤔

Copy link

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

I've tested this fix in Flux and the issue with preferred version is gone. Thanks @alvaroaleman 🥇

@k8s-ci-robot
Copy link
Contributor

@stefanprodan: changing LGTM is restricted to collaborators

In response to this:

LGTM

I've tested this fix in Flux and the issue with preferred version is gone. Thanks @alvaroaleman 🥇

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, stefanprodan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Kind: "Driver",
})
g.Expect(err).NotTo(gmg.HaveOccurred())
g.Expect(mapping.GroupVersionKind.Version).To(gmg.Equal("v2"))
Copy link
Member

@sbueringer sbueringer Mar 13, 2025

Choose a reason for hiding this comment

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

Q: Just curious. What makes v2 the preferred version in this test?

Does the apiserver have some logic that prefers v2 over v1?

(maybe worth adding a godoc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment

Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

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

Just a minor nit question/comment from me. Otherwise LGTM! Thanks a lot for looking into this!

@@ -246,10 +246,18 @@ func (m *mapper) addGroupVersionResourcesToCacheAndReloadLocked(gvr map[schema.G
}

if !found {
groupResources.Group.Versions = append(groupResources.Group.Versions, metav1.GroupVersionForDiscovery{
doc := metav1.GroupVersionForDiscovery{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
doc := metav1.GroupVersionForDiscovery{
gv := metav1.GroupVersionForDiscovery{

Short for GroupVersion. Just a suggestion. A short variable name makes sense here since the scope of the variable is short. Curious to know what doc/document has to do with this. 🤔

When requesting a resource without version through methods
such as `RESTMapping`, the mapper would previously return a random
version rather than the preferred one, this change fixes that.
Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 15, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: ea6e2e638195caece1d1772f211f8ffc66713be6

@k8s-ci-robot k8s-ci-robot merged commit 183de45 into kubernetes-sigs:main Mar 15, 2025
9 checks passed
@k8s-infra-cherrypick-robot

@alvaroaleman: new pull request created: #3159

In response to this:

When requesting a resource without version through methods such as RESTMapping, the mapper would previously return a random version rather than the preferred one, this change fixes that.

Fixes #3133
/cherrypick release-0.20

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@sbueringer
Copy link
Member

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RESTMapper randomly returns API versions
7 participants