Skip to content

Commit 09f2df1

Browse files
committed
vspheredeploymentzone: implement v1beta2 conditions
1 parent 393a169 commit 09f2df1

5 files changed

+262
-24
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
@@ -364,7 +364,7 @@ spec:
364364
conditions:
365365
description: |-
366366
conditions represents the observations of a VSphereDeploymentZone's current state.
367-
Known condition types are Paused.
367+
Known condition types are Ready, VCenterAvailable, PlacementConstraintReady, FailureDomainValidated and Paused.
368368
items:
369369
description: Condition contains details for one aspect of the
370370
current state of this API Resource.

controllers/vspheredeploymentzone_controller.go

+91-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,47 @@ 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+
infrav1.VSphereDeploymentZoneReadyV1Beta2Condition,
172+
infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
173+
infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
174+
infrav1.VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition,
175+
}},
176+
)
177+
}
178+
137179
func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, deploymentZoneCtx *capvcontext.VSphereDeploymentZoneContext) error {
138180
failureDomain := &infrav1.VSphereFailureDomain{}
139181
failureDomainKey := client.ObjectKey{Name: deploymentZoneCtx.VSphereDeploymentZone.Spec.FailureDomain}
@@ -144,17 +186,28 @@ func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, de
144186
authSession, err := r.getVCenterSession(ctx, deploymentZoneCtx, failureDomain.Spec.Topology.Datacenter)
145187
if err != nil {
146188
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VCenterAvailableCondition, infrav1.VCenterUnreachableReason, clusterv1.ConditionSeverityError, err.Error())
189+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
190+
Type: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
191+
Status: metav1.ConditionFalse,
192+
Reason: infrav1.VSphereDeploymentZoneVCenterUnreachableV1Beta2Reason,
193+
Message: err.Error(),
194+
})
147195
deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false)
148196
return err
149197
}
198+
150199
deploymentZoneCtx.AuthSession = authSession
151200
conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VCenterAvailableCondition)
201+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
202+
Type: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Condition,
203+
Status: metav1.ConditionTrue,
204+
Reason: infrav1.VSphereDeploymentZoneVCenterAvailableV1Beta2Reason,
205+
})
152206

153207
if err := r.reconcilePlacementConstraint(ctx, deploymentZoneCtx); err != nil {
154208
deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false)
155209
return err
156210
}
157-
conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition)
158211

159212
// reconcile the failure domain
160213
if err := r.reconcileFailureDomain(ctx, deploymentZoneCtx, failureDomain); err != nil {
@@ -173,16 +226,36 @@ func (r vsphereDeploymentZoneReconciler) reconcilePlacementConstraint(ctx contex
173226
if resourcePool := placementConstraint.ResourcePool; resourcePool != "" {
174227
if _, err := deploymentZoneCtx.AuthSession.Finder.ResourcePool(ctx, resourcePool); err != nil {
175228
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition, infrav1.ResourcePoolNotFoundReason, clusterv1.ConditionSeverityError, "resource pool %s is misconfigured", resourcePool)
229+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
230+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
231+
Status: metav1.ConditionFalse,
232+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintResourcePoolNotFoundV1Beta2Reason,
233+
Message: fmt.Sprintf("resource pool %s is misconfigured", resourcePool),
234+
})
176235
return errors.Wrapf(err, "failed to reconcile placement contraint: unable to find resource pool %s", resourcePool)
177236
}
178237
}
179238

180239
if folder := placementConstraint.Folder; folder != "" {
181240
if _, err := deploymentZoneCtx.AuthSession.Finder.Folder(ctx, placementConstraint.Folder); err != nil {
182241
conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition, infrav1.FolderNotFoundReason, clusterv1.ConditionSeverityError, "folder %s is misconfigured", folder)
242+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
243+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
244+
Status: metav1.ConditionFalse,
245+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintFolderNotFoundV1Beta2Reason,
246+
Message: fmt.Sprintf("folder %s is misconfigured", folder),
247+
})
183248
return errors.Wrapf(err, "failed to reconcile placement contraint: unable to find folder %s", folder)
184249
}
185250
}
251+
252+
conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition)
253+
v1beta2conditions.Set(deploymentZoneCtx.VSphereDeploymentZone, metav1.Condition{
254+
Type: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition,
255+
Status: metav1.ConditionTrue,
256+
Reason: infrav1.VSphereDeploymentZonePlacementConstraintReadyV1Beta2Reason,
257+
})
258+
186259
return nil
187260
}
188261

@@ -228,6 +301,22 @@ func (r vsphereDeploymentZoneReconciler) getVCenterSession(ctx context.Context,
228301
func (r vsphereDeploymentZoneReconciler) reconcileDelete(ctx context.Context, deploymentZoneCtx *capvcontext.VSphereDeploymentZoneContext) error {
229302
log := ctrl.LoggerFrom(ctx)
230303

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

0 commit comments

Comments
 (0)