Skip to content

Commit f31ed9d

Browse files
mcwumblygwang550tylerschultz
committed
Fix VSphereCluster VCenterAvailable condition
We now check the connectivity regardless of whether CloudProviderConfiguration is set on the spec. That property has been deprecated and it is valuable to check this connectivity early and surface this on the VSphereCluster status rather than just on VSphereVMs. This also fixes a bug where the status could be set to "False" if the secret was not found and then never properly set to "True" once the secret becomes present. #1209 Co-authored-by: David McClure <[email protected]> Co-authored-by: Guangyuan Wang <[email protected]> Co-authored-by: Tyler Schultz <[email protected]>
1 parent 2e200c1 commit f31ed9d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

controllers/vspherecluster_controller_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4245
const (
@@ -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

Comments
 (0)