@@ -34,6 +34,7 @@ import (
34
34
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
35
35
clusterutilv1 "sigs.k8s.io/cluster-api/util"
36
36
"sigs.k8s.io/cluster-api/util/conditions"
37
+ v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
37
38
"sigs.k8s.io/cluster-api/util/finalizers"
38
39
"sigs.k8s.io/cluster-api/util/patch"
39
40
"sigs.k8s.io/cluster-api/util/paused"
@@ -107,7 +108,7 @@ func (r *clusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
107
108
// Always issue a patch when exiting this function so changes to the
108
109
// resource are patched back to the API server.
109
110
defer func () {
110
- if err := clusterContext . Patch (ctx ); err != nil {
111
+ if err := r . patch (ctx , clusterContext ); err != nil {
111
112
reterr = kerrors .NewAggregate ([]error {reterr , err })
112
113
}
113
114
}()
@@ -117,18 +118,90 @@ func (r *clusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
117
118
return r .reconcileDelete (ctx , clusterContext )
118
119
}
119
120
120
- if cluster == nil {
121
- log .Info ("Waiting for Cluster controller to set OwnerRef on VSphereCluster" )
122
- return reconcile.Result {}, nil
123
- }
124
-
125
121
// Handle non-deleted clusters
126
122
return r .reconcileNormal (ctx , clusterContext )
127
123
}
128
124
125
+ // patch updates the VSphereCluster and its status on the API server.
126
+ func (r * clusterReconciler ) patch (ctx context.Context , clusterCtx * capvcontext.ClusterContext ) error {
127
+ // always update the readyCondition.
128
+ conditions .SetSummary (clusterCtx .VSphereCluster ,
129
+ conditions .WithConditions (
130
+ infrav1 .VCenterAvailableCondition ,
131
+ ),
132
+ )
133
+
134
+ if ! v1beta2conditions .Has (clusterCtx .VSphereCluster , infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ) {
135
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
136
+ Type : infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
137
+ Status : metav1 .ConditionFalse ,
138
+ Reason : infrav1 .VSphereClusterVCenterNotAvailableV1Beta2Reason ,
139
+ Message : "did not observe VCenterAvailable status" ,
140
+ })
141
+ }
142
+
143
+ if ! v1beta2conditions .Has (clusterCtx .VSphereCluster , infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ) {
144
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
145
+ Type : infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ,
146
+ Status : metav1 .ConditionFalse ,
147
+ Reason : infrav1 .VSphereClusterClusterModulesNotReadyV1Beta2Reason ,
148
+ Message : "did not observe cluster module status" ,
149
+ })
150
+ }
151
+
152
+ if err := v1beta2conditions .SetSummaryCondition (clusterCtx .VSphereCluster , clusterCtx .VSphereCluster , infrav1 .VSphereClusterReadyV1Beta2Condition ,
153
+ v1beta2conditions.ForConditionTypes {
154
+ infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Condition ,
155
+ infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
156
+ infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ,
157
+ },
158
+ // Using a custom merge strategy to override reasons applied during merge.
159
+ v1beta2conditions.CustomMergeStrategy {
160
+ MergeStrategy : v1beta2conditions .DefaultMergeStrategy (
161
+ // Use custom reasons.
162
+ v1beta2conditions .ComputeReasonFunc (v1beta2conditions .GetDefaultComputeMergeReasonFunc (
163
+ infrav1 .VSphereClusterNotReadyV1Beta2Reason ,
164
+ infrav1 .VSphereClusterReadyUnknownV1Beta2Reason ,
165
+ infrav1 .VSphereClusterReadyV1Beta2Reason ,
166
+ )),
167
+ ),
168
+ },
169
+ ); err != nil {
170
+ return pkgerrors .Wrapf (err , "failed to set %s condition" , infrav1 .VSphereClusterReadyV1Beta2Condition )
171
+ }
172
+
173
+ return clusterCtx .PatchHelper .Patch (ctx , clusterCtx .VSphereCluster ,
174
+ patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {}},
175
+ patch.WithOwnedV1Beta2Conditions {Conditions : []string {
176
+ infrav1 .VSphereClusterReadyV1Beta2Condition ,
177
+ infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Condition ,
178
+ infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
179
+ infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ,
180
+ }},
181
+ )
182
+ }
183
+
129
184
func (r * clusterReconciler ) reconcileDelete (ctx context.Context , clusterCtx * capvcontext.ClusterContext ) (reconcile.Result , error ) {
130
185
log := ctrl .LoggerFrom (ctx )
131
186
187
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
188
+ Type : infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
189
+ Status : metav1 .ConditionFalse ,
190
+ Reason : infrav1 .VSphereClusterVCenterAvailableDeletingV1Beta2Reason ,
191
+ })
192
+
193
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
194
+ Type : infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ,
195
+ Status : metav1 .ConditionFalse ,
196
+ Reason : infrav1 .VSphereClusterClusterModulesDeletingV1Beta2Reason ,
197
+ })
198
+
199
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
200
+ Type : infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Condition ,
201
+ Status : metav1 .ConditionFalse ,
202
+ Reason : infrav1 .VSphereClusterFailureDomainsDeletingV1Beta2Reason ,
203
+ })
204
+
132
205
var vsphereMachines []client.Object
133
206
var err error
134
207
if clusterCtx .Cluster != nil {
@@ -193,35 +266,82 @@ func (r *clusterReconciler) reconcileNormal(ctx context.Context, clusterCtx *cap
193
266
194
267
ok , err := r .reconcileDeploymentZones (ctx , clusterCtx )
195
268
if err != nil {
269
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
270
+ Type : infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Condition ,
271
+ Status : metav1 .ConditionFalse ,
272
+ Reason : infrav1 .VSphereClusterFailureDomainsNotReadyV1Beta2Reason ,
273
+ Message : err .Error (),
274
+ })
196
275
return reconcile.Result {}, err
197
276
}
198
277
if ! ok {
199
- log .Info ("Waiting for failure domains to be reconciled" )
278
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
279
+ Type : infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Condition ,
280
+ Status : metav1 .ConditionFalse ,
281
+ Reason : infrav1 .VSphereClusterFailureDomainsWaitingForFailureDomainStatusV1Beta2Reason ,
282
+ Message : "waiting for failure domains to report ready status" ,
283
+ })
200
284
return reconcile.Result {RequeueAfter : 10 * time .Second }, nil
201
285
}
286
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
287
+ Type : infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Condition ,
288
+ Status : metav1 .ConditionTrue ,
289
+ Reason : infrav1 .VSphereClusterFailureDomainsReadyV1Beta2Reason ,
290
+ })
291
+
292
+ // TODO check all occurencies of infrav1.VCenterAvailableCondition and infrav1.ClusterModulesAvailable/ready condition
202
293
203
294
if err := r .reconcileIdentitySecret (ctx , clusterCtx ); err != nil {
204
295
conditions .MarkFalse (clusterCtx .VSphereCluster , infrav1 .VCenterAvailableCondition , infrav1 .VCenterUnreachableReason , clusterv1 .ConditionSeverityError , err .Error ())
296
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
297
+ Type : infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
298
+ Status : metav1 .ConditionFalse ,
299
+ Reason : infrav1 .VSphereClusterVCenterUnreachableV1Beta2Reason ,
300
+ Message : err .Error (),
301
+ })
205
302
return reconcile.Result {}, err
206
303
}
207
304
208
305
vcenterSession , err := r .reconcileVCenterConnectivity (ctx , clusterCtx )
209
306
if err != nil {
210
307
conditions .MarkFalse (clusterCtx .VSphereCluster , infrav1 .VCenterAvailableCondition , infrav1 .VCenterUnreachableReason , clusterv1 .ConditionSeverityError , err .Error ())
308
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
309
+ Type : infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
310
+ Status : metav1 .ConditionFalse ,
311
+ Reason : infrav1 .VSphereClusterVCenterUnreachableV1Beta2Reason ,
312
+ Message : err .Error (),
313
+ })
211
314
return reconcile.Result {}, pkgerrors .Wrapf (err ,
212
315
"unexpected error while probing vcenter for %s" , clusterCtx )
213
316
}
214
317
conditions .MarkTrue (clusterCtx .VSphereCluster , infrav1 .VCenterAvailableCondition )
318
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
319
+ Type : infrav1 .VSphereClusterVCenterAvailableV1Beta2Condition ,
320
+ Status : metav1 .ConditionTrue ,
321
+ Reason : infrav1 .VSphereClusterVCenterAvailableV1Beta2Reason ,
322
+ })
215
323
216
324
err = r .reconcileVCenterVersion (clusterCtx , vcenterSession )
217
325
if err != nil || clusterCtx .VSphereCluster .Status .VCenterVersion == "" {
218
- conditions .MarkFalse (clusterCtx .VSphereCluster , infrav1 .ClusterModulesAvailableCondition , infrav1 .MissingVCenterVersionReason , clusterv1 .ConditionSeverityWarning , "vCenter version not set" )
326
+ conditions .MarkFalse (clusterCtx .VSphereCluster , infrav1 .ClusterModulesAvailableCondition , infrav1 .MissingVCenterVersionReason , clusterv1 .ConditionSeverityWarning , err .Error ())
327
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
328
+ Type : infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ,
329
+ Status : metav1 .ConditionFalse ,
330
+ Reason : infrav1 .VSphereClusterModulesInvalidVCenterVersionV1Beta2Reason ,
331
+ Message : err .Error (),
332
+ })
219
333
log .Error (err , "could not reconcile vCenter version" )
220
334
}
221
335
222
336
affinityReconcileResult , err := r .reconcileClusterModules (ctx , clusterCtx )
223
337
if err != nil {
224
338
conditions .MarkFalse (clusterCtx .VSphereCluster , infrav1 .ClusterModulesAvailableCondition , infrav1 .ClusterModuleSetupFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
339
+ v1beta2conditions .Set (clusterCtx .VSphereCluster , metav1.Condition {
340
+ Type : infrav1 .VSphereClusterClusterModulesReadyV1Beta2Condition ,
341
+ Status : metav1 .ConditionFalse ,
342
+ Reason : infrav1 .VSphereClusterClusterModulesNotReadyV1Beta2Reason ,
343
+ Message : err .Error (),
344
+ })
225
345
return affinityReconcileResult , err
226
346
}
227
347
@@ -295,13 +415,14 @@ func (r *clusterReconciler) reconcileVCenterConnectivity(ctx context.Context, cl
295
415
func (r * clusterReconciler ) reconcileVCenterVersion (clusterCtx * capvcontext.ClusterContext , s * session.Session ) error {
296
416
version , err := s .GetVersion ()
297
417
if err != nil {
298
- return err
418
+ return pkgerrors . Wrapf ( err , "invalid vCenter version" )
299
419
}
300
420
clusterCtx .VSphereCluster .Status .VCenterVersion = version
301
421
return nil
302
422
}
303
423
304
424
func (r * clusterReconciler ) reconcileDeploymentZones (ctx context.Context , clusterCtx * capvcontext.ClusterContext ) (bool , error ) {
425
+ log := ctrl .LoggerFrom (ctx )
305
426
// If there is no failure domain selector, skip reconciliation
306
427
if clusterCtx .VSphereCluster .Spec .FailureDomainSelector == nil {
307
428
return true , nil
@@ -346,6 +467,7 @@ func (r *clusterReconciler) reconcileDeploymentZones(ctx context.Context, cluste
346
467
347
468
clusterCtx .VSphereCluster .Status .FailureDomains = failureDomains
348
469
if readyNotReported > 0 {
470
+ log .Info ("Waiting for failure domains to be reconciled" )
349
471
conditions .MarkFalse (clusterCtx .VSphereCluster , infrav1 .FailureDomainsAvailableCondition , infrav1 .WaitingForFailureDomainStatusReason , clusterv1 .ConditionSeverityInfo , "waiting for failure domains to report ready status" )
350
472
return false , nil
351
473
}
0 commit comments