diff --git a/test/e2e/control_plane_upgrade_test.go b/test/e2e/control_plane_upgrade_test.go index 7662fb98270..79de742cbbd 100644 --- a/test/e2e/control_plane_upgrade_test.go +++ b/test/e2e/control_plane_upgrade_test.go @@ -8,7 +8,6 @@ import ( "testing" . "github.com/onsi/gomega" - configv1 "github.com/openshift/api/config/v1" hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" e2eutil "github.com/openshift/hypershift/test/e2e/util" crclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -69,44 +68,7 @@ func TestUpgradeControlPlane(t *testing.T) { err = mgtClient.Get(ctx, crclient.ObjectKeyFromObject(hostedCluster), hostedCluster) g.Expect(err).NotTo(HaveOccurred(), "failed to get hostedcluster") - t.Run("Verifying featureGate status has entries for the same versions as clusterVersion", func(t *testing.T) { - e2eutil.AtLeast(t, e2eutil.Version419) - - g := NewWithT(t) - - clusterVersion := &configv1.ClusterVersion{} - err = guestClient.Get(ctx, crclient.ObjectKey{Name: "version"}, clusterVersion) - g.Expect(err).NotTo(HaveOccurred(), "failed to get ClusterVersion resource") - - featureGate := &configv1.FeatureGate{} - err = guestClient.Get(ctx, crclient.ObjectKey{Name: "cluster"}, featureGate) - g.Expect(err).NotTo(HaveOccurred(), "failed to get FeatureGate resource") - - clusterVersions := make(map[string]bool) - for _, history := range clusterVersion.Status.History { - clusterVersions[history.Version] = true - } - - // check that each version in the ClusterVersion history has a corresponding entry in FeatureGate status. - for version := range clusterVersions { - found := false - for _, details := range featureGate.Status.FeatureGates { - if details.Version == version { - found = true - break - } - } - if !found { - t.Errorf("version %s found in ClusterVersion history but missing in FeatureGate status", version) - } - } - g.Expect(len(featureGate.Status.FeatureGates)).To(Equal(len(clusterVersion.Status.History)), - "Expected the same number of entries in FeatureGate status (%d) as in ClusterVersion history (%d)", - len(featureGate.Status.FeatureGates), len(clusterVersion.Status.History)) - - t.Log("Validation passed") - }) - + e2eutil.EnsureFeatureGateStatus(t, ctx, guestClient) e2eutil.EnsureNodeCountMatchesNodePoolReplicas(t, ctx, mgtClient, guestClient, hostedCluster.Spec.Platform.Type, hostedCluster.Namespace) e2eutil.EnsureNoCrashingPods(t, ctx, mgtClient, hostedCluster) e2eutil.EnsureMachineDeploymentGeneration(t, ctx, mgtClient, hostedCluster, 1) diff --git a/test/e2e/create_cluster_test.go b/test/e2e/create_cluster_test.go index 4d5de23233d..2d865e58fcc 100644 --- a/test/e2e/create_cluster_test.go +++ b/test/e2e/create_cluster_test.go @@ -1845,7 +1845,7 @@ func TestCreateCluster(t *testing.T) { e2eutil.NewHypershiftTest(t, ctx, func(t *testing.T, g Gomega, mgtClient crclient.Client, hostedCluster *hyperv1.HostedCluster) { // Sanity check the cluster by waiting for the nodes to report ready - _ = e2eutil.WaitForGuestClient(t, ctx, mgtClient, hostedCluster) + guestClient := e2eutil.WaitForGuestClient(t, ctx, mgtClient, hostedCluster) t.Logf("fetching mgmt kubeconfig") mgmtCfg, err := e2eutil.GetConfig() @@ -1871,6 +1871,7 @@ func TestCreateCluster(t *testing.T) { e2eutil.EnsureCustomLabels(t, ctx, mgtClient, hostedCluster) e2eutil.EnsureCustomTolerations(t, ctx, mgtClient, hostedCluster) e2eutil.EnsureAppLabel(t, ctx, mgtClient, hostedCluster) + e2eutil.EnsureFeatureGateStatus(t, ctx, guestClient) // ensure KAS DNS name is configured with a KAS Serving cert e2eutil.EnsureKubeAPIDNSNameCustomCert(t, ctx, mgtClient, hostedCluster) diff --git a/test/e2e/util/util.go b/test/e2e/util/util.go index 03c414ae55e..161aaaa0ff0 100644 --- a/test/e2e/util/util.go +++ b/test/e2e/util/util.go @@ -950,6 +950,41 @@ func EnsureAllContainersHaveTerminationMessagePolicyFallbackToLogsOnError(t *tes }) } +// NOTE: This function assumes that it is not called in the middle of a version rollout +// i.e. It expects that the first entry in ClusterVersion history is Completed +func EnsureFeatureGateStatus(t *testing.T, ctx context.Context, guestClient crclient.Client) { + t.Run("EnsureFeatureGateStatus", func(t *testing.T) { + AtLeast(t, Version419) + + g := NewWithT(t) + + clusterVersion := &configv1.ClusterVersion{} + err := guestClient.Get(ctx, crclient.ObjectKey{Name: "version"}, clusterVersion) + g.Expect(err).NotTo(HaveOccurred(), "failed to get ClusterVersion resource") + + featureGate := &configv1.FeatureGate{} + err = guestClient.Get(ctx, crclient.ObjectKey{Name: "cluster"}, featureGate) + g.Expect(err).NotTo(HaveOccurred(), "failed to get FeatureGate resource") + + // Expect at least one entry in ClusterVersion history + g.Expect(len(clusterVersion.Status.History)).To(BeNumerically(">", 0), "ClusterVersion history is empty") + currentVersion := clusterVersion.Status.History[0].Version + + // Expect current version to be in Completed state + g.Expect(clusterVersion.Status.History[0].State).To(Equal(configv1.CompletedUpdate), "most recent ClusterVersion history entry is not in Completed state") + + // Ensure that the current version in ClusterVersion is also present in FeatureGate status + versionFound := false + for _, details := range featureGate.Status.FeatureGates { + if details.Version == currentVersion { + versionFound = true + break + } + } + g.Expect(versionFound).To(BeTrue(), "current version %s from ClusterVersion not found in FeatureGate status", currentVersion) + }) +} + func EnsureNodeCountMatchesNodePoolReplicas(t *testing.T, ctx context.Context, hostClient, guestClient crclient.Client, platform hyperv1.PlatformType, nodePoolNamespace string) { t.Run("EnsureNodeCountMatchesNodePoolReplicas", func(t *testing.T) { var nodePoolList hyperv1.NodePoolList