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

Properly handle different versioned resources in gwctl (eg. v1beta1 v/s v1 APIs) and related code cleanups #3001

Merged
merged 6 commits into from
May 2, 2024

Conversation

gauravkghildiyal
Copy link
Member

What type of PR is this?
/kind cleanup

What this PR does / why we need it:

Use API discovery to determine the preferred API versions for Gateway API types.

Clusters may not always have the v1 CRDs installed. This means gwctl will have
to use whatever version is available in the cluster. Hence, we will use API
Discovery to determine the "preferred" API version as per the kube-apiserver and
then use a dynamic client to fetch that specific versioned resource.

Once that specific versioned resource is fetched (e.g. v1beta1.Gateway), it will
be converted to a concrete type used within gwctl (eg. v1.Gateway), which will
usually be a more newer/stable version. For most cases, this conversion should
not result in any losses. If in the future, a need arises for such special
cases, we should be able to extend the approach by configuring some conversion
functions (eg. conversion function for v1beta1.Gateway -> v1.Gateway).

Which issue(s) this PR fixes:

Fixes #3000

Does this PR introduce a user-facing change?:

NONE

/area gwctl

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note. area/gwctl approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 21, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 21, 2024
@gauravkghildiyal
Copy link
Member Author

/cc @mlavacca

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2024
@gauravkghildiyal gauravkghildiyal force-pushed the api-version-fix branch 2 times, most recently from c172d6d to a9369f8 Compare May 1, 2024 21:42
The dynamic client returned for unit tests may not be smart enough to
automatically guess the APIVersion and Kind (which the real kube-apiserver can
handle automatically). To get over this, we can simply simply include these when
creating the objects.
@gauravkghildiyal gauravkghildiyal force-pushed the api-version-fix branch 2 times, most recently from 3f7ef46 to 6c18bf8 Compare May 2, 2024 02:04
@gauravkghildiyal
Copy link
Member Author

/retest

… API types.

Clusters may not always have the v1 CRDs installed. This means gwctl will have
to use whatever version is available in the cluster. Hence, we will use API
Discovery to determine the "preferred" API version as per the kube-apiserver and
then use a dynamic client to fetch that specific versioned resource.

Once that specific versioned resource is fetched (e.g. v1beta1.Gateway), it will
be converted to a concrete type used within gwctl (eg. v1.Gateway), which will
usually be a more newer/stable version. For most cases, this conversion should
not result in any losses. If in the future, a need arises for such special
cases, we should be able to extend the approach by configuring some conversion
functions (eg. conversion function for v1beta1.Gateway -> v1.Gateway).
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks @gauravkghildiyal, this looks like a great addition!

gwctl/pkg/common/clients.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal, robscott

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

@robscott
Copy link
Member

robscott commented May 2, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 2, 2024
@k8s-ci-robot k8s-ci-robot merged commit ab850c3 into kubernetes-sigs:main May 2, 2024
8 checks passed
@gauravkghildiyal gauravkghildiyal deleted the api-version-fix branch May 2, 2024 18:08
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. area/gwctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gwctl] Handle resources from multiple versions (v1, v1beta1) of Gateway API.
3 participants