Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions test/e2e/control_plane_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/create_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down