@@ -24,6 +24,7 @@ import (
2424
2525 . "github.com/onsi/ginkgo"
2626 . "github.com/onsi/gomega"
27+ "github.com/vmware/govmomi/simulator"
2728
2829 corev1 "k8s.io/api/core/v1"
2930 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -37,6 +38,8 @@ import (
3738
3839 infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha4"
3940 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context/fake"
41+ "sigs.k8s.io/cluster-api-provider-vsphere/pkg/identity"
42+ "sigs.k8s.io/cluster-api-provider-vsphere/test/helpers"
4043)
4144
4245const (
@@ -49,12 +52,21 @@ var _ = Describe("ClusterReconciler", func() {
4952
5053 Context ("Reconcile an VSphereCluster" , func () {
5154 It ("should create a cluster" , func () {
55+ fakeVCenter := startVcenter ()
56+ vcURL := fakeVCenter .ServerURL ()
57+ defer fakeVCenter .Destroy ()
58+
5259 // Create the secret containing the credentials
60+ password , _ := vcURL .User .Password ()
5361 secret := & corev1.Secret {
5462 ObjectMeta : metav1.ObjectMeta {
5563 GenerateName : "secret-" ,
5664 Namespace : "default" ,
5765 },
66+ Data : map [string ][]byte {
67+ identity .UsernameKey : []byte (vcURL .User .Username ()),
68+ identity .PasswordKey : []byte (password ),
69+ },
5870 }
5971 Expect (testEnv .Create (ctx , secret )).To (Succeed ())
6072
@@ -69,6 +81,7 @@ var _ = Describe("ClusterReconciler", func() {
6981 Kind : infrav1 .SecretKind ,
7082 Name : secret .Name ,
7183 },
84+ Server : fmt .Sprintf ("%s://%s" , vcURL .Scheme , vcURL .Host ),
7285 },
7386 }
7487 Expect (testEnv .Create (ctx , instance )).To (Succeed ())
@@ -129,6 +142,14 @@ var _ = Describe("ClusterReconciler", func() {
129142 }
130143 return len (secret .OwnerReferences ) > 0
131144 }, timeout ).Should (BeTrue ())
145+
146+ By ("setting the VSphereCluster's VCenterAvailableCondition to true" )
147+ Eventually (func () bool {
148+ if err := testEnv .Get (ctx , key , instance ); err != nil {
149+ return false
150+ }
151+ return conditions .IsTrue (instance , infrav1 .VCenterAvailableCondition )
152+ }, timeout ).Should (BeTrue ())
132153 })
133154
134155 It ("should error if secret is already owned by a different cluster" , func () {
@@ -453,3 +474,15 @@ func deploymentZone(server, fdName string, cp, ready *bool) *infrav1.VSphereDepl
453474 Status : infrav1.VSphereDeploymentZoneStatus {Ready : ready },
454475 }
455476}
477+
478+ func startVcenter () * helpers.Simulator {
479+ model := simulator .VPX ()
480+ model .Pool = 1
481+
482+ simr , err := helpers .VCSimBuilder ().WithModel (model ).Build ()
483+ if err != nil {
484+ panic (fmt .Sprintf ("unable to create simulator %s" , err ))
485+ }
486+
487+ return simr
488+ }
0 commit comments