44 "context"
55 "fmt"
66 "strings"
7+ "sync"
78
89 g "github.com/onsi/ginkgo/v2"
910 o "github.com/onsi/gomega"
@@ -16,17 +17,48 @@ import (
1617 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
1718)
1819
20+ var (
21+ clusterInfraMu sync.Mutex
22+ clusterInfra * configv1.Infrastructure
23+ clusterInfraFetched bool
24+ )
25+
26+ // clusterInfrastructure returns the cluster Infrastructure object. A successful fetch is cached for
27+ // the rest of the process; if Get fails, nothing is cached and the next call retries.
28+ func clusterInfrastructure (oc * exutil.CLI ) (* configv1.Infrastructure , error ) {
29+ clusterInfraMu .Lock ()
30+ defer clusterInfraMu .Unlock ()
31+ if clusterInfraFetched {
32+ return clusterInfra , nil
33+ }
34+ infra , err := oc .AdminConfigClient ().ConfigV1 ().Infrastructures ().Get (
35+ context .Background (), "cluster" , metav1.GetOptions {})
36+ if err == nil {
37+ clusterInfra = infra
38+ clusterInfraFetched = true
39+ }
40+ return infra , err
41+ }
42+
1943func skipIfNotBaremetal (oc * exutil.CLI ) {
2044 g .By ("checking platform type" )
2145
22- infra , err := oc . AdminConfigClient (). ConfigV1 (). Infrastructures (). Get ( context . Background (), "cluster" , metav1. GetOptions {} )
46+ infra , err := clusterInfrastructure ( oc )
2347 o .Expect (err ).NotTo (o .HaveOccurred ())
2448
2549 if infra .Status .PlatformStatus .Type != configv1 .BareMetalPlatformType {
2650 e2eskipper .Skipf ("No baremetal platform detected" )
2751 }
2852}
2953
54+ func skipIfTwoNode (oc * exutil.CLI ) {
55+ infra , err := clusterInfrastructure (oc )
56+ o .Expect (err ).NotTo (o .HaveOccurred ())
57+ if infra .Status .ControlPlaneTopology == configv1 .DualReplicaTopologyMode {
58+ e2eskipper .Skipf ("This test does not apply to two-node" )
59+ }
60+ }
61+
3062// Starting from 4.10, metal3 resources could be created in the vSphere, OpenStack and None
3163// Platforms in addition to the Baremetal Platform.
3264// Starting from 4.12, metal3 resources could be created in the AWS Platform too.
@@ -35,7 +67,7 @@ func skipIfNotBaremetal(oc *exutil.CLI) {
3567func skipIfUnsupportedPlatformOrConfig (oc * exutil.CLI , dc dynamic.Interface ) {
3668 g .By ("checking supported platforms" )
3769
38- infra , err := oc . AdminConfigClient (). ConfigV1 (). Infrastructures (). Get ( context . Background (), "cluster" , metav1. GetOptions {} )
70+ infra , err := clusterInfrastructure ( oc )
3971 o .Expect (err ).NotTo (o .HaveOccurred ())
4072
4173 switch infra .Status .PlatformStatus .Type {
0 commit comments