@@ -31,6 +31,7 @@ import (
31
31
clusterutilv1 "sigs.k8s.io/cluster-api/util"
32
32
"sigs.k8s.io/cluster-api/util/collections"
33
33
"sigs.k8s.io/cluster-api/util/conditions"
34
+ v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
34
35
"sigs.k8s.io/cluster-api/util/finalizers"
35
36
"sigs.k8s.io/cluster-api/util/patch"
36
37
"sigs.k8s.io/cluster-api/util/paused"
@@ -122,7 +123,7 @@ func (r vsphereDeploymentZoneReconciler) Reconcile(ctx context.Context, request
122
123
PatchHelper : patchHelper ,
123
124
}
124
125
defer func () {
125
- if err := vsphereDeploymentZoneContext . Patch (ctx ); err != nil {
126
+ if err := r . patch (ctx , vsphereDeploymentZoneContext ); err != nil {
126
127
reterr = kerrors .NewAggregate ([]error {reterr , err })
127
128
}
128
129
}()
@@ -134,6 +135,47 @@ func (r vsphereDeploymentZoneReconciler) Reconcile(ctx context.Context, request
134
135
return ctrl.Result {}, r .reconcileNormal (ctx , vsphereDeploymentZoneContext )
135
136
}
136
137
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
+
137
179
func (r vsphereDeploymentZoneReconciler ) reconcileNormal (ctx context.Context , deploymentZoneCtx * capvcontext.VSphereDeploymentZoneContext ) error {
138
180
failureDomain := & infrav1.VSphereFailureDomain {}
139
181
failureDomainKey := client.ObjectKey {Name : deploymentZoneCtx .VSphereDeploymentZone .Spec .FailureDomain }
@@ -144,17 +186,28 @@ func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, de
144
186
authSession , err := r .getVCenterSession (ctx , deploymentZoneCtx , failureDomain .Spec .Topology .Datacenter )
145
187
if err != nil {
146
188
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
+ })
147
195
deploymentZoneCtx .VSphereDeploymentZone .Status .Ready = ptr .To (false )
148
196
return err
149
197
}
198
+
150
199
deploymentZoneCtx .AuthSession = authSession
151
200
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
+ })
152
206
153
207
if err := r .reconcilePlacementConstraint (ctx , deploymentZoneCtx ); err != nil {
154
208
deploymentZoneCtx .VSphereDeploymentZone .Status .Ready = ptr .To (false )
155
209
return err
156
210
}
157
- conditions .MarkTrue (deploymentZoneCtx .VSphereDeploymentZone , infrav1 .PlacementConstraintMetCondition )
158
211
159
212
// reconcile the failure domain
160
213
if err := r .reconcileFailureDomain (ctx , deploymentZoneCtx , failureDomain ); err != nil {
@@ -173,16 +226,36 @@ func (r vsphereDeploymentZoneReconciler) reconcilePlacementConstraint(ctx contex
173
226
if resourcePool := placementConstraint .ResourcePool ; resourcePool != "" {
174
227
if _ , err := deploymentZoneCtx .AuthSession .Finder .ResourcePool (ctx , resourcePool ); err != nil {
175
228
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
+ })
176
235
return errors .Wrapf (err , "failed to reconcile placement contraint: unable to find resource pool %s" , resourcePool )
177
236
}
178
237
}
179
238
180
239
if folder := placementConstraint .Folder ; folder != "" {
181
240
if _ , err := deploymentZoneCtx .AuthSession .Finder .Folder (ctx , placementConstraint .Folder ); err != nil {
182
241
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
+ })
183
248
return errors .Wrapf (err , "failed to reconcile placement contraint: unable to find folder %s" , folder )
184
249
}
185
250
}
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
+
186
259
return nil
187
260
}
188
261
@@ -228,6 +301,22 @@ func (r vsphereDeploymentZoneReconciler) getVCenterSession(ctx context.Context,
228
301
func (r vsphereDeploymentZoneReconciler ) reconcileDelete (ctx context.Context , deploymentZoneCtx * capvcontext.VSphereDeploymentZoneContext ) error {
229
302
log := ctrl .LoggerFrom (ctx )
230
303
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
+
231
320
machines := & clusterv1.MachineList {}
232
321
if err := r .Client .List (ctx , machines ); err != nil {
233
322
return errors .Wrapf (err , "failed to list Machines" )
0 commit comments