Skip to content

Commit 9aac384

Browse files
authored
Merge pull request #1066 from yastij/probe-vcenter
probe vcenter as part of the vspherecluster reconciliation
2 parents 03b6af5 + 556d6cc commit 9aac384

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

api/v1alpha3/condition_consts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ const (
4747
// while installing the container storage interface addon; those kind of errors are usually transient
4848
// the operation is automatically re-tried by the controller.
4949
CSIProvisioningFailedReason = "CSIProvisioningFailed"
50+
51+
// VCenterAvailableCondition documents the connectivity with vcenter
52+
// for a given VSphereCluster
53+
VCenterAvailableCondition clusterv1.ConditionType = "VCenterAvailable"
54+
55+
// VCenterUnreachableReason (Severity=Error) documents a VSphereCluster controller detecting
56+
// issues with VCenter reachability;
57+
VCenterUnreachableReason = "VCenterUnreachable"
5058
)
5159

5260
// Conditions and condition Reasons for the VSphereMachine and the VSphereVM object.

controllers/vspherecluster_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/context"
3535
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/record"
3636
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/services/cloudprovider"
37+
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/session"
3738
infrautilv1 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/util"
3839
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
3940
clusterutilv1 "sigs.k8s.io/cluster-api/util"
@@ -251,6 +252,13 @@ func (r clusterReconciler) reconcileNormal(ctx *context.ClusterContext) (reconci
251252
// If the VSphereCluster doesn't have our finalizer, add it.
252253
ctrlutil.AddFinalizer(ctx.VSphereCluster, infrav1.ClusterFinalizer)
253254

255+
if err := r.reconcileVCenterConnectivity(ctx); err != nil {
256+
conditions.MarkFalse(ctx.VSphereCluster, infrav1.VCenterAvailableCondition, infrav1.VCenterUnreachableReason, clusterv1.ConditionSeverityError, err.Error())
257+
return reconcile.Result{}, errors.Wrapf(err,
258+
"unexpected error while probing vcenter for %s", ctx)
259+
}
260+
conditions.MarkTrue(ctx.VSphereCluster, infrav1.VCenterAvailableCondition)
261+
254262
// Reconcile the VSphereCluster's load balancer.
255263
if ok, err := r.reconcileLoadBalancer(ctx); !ok {
256264
if err != nil {
@@ -319,6 +327,12 @@ func (r clusterReconciler) reconcileNormal(ctx *context.ClusterContext) (reconci
319327
return reconcile.Result{}, nil
320328
}
321329

330+
func (r clusterReconciler) reconcileVCenterConnectivity(ctx *context.ClusterContext) error {
331+
_, err := session.GetOrCreate(ctx, ctx.VSphereCluster.Spec.Server,
332+
ctx.VSphereCluster.Spec.CloudProviderConfiguration.Workspace.Datacenter, ctx.Username, ctx.Password, ctx.VSphereCluster.Spec.Thumbprint)
333+
return err
334+
}
335+
322336
func (r clusterReconciler) reconcileLoadBalancer(ctx *context.ClusterContext) (bool, error) {
323337

324338
if ctx.VSphereCluster.Spec.LoadBalancerRef == nil {

0 commit comments

Comments
 (0)