Skip to content

Commit

Permalink
Merge pull request #4439 from dkhater-redhat/bootstrap-e2e-test-featu…
Browse files Browse the repository at this point in the history
…regate

OCPBUGS-30603: Bootstrap e2e test featuregate setup does not match the actual code
  • Loading branch information
openshift-merge-bot[bot] authored Jul 3, 2024
2 parents d37b0a6 + 583ae9a commit edfb19f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
18 changes: 1 addition & 17 deletions cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

features "github.com/openshift/api/features"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/openshift/machine-config-operator/cmd/common"
"github.com/openshift/machine-config-operator/internal/clients"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
Expand Down Expand Up @@ -103,7 +102,7 @@ func runStartCmd(_ *cobra.Command, _ []string) {
klog.Fatalf("unable to get initial features: %v", err)
}

enabled, disabled := getEnabledDisabledFeatures(fg)
enabled, disabled := ctrlcommon.GetEnabledDisabledFeatures(fg)
klog.Infof("FeatureGates initialized: enabled=%v disabled=%v", enabled, disabled)
if fg.Enabled(features.FeatureGatePinnedImages) && fg.Enabled(features.FeatureGateMachineConfigNodes) {
pinnedImageSet := pinnedimageset.New(
Expand Down Expand Up @@ -230,18 +229,3 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle

return controllers
}

func getEnabledDisabledFeatures(features featuregates.FeatureGate) ([]string, []string) {
var enabled []string
var disabled []string

for _, feature := range features.KnownFeatures() {
if features.Enabled(feature) {
enabled = append(enabled, string(feature))
} else {
disabled = append(disabled, string(feature))
}
}

return enabled, disabled
}
47 changes: 47 additions & 0 deletions pkg/controller/common/featuregates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package common

import (
"context"
"fmt"
"time"

"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"k8s.io/klog/v2"
)

func WaitForFeatureGatesReady(ctx context.Context, featureGateAccess featuregates.FeatureGateAccess) error {
timeout := time.After(1 * time.Minute)
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-timeout:
return fmt.Errorf("timed out waiting for FeatureGates to be ready")
default:
features, err := featureGateAccess.CurrentFeatureGates()
if err == nil {
enabled, disabled := GetEnabledDisabledFeatures(features)
klog.Infof("FeatureGates initialized: enabled=%v, disabled=%v", enabled, disabled)
return nil
}
klog.Infof("Waiting for FeatureGates to be ready...")
time.Sleep(1 * time.Second)
}
}
}

// getEnabledDisabledFeatures extracts enabled and disabled features from the feature gate.
func GetEnabledDisabledFeatures(features featuregates.FeatureGate) ([]string, []string) {
var enabled []string
var disabled []string

for _, feature := range features.KnownFeatures() {
if features.Enabled(feature) {
enabled = append(enabled, string(feature))
} else {
disabled = append(disabled, string(feature))
}
}

return enabled, disabled
}
3 changes: 3 additions & 0 deletions test/e2e-bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ func newTestFixture(t *testing.T, cfg *rest.Config, objs []runtime.Object) *fixt
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OperatorInformerFactory.Start(ctrlctx.Stop)

err := ctrlcommon.WaitForFeatureGatesReady(ctx, ctrlctx.FeatureGateAccess)
require.NoError(t, err, "FeatureGates should be available before proceeding")

close(ctrlctx.InformersStarted)

for _, c := range controllers {
Expand Down

0 comments on commit edfb19f

Please sign in to comment.