Skip to content

Commit ad7777b

Browse files
committedMar 18, 2025
vspheredeploymentzone: implement v1beta2 conditions
1 parent cf8ddc6 commit ad7777b

5 files changed

+263
-27
lines changed
 

‎apis/v1beta1/vspheredeploymentzone_types.go

+98-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,103 @@ const (
2828
DeploymentZoneFinalizer = "vspheredeploymentzone.infrastructure.cluster.x-k8s.io"
2929
)
3030

31+
// VSphereDeploymentZone's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
32+
const (
33+
// VSphereDeploymentZoneReadyV1Beta2Condition is true if the VSphereDeploymentZone's deletionTimestamp is not set, VSphereDeploymentZone's
34+
// VCenterAvailable, PlacementConstraintReady and FailureDomainValidated conditions are true.
35+
VSphereDeploymentZoneReadyV1Beta2Condition = clusterv1.ReadyV1Beta2Condition
36+
37+
// VSphereDeploymentZoneReadyV1Beta2Reason surfaces when the VSphereDeploymentZone readiness criteria is met.
38+
VSphereDeploymentZoneReadyV1Beta2Reason = clusterv1.ReadyV1Beta2Reason
39+
40+
// VSphereDeploymentZoneNotReadyV1Beta2Reason surfaces when the VSphereDeploymentZone readiness criteria is not met.
41+
VSphereDeploymentZoneNotReadyV1Beta2Reason = clusterv1.NotReadyV1Beta2Reason
42+
43+
// VSphereDeploymentZoneReadyUnknownV1Beta2Reason surfaces when at least one VSphereDeploymentZone readiness criteria is unknown
44+
// and no VSphereDeploymentZone readiness criteria is not met.
45+
VSphereDeploymentZoneReadyUnknownV1Beta2Reason = clusterv1.ReadyUnknownV1Beta2Reason
46+
)
47+
48+
// VSphereDeploymentZone's VCenterAvailable condition and corresponding reasons that will be used in v1Beta2 API version.
49+
const (
50+
// VSphereDeploymentZoneVCenterAvailableV1Beta2Condition documents the status of vCenter for a VSphereDeploymentZone.
51+
VSphereDeploymentZoneVCenterAvailableV1Beta2Condition = "VCenterAvailable"
52+
53+
// VSphereDeploymentZoneVCenterAvailableV1Beta2Reason surfaces when the vCenter for a VSphereDeploymentZone is available.
54+
VSphereDeploymentZoneVCenterAvailableV1Beta2Reason = clusterv1.AvailableV1Beta2Reason
55+
56+
// VSphereDeploymentZoneVCenterUnreachableV1Beta2Reason surfaces when the vCenter for a VSphereDeploymentZone is unreachable.
57+
VSphereDeploymentZoneVCenterUnreachableV1Beta2Reason = "VCenterUnreachable"
58+
59+
// VSphereDeploymentZoneVCenterAvailableDeletingV1Beta2Reason surfaces when the vCenter for a VSphereDeploymentZone is being deleted.
60+
VSphereDeploymentZoneVCenterAvailableDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
61+
)
62+
63+
// VSphereDeploymentZone's PlacementConstraintReady condition and corresponding reasons that will be used in v1Beta2 API version.
64+
const (
65+
// VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition documents the placement constraint status for a VSphereDeploymentZone.
66+
VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition = "PlacementConstraintReady"
67+
68+
// VSphereDeploymentZonePlacementConstraintReadyV1Beta2Reason surfaces when the placement status for a VSphereDeploymentZone is ready.
69+
VSphereDeploymentZonePlacementConstraintReadyV1Beta2Reason = clusterv1.ReadyV1Beta2Reason
70+
71+
// VSphereDeploymentZonePlacementConstraintVCenterNotAvailableV1Beta2Reason surfaces when the placement constraint for a VSphereDeploymentZone
72+
// can't be verified because of no connectivity to VCenter.
73+
VSphereDeploymentZonePlacementConstraintVCenterNotAvailableV1Beta2Reason = "VCenterNotAvailable"
74+
75+
// VSphereDeploymentZonePlacementConstraintResourcePoolNotFoundV1Beta2Reason surfaces when the resource pool for a VSphereDeploymentZone is not found.
76+
VSphereDeploymentZonePlacementConstraintResourcePoolNotFoundV1Beta2Reason = "ResourcePoolNotFound"
77+
78+
// VSphereDeploymentZonePlacementConstraintFolderNotFoundV1Beta2Reason surfaces when the resource pool for a VSphereDeploymentZone is not found.
79+
VSphereDeploymentZonePlacementConstraintFolderNotFoundV1Beta2Reason = "FolderNotFound"
80+
81+
// VSphereDeploymentZonePlacementConstraintDeletingV1Beta2Reason surfaces when the VSphereDeploymentZone is being deleted.
82+
VSphereDeploymentZonePlacementConstraintDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
83+
)
84+
85+
// VSphereDeploymentZone's FailureDomainValidated condition and corresponding reasons that will be used in v1Beta2 API version.
86+
const (
87+
// VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition documents failure domain validation status for a VSphereDeploymentZone.
88+
VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition = "FailureDomainValidated"
89+
90+
// VSphereDeploymentZoneFailureDomainValidatedV1Beta2Reason surfaces when the failure domain for a VSphereDeploymentZone is validated.
91+
VSphereDeploymentZoneFailureDomainValidatedV1Beta2Reason = "Validated"
92+
93+
// VSphereDeploymentZoneFailureDomainVCenterNotAvailableV1Beta2Reason surfaces when the failure domain for a VSphereDeploymentZone
94+
// can't be validated because of no connectivity to VCenter.
95+
VSphereDeploymentZoneFailureDomainVCenterNotAvailableV1Beta2Reason = "VCenterNotAvailable"
96+
97+
// VSphereDeploymentZoneFailureDomainValidationFailedV1Beta2Reason surfaces when the failure domain's validation for a VSphereDeploymentZone failed.
98+
VSphereDeploymentZoneFailureDomainValidationFailedV1Beta2Reason = "ValidationFailed"
99+
100+
// VSphereDeploymentZoneFailureDomainRegionMisconfiguredV1Beta2Reason surfaces when the failure domain's region for a VSphereDeploymentZone is misconfigured.
101+
VSphereDeploymentZoneFailureDomainRegionMisconfiguredV1Beta2Reason = "RegionMisconfigured"
102+
103+
// VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason surfaces when the failure domain's zone for a VSphereDeploymentZone is misconfigured.
104+
VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason = "ZoneMisconfigured"
105+
106+
// VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason surfaces when the failure domain's hosts for a VSphereDeploymentZone are misconfigured.
107+
VSphereDeploymentZoneFailureDomainHostsMisconfiguredV1Beta2Reason = "HostsMisconfigured"
108+
109+
// VSphereDeploymentZoneFailureDomainHostsAffinityMisconfiguredV1Beta2Reason surfaces when the failure domain's hosts for a VSphereDeploymentZone are misconfigured.
110+
VSphereDeploymentZoneFailureDomainHostsAffinityMisconfiguredV1Beta2Reason = "HostsAffinityMisconfigured"
111+
112+
// VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason surfaces when the failure domain's datastore for a VSphereDeploymentZone is not found.
113+
VSphereDeploymentZoneFailureDomainDatastoreNotFoundV1Beta2Reason = "DatastoreNotFound"
114+
115+
// VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason surfaces when the failure domain's network for a VSphereDeploymentZone is not found.
116+
VSphereDeploymentZoneFailureDomainNetworkNotFoundV1Beta2Reason = "NetworkNotFound"
117+
118+
// VSphereDeploymentZoneFailureDomainComputeClusterNotFoundV1Beta2Reason surfaces when the failure domain's compute cluster for a VSphereDeploymentZone failed.
119+
VSphereDeploymentZoneFailureDomainComputeClusterNotFoundV1Beta2Reason = "ComputeClusterNotFound"
120+
121+
// VSphereDeploymentZoneFailureDomainValidationFailedV1Beta2Reason surfaces when the failure domain's resource pool for a VSphereDeploymentZone failed.
122+
VSphereDeploymentZoneFailureDomainResourcePoolNotFoundV1Beta2Reason = "ResourcePoolNotFound"
123+
124+
// VSphereDeploymentZoneFailureDomainDeletingV1Beta2Reason surfaces when the VSphereDeploymentZone is being deleted.
125+
VSphereDeploymentZoneFailureDomainDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
126+
)
127+
31128
// VSphereDeploymentZoneSpec defines the desired state of VSphereDeploymentZone.
32129
type VSphereDeploymentZoneSpec struct {
33130

@@ -93,7 +190,7 @@ type VSphereDeploymentZoneStatus struct {
93190
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
94191
type VSphereDeploymentZoneV1Beta2Status struct {
95192
// conditions represents the observations of a VSphereDeploymentZone's current state.
96-
// Known condition types are Paused.
193+
// Known condition types are Ready, VCenterAvailable, PlacementConstraintReady, FailureDomainValidated and Paused.
97194
// +optional
98195
// +listType=map
99196
// +listMapKey=type

‎config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspheredeploymentzones.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ spec:
371371
conditions:
372372
description: |-
373373
conditions represents the observations of a VSphereDeploymentZone's current state.
374-
Known condition types are Paused.
374+
Known condition types are Ready, VCenterAvailable, PlacementConstraintReady, FailureDomainValidated and Paused.
375375
items:
376376
description: Condition contains details for one aspect of the
377377
current state of this API Resource.

‎controllers/vspheredeploymentzone_controller.go

+92-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
clusterutilv1 "sigs.k8s.io/cluster-api/util"
3232
"sigs.k8s.io/cluster-api/util/collections"
3333
"sigs.k8s.io/cluster-api/util/conditions"
34+
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
3435
"sigs.k8s.io/cluster-api/util/finalizers"
3536
"sigs.k8s.io/cluster-api/util/patch"
3637
"sigs.k8s.io/cluster-api/util/paused"
@@ -122,7 +123,7 @@ func (r vsphereDeploymentZoneReconciler) Reconcile(ctx context.Context, request
122123
PatchHelper: patchHelper,
123124
}
124125
defer func() {
125-
if err := vsphereDeploymentZoneContext.Patch(ctx); err != nil {
126+
if err := r.patch(ctx, vsphereDeploymentZoneContext); err != nil {
126127
reterr = kerrors.NewAggregate([]error{reterr, err})
127128
}
128129
}()
@@ -134,6 +135,48 @@ func (r vsphereDeploymentZoneReconciler) Reconcile(ctx context.Context, request
134135
return ctrl.Result{}, r.reconcileNormal(ctx, vsphereDeploymentZoneContext)
135136
}
136137

138+
// Patch patches the VSphereDeploymentZone.
139+
func (r vsphereDeploymentZoneReconciler) patch(ctx context.Context, vsphereDeploymentZoneContext *capvcontext.VSphereDeploymentZoneContext) error {
140+
conditions.SetSummary(vsphereDeploymentZoneContext.VSphereDeploymentZone,
141+
conditions.WithConditions(
142+
infrav1.VCenterAvailableCondition,
143+
infrav1.VSphereFailureDomainValidatedCondition,
144+
infrav1.PlacementConstraintMetCondition,
145+
),
146+
)
147+
148+
if err := v1beta2conditions.SetSummaryCondition(vsphereDeploymentZoneContext.VSphereDeploymentZone, vsphereDeploymentZoneContext.VSphereDeploymentZone, infrav1.VSphereDeploymentZoneReadyV1Beta2Condition,
149+
v1beta2conditions.ForConditionTypes{
150+
infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
151+
infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
152+
infrav1.VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition,
153+
},
154+
// Using a custom merge strategy to override reasons applied during merge.
155+
v1beta2conditions.CustomMergeStrategy{
156+
MergeStrategy: v1beta2conditions.DefaultMergeStrategy(
157+
// Use custom reasons.
158+
v1beta2conditions.ComputeReasonFunc(v1beta2conditions.GetDefaultComputeMergeReasonFunc(
159+
infrav1.VSphereDeploymentZoneNotReadyV1Beta2Reason,
160+
infrav1.VSphereDeploymentZoneReadyUnknownV1Beta2Reason,
161+
infrav1.VSphereDeploymentZoneReadyV1Beta2Reason,
162+
)),
163+
),
164+
},
165+
); err != nil {
166+
return errors.Wrapf(err, "failed to set %s condition", infrav1.VSphereDeploymentZoneReadyV1Beta2Condition)
167+
}
168+
169+
return vsphereDeploymentZoneContext.PatchHelper.Patch(ctx, vsphereDeploymentZoneContext.VSphereDeploymentZone,
170+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
171+
clusterv1.PausedV1Beta2Condition,
172+
infrav1.VSphereDeploymentZoneReadyV1Beta2Condition,
173+
infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
174+
infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
175+
infrav1.VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition,
176+
}},
177+
)
178+
}
179+
137180
func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, deploymentZoneCtx *capvcontext.VSphereDeploymentZoneContext) error {
138181
failureDomain := &infrav1.VSphereFailureDomain{}
139182
failureDomainKey := client.ObjectKey{Name: deploymentZoneCtx.VSphereDeploymentZone.Spec.FailureDomain}
@@ -144,17 +187,28 @@ func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, de
144187
authSession, err := r.getVCenterSession(ctx, deploymentZoneCtx, failureDomain.Spec.Topology.Datacenter)
145188
if err != nil {
146189
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VCenterAvailableCondition, infrav1.VCenterUnreachableReason, clusterv1.ConditionSeverityError, err.Error())
190+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
191+
Type: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
192+
Status: metav1.ConditionFalse,
193+
Reason: infrav1.VSphereDeploymentZoneVCenterUnreachableV1Beta2Reason,
194+
Message: err.Error(),
195+
})
147196
deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false)
148197
return err
149198
}
199+
150200
deploymentZoneCtx.AuthSession = authSession
151201
conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VCenterAvailableCondition)
202+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
203+
Type: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
204+
Status: metav1.ConditionTrue,
205+
Reason: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Reason,
206+
})
152207

153208
if err := r.reconcilePlacementConstraint(ctx, deploymentZoneCtx); err != nil {
154209
deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false)
155210
return err
156211
}
157-
conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition)
158212

159213
// reconcile the failure domain
160214
if err := r.reconcileFailureDomain(ctx, deploymentZoneCtx, failureDomain); err != nil {
@@ -173,16 +227,36 @@ func (r vsphereDeploymentZoneReconciler) reconcilePlacementConstraint(ctx contex
173227
if resourcePool := placementConstraint.ResourcePool; resourcePool != "" {
174228
if _, err := deploymentZoneCtx.AuthSession.Finder.ResourcePool(ctx, resourcePool); err != nil {
175229
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition, infrav1.ResourcePoolNotFoundReason, clusterv1.ConditionSeverityError, "resource pool %s is misconfigured", resourcePool)
230+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
231+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
232+
Status: metav1.ConditionFalse,
233+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintResourcePoolNotFoundV1Beta2Reason,
234+
Message: fmt.Sprintf("resource pool %s is misconfigured", resourcePool),
235+
})
176236
return errors.Wrapf(err, "failed to reconcile placement contraint: unable to find resource pool %s", resourcePool)
177237
}
178238
}
179239

180240
if folder := placementConstraint.Folder; folder != "" {
181241
if _, err := deploymentZoneCtx.AuthSession.Finder.Folder(ctx, placementConstraint.Folder); err != nil {
182242
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition, infrav1.FolderNotFoundReason, clusterv1.ConditionSeverityError, "folder %s is misconfigured", folder)
243+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
244+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
245+
Status: metav1.ConditionFalse,
246+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintFolderNotFoundV1Beta2Reason,
247+
Message: fmt.Sprintf("folder %s is misconfigured", folder),
248+
})
183249
return errors.Wrapf(err, "failed to reconcile placement contraint: unable to find folder %s", folder)
184250
}
185251
}
252+
253+
conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition)
254+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
255+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
256+
Status: metav1.ConditionTrue,
257+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Reason,
258+
})
259+
186260
return nil
187261
}
188262

@@ -228,6 +302,22 @@ func (r vsphereDeploymentZoneReconciler) getVCenterSession(ctx context.Context,
228302
func (r vsphereDeploymentZoneReconciler) reconcileDelete(ctx context.Context, deploymentZoneCtx *capvcontext.VSphereDeploymentZoneContext) error {
229303
log := ctrl.LoggerFrom(ctx)
230304

305+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
306+
Type: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
307+
Status: metav1.ConditionFalse,
308+
Reason: infrav1.VSphereDeploymentZoneVCenterAvailableDeletingV1Beta2Reason,
309+
})
310+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
311+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
312+
Status: metav1.ConditionFalse,
313+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintDeletingV1Beta2Reason,
314+
})
315+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
316+
Type: infrav1.VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition,
317+
Status: metav1.ConditionFalse,
318+
Reason: infrav1.VSphereDeploymentZoneFailureDomainDeletingV1Beta2Reason,
319+
})
320+
231321
machines := &clusterv1.MachineList{}
232322
if err := r.Client.List(ctx, machines); err != nil {
233323
return errors.Wrapf(err, "failed to list Machines")

0 commit comments

Comments
 (0)
Please sign in to comment.