@@ -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,48 @@ 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
+ clusterv1 .PausedV1Beta2Condition ,
172
+ infrav1 .VSphereDeploymentZoneReadyV1Beta2Condition ,
173
+ infrav1 .VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition ,
174
+ infrav1 .VSphereDeploymentZoneVCenterAvailableV1Beta2Condition ,
175
+ infrav1 .VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition ,
176
+ }},
177
+ )
178
+ }
179
+
137
180
func (r vsphereDeploymentZoneReconciler ) reconcileNormal (ctx context.Context , deploymentZoneCtx * capvcontext.VSphereDeploymentZoneContext ) error {
138
181
failureDomain := & infrav1.VSphereFailureDomain {}
139
182
failureDomainKey := client.ObjectKey {Name : deploymentZoneCtx .VSphereDeploymentZone .Spec .FailureDomain }
@@ -144,17 +187,28 @@ func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, de
144
187
authSession , err := r .getVCenterSession (ctx , deploymentZoneCtx , failureDomain .Spec .Topology .Datacenter )
145
188
if err != nil {
146
189
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
+ })
147
196
deploymentZoneCtx .VSphereDeploymentZone .Status .Ready = ptr .To (false )
148
197
return err
149
198
}
199
+
150
200
deploymentZoneCtx .AuthSession = authSession
151
201
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
+ })
152
207
153
208
if err := r .reconcilePlacementConstraint (ctx , deploymentZoneCtx ); err != nil {
154
209
deploymentZoneCtx .VSphereDeploymentZone .Status .Ready = ptr .To (false )
155
210
return err
156
211
}
157
- conditions .MarkTrue (deploymentZoneCtx .VSphereDeploymentZone , infrav1 .PlacementConstraintMetCondition )
158
212
159
213
// reconcile the failure domain
160
214
if err := r .reconcileFailureDomain (ctx , deploymentZoneCtx , failureDomain ); err != nil {
@@ -173,16 +227,36 @@ func (r vsphereDeploymentZoneReconciler) reconcilePlacementConstraint(ctx contex
173
227
if resourcePool := placementConstraint .ResourcePool ; resourcePool != "" {
174
228
if _ , err := deploymentZoneCtx .AuthSession .Finder .ResourcePool (ctx , resourcePool ); err != nil {
175
229
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
+ })
176
236
return errors .Wrapf (err , "failed to reconcile placement contraint: unable to find resource pool %s" , resourcePool )
177
237
}
178
238
}
179
239
180
240
if folder := placementConstraint .Folder ; folder != "" {
181
241
if _ , err := deploymentZoneCtx .AuthSession .Finder .Folder (ctx , placementConstraint .Folder ); err != nil {
182
242
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
+ })
183
249
return errors .Wrapf (err , "failed to reconcile placement contraint: unable to find folder %s" , folder )
184
250
}
185
251
}
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
+
186
260
return nil
187
261
}
188
262
@@ -228,6 +302,22 @@ func (r vsphereDeploymentZoneReconciler) getVCenterSession(ctx context.Context,
228
302
func (r vsphereDeploymentZoneReconciler ) reconcileDelete (ctx context.Context , deploymentZoneCtx * capvcontext.VSphereDeploymentZoneContext ) error {
229
303
log := ctrl .LoggerFrom (ctx )
230
304
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
+
231
321
machines := & clusterv1.MachineList {}
232
322
if err := r .Client .List (ctx , machines ); err != nil {
233
323
return errors .Wrapf (err , "failed to list Machines" )
0 commit comments