-
Notifications
You must be signed in to change notification settings - Fork 843
wip: generate openshift feature gates based on upstream feature gate state #2994
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
Draft
everettraven
wants to merge
6
commits into
openshift:master
Choose a base branch
from
everettraven:poc/tooling/upstream-featuregates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
deb4e1e
tooling: generate openshift feature gates based on upstream feature g…
everettraven 595cfd6
deps: update go mod and vendor
everettraven 9e94d91
features: add ability to set group-kind-resource pairings to feature …
everettraven 2b565c4
deps: go mod tidy + vendor
everettraven 2c3c17d
wip: add apis to be enabled for CoordinatedLeaderElection gate
everettraven 961008a
fixup! always sort descending priority order
everettraven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package features | ||
|
|
||
| import ( | ||
| "slices" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| "k8s.io/apimachinery/pkg/version" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| ) | ||
|
|
||
| // GroupVersionResourcesForFeatureGate is intended to be used to fetch the appropriate group-version-resource | ||
| // pairings for a given feature gate name for upstream Kubernetes feature gates that have an OpenShift equivalent gate. | ||
| // This is so that it can be used to configure the kube-apiserver with the correct --runtime-config options | ||
| // to only ever enable the most up-to-date versions of an API that a gate depends on. | ||
| // This will only ever return GVRs for alpha or beta APIs. Stable APIs are served by default and therefore do not require | ||
| // an explicit --runtime-config entry. | ||
| // If the provided gate does not exist or is a stable API version, the return value will be nil. | ||
| func GroupVersionResourcesForFeatureGate(featureGate configv1.FeatureGateName) []schema.GroupVersionResource { | ||
| gateStatuses, ok := allFeatureGates[featureGate] | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| // aggregate GRs across all gate statuses. Realistically, this should only ever be a single | ||
| // gate status for upstream equivalent gates. | ||
| groupKindResources := sets.New[groupKindResource]() | ||
| for _, status := range gateStatuses { | ||
| groupKindResources.Insert(status.groupKindResources.UnsortedList()...) | ||
| } | ||
|
|
||
| gvrs := []schema.GroupVersionResource{} | ||
|
|
||
| for _, gkr := range groupKindResources.UnsortedList() { | ||
| versions := scheme.Scheme.VersionsForGroupKind(schema.GroupKind{Group: gkr.Group, Kind: gkr.Kind}) | ||
|
|
||
| // ensure that we are always sorting in descending order of version priority | ||
| slices.SortFunc(versions, func(a, b schema.GroupVersion) int { | ||
| return version.CompareKubeAwareVersionStrings(b.Version, a.Version) | ||
| }) | ||
|
|
||
| if len(versions) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| gvrs = append(gvrs, schema.GroupVersionResource{ | ||
| Group: versions[0].Group, | ||
| Version: versions[0].Version, | ||
| Resource: gkr.Resource, | ||
| }) | ||
| } | ||
|
|
||
| return gvrs | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Preserve the documented nil return value.
A known gate with no resource mappings returns a non-nil empty slice. A known gate with no registered API version also returns a non-nil empty slice. Lines 16 and the function contract specify
nilfor these cases.Declare
gvrswithout an empty literal so it remains nil until an entry is appended.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents