diff --git a/api/v1alpha3/condition_consts.go b/api/v1alpha3/condition_consts.go index dffe5b0bbd..acac361cca 100644 --- a/api/v1alpha3/condition_consts.go +++ b/api/v1alpha3/condition_consts.go @@ -47,6 +47,14 @@ const ( // while installing the container storage interface addon; those kind of errors are usually transient // the operation is automatically re-tried by the controller. CSIProvisioningFailedReason = "CSIProvisioningFailed" + + // VCenterAvailableCondition documents the connectivity with vcenter + // for a given VSphereCluster + VCenterAvailableCondition clusterv1.ConditionType = "VCenterAvailable" + + // VCenterUnreachableReason (Severity=Error) documents a VSphereCluster controller detecting + // issues with VCenter reachability; + VCenterUnreachableReason = "VCenterUnreachable" ) // Conditions and condition Reasons for the VSphereMachine and the VSphereVM object. diff --git a/controllers/vspherecluster_controller.go b/controllers/vspherecluster_controller.go index 744e0818b9..c5db8ac5d2 100644 --- a/controllers/vspherecluster_controller.go +++ b/controllers/vspherecluster_controller.go @@ -34,6 +34,7 @@ import ( "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/record" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/services/cloudprovider" + "sigs.k8s.io/cluster-api-provider-vsphere/pkg/session" infrautilv1 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/util" clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" clusterutilv1 "sigs.k8s.io/cluster-api/util" @@ -251,6 +252,13 @@ func (r clusterReconciler) reconcileNormal(ctx *context.ClusterContext) (reconci // If the VSphereCluster doesn't have our finalizer, add it. ctrlutil.AddFinalizer(ctx.VSphereCluster, infrav1.ClusterFinalizer) + if err := r.reconcileVCenterConnectivity(ctx); err != nil { + conditions.MarkFalse(ctx.VSphereCluster, infrav1.VCenterAvailableCondition, infrav1.VCenterUnreachableReason, clusterv1.ConditionSeverityError, err.Error()) + return reconcile.Result{}, errors.Wrapf(err, + "unexpected error while probing vcenter for %s", ctx) + } + conditions.MarkTrue(ctx.VSphereCluster, infrav1.VCenterAvailableCondition) + // Reconcile the VSphereCluster's load balancer. if ok, err := r.reconcileLoadBalancer(ctx); !ok { if err != nil { @@ -319,6 +327,12 @@ func (r clusterReconciler) reconcileNormal(ctx *context.ClusterContext) (reconci return reconcile.Result{}, nil } +func (r clusterReconciler) reconcileVCenterConnectivity(ctx *context.ClusterContext) error { + _, err := session.GetOrCreate(ctx, ctx.VSphereCluster.Spec.Server, + ctx.VSphereCluster.Spec.CloudProviderConfiguration.Workspace.Datacenter, ctx.Username, ctx.Password, ctx.VSphereCluster.Spec.Thumbprint) + return err +} + func (r clusterReconciler) reconcileLoadBalancer(ctx *context.ClusterContext) (bool, error) { if ctx.VSphereCluster.Spec.LoadBalancerRef == nil {