diff --git a/test/e2e/e2e_setup_test.go b/test/e2e/e2e_setup_test.go index f8674de46a..99d72ef17b 100644 --- a/test/e2e/e2e_setup_test.go +++ b/test/e2e/e2e_setup_test.go @@ -317,6 +317,23 @@ func addVCSimTestVariables(managementClusterProxy framework.ClusterProxy, specNa testSpecificVariables[k] = v } + + vsphereClientsInitialized.Do(func() { + for k, v := range envVar.Status.Variables { + switch k { + case "VSPHERE_USERNAME": + vsphereUsername = v + case "VSPHERE_PASSWORD": + vspherePassword = v + case "VSPHERE_SERVER": + vsphereServer = v + case "VSPHERE_DATACENTER": + vsphereDatacenter = v + } + } + + By("Initializing the vSphere session to ensure credentials are working", initVSphereSession) + }) } func setupNamespaceWithVMOperatorDependenciesVCSim(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) { diff --git a/test/e2e/govmomi_test.go b/test/e2e/govmomi_test.go index 10e0e60ac3..9bc35874b2 100644 --- a/test/e2e/govmomi_test.go +++ b/test/e2e/govmomi_test.go @@ -20,6 +20,7 @@ import ( "flag" "net/url" "os" + "sync" "time" . "github.com/onsi/ginkgo/v2" @@ -42,6 +43,8 @@ var ( vsphereClient *govmomi.Client restClient *rest.Client vsphereFinder *find.Finder + + vsphereClientsInitialized sync.Once ) func init() {