-
Notifications
You must be signed in to change notification settings - Fork 68
✨ OPRUN-4232: Refactor e2e tests to support feature-gate aware skipping #2293
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
openshift-merge-bot
merged 1 commit into
operator-framework:main
from
tmshort:rm-experimental-e2e
Oct 31, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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,108 @@ | ||
| // Package utils provides helper functions for e2e tests, including | ||
| // feature gate detection and validation utilities. | ||
| package utils | ||
|
|
||
| import ( | ||
| "strings" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| "k8s.io/component-base/featuregate" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| catdfeatures "github.com/operator-framework/operator-controller/internal/catalogd/features" | ||
| opconfeatures "github.com/operator-framework/operator-controller/internal/operator-controller/features" | ||
| ) | ||
|
|
||
| var ( | ||
| featureGateStatus map[string]bool | ||
| featureGateStatusOnce sync.Once | ||
| ) | ||
|
|
||
| const ( | ||
| fgPrefix = "--feature-gates=" | ||
| ) | ||
|
|
||
| // SkipIfFeatureGateDisabled skips the test if the specified feature gate is disabled. | ||
| // It queries the OLM deployments to detect feature gate settings and falls back to | ||
| // programmatic defaults if the feature gate is not explicitly configured. | ||
| func SkipIfFeatureGateDisabled(t *testing.T, fg string) { | ||
| if !isFeatureGateEnabled(t, fg) { | ||
| t.Skipf("Feature-gate %q disabled", fg) | ||
| } | ||
| } | ||
|
|
||
| func isFeatureGateEnabled(t *testing.T, fg string) bool { | ||
| gatherFeatureGates(t) | ||
| enabled, ok := featureGateStatus[fg] | ||
| if ok { | ||
| return enabled | ||
| } | ||
|
|
||
| // Not found (i.e. not explicitly set), so we need to find the programmed default. | ||
| // Because feature-gates are organized by catd/opcon, we need to check each individually. | ||
| // To avoid a panic, we need to check if it's a known gate first. | ||
| mfgs := []featuregate.MutableFeatureGate{ | ||
| catdfeatures.CatalogdFeatureGate, | ||
| opconfeatures.OperatorControllerFeatureGate, | ||
| } | ||
| f := featuregate.Feature(fg) | ||
| for _, mfg := range mfgs { | ||
| known := mfg.GetAll() | ||
| if _, ok := known[f]; ok { | ||
| e := mfg.Enabled(f) | ||
| t.Logf("Feature-gate %q not found in arguments, defaulting to %v", fg, e) | ||
| return e | ||
| } | ||
| } | ||
|
|
||
| t.Fatalf("Unknown feature-gate: %q", fg) | ||
| return false // unreachable, but required for compilation | ||
| } | ||
|
|
||
| func processFeatureGate(t *testing.T, featureGateValue string) { | ||
| fgvs := strings.Split(featureGateValue, ",") | ||
| for _, fg := range fgvs { | ||
| v := strings.Split(fg, "=") | ||
| require.Len(t, v, 2, "invalid feature-gate format: %q (expected name=value)", fg) | ||
| switch v[1] { | ||
| case "true": | ||
| featureGateStatus[v[0]] = true | ||
| t.Logf("Feature-gate %q enabled", v[0]) | ||
| case "false": | ||
| featureGateStatus[v[0]] = false | ||
| t.Logf("Feature-gate %q disabled", v[0]) | ||
| default: | ||
| t.Fatalf("invalid feature-gate value: %q (expected true or false)", fg) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func gatherFeatureGatesFromDeployment(t *testing.T, dep *appsv1.Deployment) { | ||
| for _, con := range dep.Spec.Template.Spec.Containers { | ||
| for _, arg := range con.Args { | ||
| if strings.HasPrefix(arg, fgPrefix) { | ||
| processFeatureGate(t, strings.TrimPrefix(arg, fgPrefix)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func gatherFeatureGates(t *testing.T) { | ||
| featureGateStatusOnce.Do(func() { | ||
| featureGateStatus = make(map[string]bool) | ||
|
|
||
| depList := &appsv1.DeploymentList{} | ||
| err := c.List(t.Context(), depList, client.MatchingLabels{ | ||
| "app.kubernetes.io/part-of": "olm", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Len(t, depList.Items, 2) | ||
|
|
||
| for _, d := range depList.Items { | ||
| gatherFeatureGatesFromDeployment(t, &d) | ||
| } | ||
| }) | ||
| } | ||
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.
Nit: I would reorder these functions so they are in the order they're used so a human reading the code doesn't have to scroll to the bottom and then work their way back up.
Current order:
Suggested Order:
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.
But you can tell I'm a C programmer this way!
(But yeah, I hear you)