diff --git a/test/extended/baremetal/common.go b/test/extended/baremetal/common.go index 94d98d5ab4b3..ee5dc9604028 100644 --- a/test/extended/baremetal/common.go +++ b/test/extended/baremetal/common.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "sync" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" @@ -16,10 +17,33 @@ import ( e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" ) +var ( + clusterInfraMu sync.Mutex + clusterInfra *configv1.Infrastructure + clusterInfraFetched bool +) + +// clusterInfrastructure returns the cluster Infrastructure object. A successful fetch is cached for +// the rest of the process; if Get fails, nothing is cached and the next call retries. +func clusterInfrastructure(oc *exutil.CLI) (*configv1.Infrastructure, error) { + clusterInfraMu.Lock() + defer clusterInfraMu.Unlock() + if clusterInfraFetched { + return clusterInfra, nil + } + infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get( + context.Background(), "cluster", metav1.GetOptions{}) + if err == nil { + clusterInfra = infra + clusterInfraFetched = true + } + return infra, err +} + func skipIfNotBaremetal(oc *exutil.CLI) { g.By("checking platform type") - infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{}) + infra, err := clusterInfrastructure(oc) o.Expect(err).NotTo(o.HaveOccurred()) if infra.Status.PlatformStatus.Type != configv1.BareMetalPlatformType { @@ -27,6 +51,14 @@ func skipIfNotBaremetal(oc *exutil.CLI) { } } +func skipIfTwoNode(oc *exutil.CLI) { + infra, err := clusterInfrastructure(oc) + o.Expect(err).NotTo(o.HaveOccurred()) + if infra.Status.ControlPlaneTopology == configv1.DualReplicaTopologyMode { + e2eskipper.Skipf("This test does not apply to two-node") + } +} + // Starting from 4.10, metal3 resources could be created in the vSphere, OpenStack and None // Platforms in addition to the Baremetal Platform. // Starting from 4.12, metal3 resources could be created in the AWS Platform too. @@ -35,7 +67,7 @@ func skipIfNotBaremetal(oc *exutil.CLI) { func skipIfUnsupportedPlatformOrConfig(oc *exutil.CLI, dc dynamic.Interface) { g.By("checking supported platforms") - infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{}) + infra, err := clusterInfrastructure(oc) o.Expect(err).NotTo(o.HaveOccurred()) switch infra.Status.PlatformStatus.Type { diff --git a/test/extended/baremetal/high_availability.go b/test/extended/baremetal/high_availability.go index c7a47126f5b0..1830e390134b 100644 --- a/test/extended/baremetal/high_availability.go +++ b/test/extended/baremetal/high_availability.go @@ -149,13 +149,20 @@ var _ = g.Describe("[sig-installer][Feature:baremetal][Serial] Baremetal platfor func checkMetal3DeploymentHealthy(oc *exutil.CLI) { dc := oc.AdminDynamicClient() bmc := baremetalClient(dc) + operationalStatus := "OK" + infra, err := clusterInfrastructure(oc) + o.Expect(err).NotTo(o.HaveOccurred()) + + if infra.Status.ControlPlaneTopology == configv1.DualReplicaTopologyMode { + operationalStatus = "detached" + } hosts, err := bmc.List(context.Background(), v1.ListOptions{}) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(hosts.Items).ToNot(o.BeEmpty()) for _, h := range hosts.Items { - expectStringField(h, "baremetalhost", "status.operationalStatus").To(o.BeEquivalentTo("OK")) + expectStringField(h, "baremetalhost", "status.operationalStatus").To(o.BeEquivalentTo(operationalStatus)) expectStringField(h, "baremetalhost", "status.provisioning.state").To(o.Or(o.BeEquivalentTo("provisioned"), o.BeEquivalentTo("externally provisioned"))) expectBoolField(h, "baremetalhost", "spec.online").To(o.BeTrue()) } diff --git a/test/extended/baremetal/hosts.go b/test/extended/baremetal/hosts.go index 92c908dae54d..4abdcb39a31e 100644 --- a/test/extended/baremetal/hosts.go +++ b/test/extended/baremetal/hosts.go @@ -165,6 +165,7 @@ var _ = g.Describe("[sig-installer][Feature:baremetal][Serial] Baremetal platfor g.BeforeEach(func() { skipIfNotBaremetal(oc) + skipIfTwoNode(oc) helper = NewBaremetalTestHelper(oc.AdminDynamicClient()) helper.Setup() })