@@ -24,7 +24,7 @@ import (
24
24
25
25
const (
26
26
DefaultRequeueDelay = 10 * time .Second
27
- HealthcheckRequeueDelay = 30 * time .Second
27
+ SelfCheckRequeueDelay = 30 * time .Second
28
28
StorageInitializationRequeueDelay = 30 * time .Second
29
29
30
30
StorageInitializedCondition = "StorageInitialized"
@@ -62,22 +62,26 @@ func (r *StorageReconciler) Sync(ctx context.Context, cr *ydbv1alpha1.Storage) (
62
62
return result , err
63
63
}
64
64
65
- result , err = r .waitForHealthCheck (ctx , & storage )
66
- if err != nil || ! result .IsZero () {
67
- return result , err
68
- }
69
-
70
65
if ! meta .IsStatusConditionTrue (storage .Status .Conditions , StorageInitializedCondition ) {
71
66
result , err = r .setInitialStatus (ctx , & storage )
72
67
if err != nil || ! result .IsZero () {
73
68
return result , err
74
69
}
70
+ result , err = r .runSelfCheck (ctx , & storage , true )
71
+ if err != nil || ! result .IsZero () {
72
+ return result , err
73
+ }
75
74
result , err = r .runInitScripts (ctx , & storage )
76
75
if err != nil || ! result .IsZero () {
77
76
return result , err
78
77
}
79
78
}
80
79
80
+ result , err = r .runSelfCheck (ctx , & storage , false )
81
+ if err != nil || ! result .IsZero () {
82
+ return result , err
83
+ }
84
+
81
85
return controllers .Ok ()
82
86
}
83
87
@@ -225,103 +229,115 @@ func (r *StorageReconciler) waitForStatefulSetToScale(ctx context.Context, stora
225
229
}
226
230
227
231
func (r * StorageReconciler ) setInitialStatus (ctx context.Context , storage * resources.StorageClusterBuilder ) (ctrl.Result , error ) {
228
- meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
229
- Type : StorageInitializedCondition ,
230
- Status : "False" ,
231
- Reason : StorageInitializedReasonInProgress ,
232
- Message : "Storage is not initialized" ,
233
- })
234
- if _ , err := r .setState (ctx , storage ); err != nil {
235
- return controllers .NoRequeue (err )
232
+ if meta .FindStatusCondition (storage .Status .Conditions , StorageInitializedCondition ) == nil {
233
+ meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
234
+ Type : StorageInitializedCondition ,
235
+ Status : "False" ,
236
+ Reason : StorageInitializedReasonInProgress ,
237
+ Message : "Storage is not initialized" ,
238
+ })
239
+ if _ , err := r .setState (ctx , storage ); err != nil {
240
+ return controllers .NoRequeue (err )
241
+ }
236
242
}
237
243
238
- configMapName := storage .Name
239
- if storage .Spec .ClusterConfig != "" {
240
- configMapName = storage .Spec .ClusterConfig
244
+ if meta .FindStatusCondition (storage .Status .Conditions , InitStorageStepCondition ) == nil {
245
+ meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
246
+ Type : InitStorageStepCondition ,
247
+ Status : "False" ,
248
+ Reason : InitStorageStepReasonInProgress ,
249
+ Message : "InitStorageStep is required" ,
250
+ })
251
+ if _ , err := r .setState (ctx , storage ); err != nil {
252
+ return controllers .NoRequeue (err )
253
+ }
241
254
}
242
255
243
- configMap := & corev1. ConfigMap {}
244
- err := r . Get ( ctx , types. NamespacedName {
245
- Name : configMapName ,
246
- Namespace : storage .Namespace ,
247
- }, configMap )
256
+ if meta . FindStatusCondition ( storage . Status . Conditions , InitRootStorageStepCondition ) == nil {
257
+ configMapName := storage . Name
258
+ if storage . Spec . ClusterConfig != "" {
259
+ configMapName = storage .Spec . ClusterConfig
260
+ }
248
261
249
- if err != nil && errors .IsNotFound (err ) {
250
- return controllers .Ok ()
251
- } else if err != nil {
252
- r .Recorder .Event (
253
- storage ,
254
- corev1 .EventTypeNormal ,
255
- "Syncing" ,
256
- fmt .Sprintf ("Failed to get ConfigMap: %s" , err ),
257
- )
258
- return controllers .NoRequeue (err )
259
- }
262
+ configMap := & corev1.ConfigMap {}
263
+ err := r .Get (ctx , types.NamespacedName {
264
+ Name : configMapName ,
265
+ Namespace : storage .Namespace ,
266
+ }, configMap )
260
267
261
- meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
262
- Type : InitStorageStepCondition ,
263
- Status : "False" ,
264
- Reason : InitStorageStepReasonInProgress ,
265
- Message : "InitStorageStep is required" ,
266
- })
267
- if _ , err := r .setState (ctx , storage ); err != nil {
268
- return controllers .NoRequeue (err )
268
+ if err != nil && errors .IsNotFound (err ) {
269
+ return controllers .Ok ()
270
+ } else if err != nil {
271
+ r .Recorder .Event (
272
+ storage ,
273
+ corev1 .EventTypeNormal ,
274
+ "Syncing" ,
275
+ fmt .Sprintf ("Failed to get ConfigMap: %s" , err ),
276
+ )
277
+ return controllers .NoRequeue (err )
278
+ }
279
+
280
+ if _ , ok := configMap .Data ["init_root_storage.bash" ]; ok {
281
+ meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
282
+ Type : InitRootStorageStepCondition ,
283
+ Status : "False" ,
284
+ Reason : InitRootStorageStepReasonInProgress ,
285
+ Message : fmt .Sprintf ("InitRootStorageStep is required, init_root_storage.bash script is specified in ConfigMap: %s" , configMapName ),
286
+ })
287
+ if _ , err := r .setState (ctx , storage ); err != nil {
288
+ return controllers .NoRequeue (err )
289
+ }
290
+ } else {
291
+ meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
292
+ Type : InitRootStorageStepCondition ,
293
+ Status : "True" ,
294
+ Reason : InitRootStorageStepReasonNotRequired ,
295
+ Message : "InitRootStorageStep is not required" ,
296
+ })
297
+ if _ , err := r .setState (ctx , storage ); err != nil {
298
+ return controllers .NoRequeue (err )
299
+ }
300
+ }
269
301
}
270
302
271
- if _ , ok := configMap . Data [ "init_root_storage.bash" ]; ok {
303
+ if meta . FindStatusCondition ( storage . Status . Conditions , InitCMSStepCondition ) == nil {
272
304
meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
273
- Type : InitRootStorageStepCondition ,
305
+ Type : InitCMSStepCondition ,
274
306
Status : "False" ,
275
- Reason : InitRootStorageStepReasonInProgress ,
276
- Message : fmt .Sprintf ("InitRootStorageStep (init_root_storage.bash script) is specified in ConfigMap: %s" , configMapName ),
277
- })
278
- if _ , err := r .setState (ctx , storage ); err != nil {
279
- return controllers .NoRequeue (err )
280
- }
281
- } else {
282
- meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
283
- Type : InitRootStorageStepCondition ,
284
- Status : "True" ,
285
- Reason : InitRootStorageStepReasonNotRequired ,
286
- Message : "InitRootStorageStep is not required" ,
307
+ Reason : InitCMSStepReasonInProgress ,
308
+ Message : "InitCMSStep is required" ,
287
309
})
288
310
if _ , err := r .setState (ctx , storage ); err != nil {
289
311
return controllers .NoRequeue (err )
290
312
}
291
313
}
292
314
293
- meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
294
- Type : InitCMSStepCondition ,
295
- Status : "False" ,
296
- Reason : InitCMSStepReasonInProgress ,
297
- Message : "InitCMSStep is required" ,
298
- })
299
- if _ , err := r .setState (ctx , storage ); err != nil {
300
- return controllers .NoRequeue (err )
301
- }
302
-
303
315
return controllers .Ok ()
304
316
}
305
317
306
- func (r * StorageReconciler ) waitForHealthCheck (ctx context.Context , storage * resources.StorageClusterBuilder ) (ctrl.Result , error ) {
307
- err := healthcheck .CheckBootstrapHealth (ctx , storage )
318
+ func (r * StorageReconciler ) runSelfCheck (ctx context.Context , storage * resources.StorageClusterBuilder , waitForGoodResultWithoutIssues bool ) (ctrl.Result , error ) {
319
+ result , err := healthcheck .GetSelfCheckResult (ctx , storage )
308
320
309
321
if err != nil {
310
- r .Recorder . Event (
311
- storage ,
312
- corev1 . EventTypeNormal ,
313
- "HealthcheckInProgress" ,
314
- fmt . Sprintf ( "Waiting for healthcheck, current status: %s" , err ),
315
- )
316
- return controllers . RequeueAfter ( HealthcheckRequeueDelay , err )
322
+ r .Log . Error ( err , "GetSelfCheckResult error" )
323
+ return controllers . RequeueAfter ( SelfCheckRequeueDelay , err )
324
+ }
325
+
326
+ eventType := corev1 . EventTypeNormal
327
+ if result . SelfCheckResult . String () != "GOOD" {
328
+ eventType = corev1 . EventTypeWarning
317
329
}
318
330
319
331
r .Recorder .Event (
320
332
storage ,
321
- corev1 . EventTypeNormal ,
322
- "HealthcheckOK " ,
323
- "Bootstrap healthcheck is green" ,
333
+ eventType ,
334
+ "SelfCheck " ,
335
+ fmt . Sprintf ( "SelfCheck result: %s, issues found: %d" , result . SelfCheckResult . String (), len ( result . IssueLog )) ,
324
336
)
337
+
338
+ if waitForGoodResultWithoutIssues && (result .SelfCheckResult .String () != "GOOD" || len (result .IssueLog ) > 0 ) {
339
+ return controllers .RequeueAfter (SelfCheckRequeueDelay , err )
340
+ }
325
341
return controllers .Ok ()
326
342
}
327
343
0 commit comments