@@ -19,7 +19,6 @@ package controllers
19
19
import (
20
20
"context"
21
21
"fmt"
22
-
23
22
"github.com/go-logr/logr"
24
23
mf "github.com/manifestival/manifestival"
25
24
dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1"
@@ -119,7 +118,12 @@ func (r *DSPAReconciler) buildCondition(conditionType string, dspa *dspav1alpha1
119
118
return condition
120
119
}
121
120
122
- func (r * DSPAReconciler ) isDeploymentAvailable (ctx context.Context , dspa * dspav1alpha1.DataSciencePipelinesApplication , name string ) bool {
121
+ // isDeploymentInCondition evaluates if condition with "name" is in condition of type "conditionType".
122
+ // this procedure is valid only for conditions with bool status type, for conditions of non bool type
123
+ // results are undefined.
124
+ func (r * DSPAReconciler ) isDeploymentInCondition (ctx context.Context ,
125
+ dspa * dspav1alpha1.DataSciencePipelinesApplication , name string ,
126
+ conditionType appsv1.DeploymentConditionType ) (bool , appsv1.DeploymentCondition ) {
123
127
found := & appsv1.Deployment {}
124
128
125
129
// Every Deployment in DSPA is the name followed by the DSPA CR name
@@ -128,15 +132,15 @@ func (r *DSPAReconciler) isDeploymentAvailable(ctx context.Context, dspa *dspav1
128
132
err := r .Get (ctx , types.NamespacedName {Name : component , Namespace : dspa .Namespace }, found )
129
133
if err == nil {
130
134
if found .Spec .Replicas != nil && * found .Spec .Replicas == 0 {
131
- return false
135
+ return false , appsv1. DeploymentCondition {}
132
136
}
133
137
for _ , s := range found .Status .Conditions {
134
- if s .Type == "Available" && s .Status == corev1 .ConditionTrue {
135
- return true
138
+ if s .Type == conditionType && s .Status == corev1 .ConditionTrue {
139
+ return true , s
136
140
}
137
141
}
138
142
}
139
- return false
143
+ return false , appsv1. DeploymentCondition {}
140
144
}
141
145
142
146
//+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications,verbs=get;list;watch;create;update;patch;delete
@@ -222,9 +226,6 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
222
226
return ctrl.Result {}, nil
223
227
}
224
228
225
- // Initialize conditions
226
- var conditions []metav1.Condition
227
-
228
229
err = r .ReconcileDatabase (ctx , dspa , params )
229
230
if err != nil {
230
231
return ctrl.Result {}, err
@@ -240,39 +241,21 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
240
241
return ctrl.Result {}, err
241
242
}
242
243
243
- apiServerReady := r .buildCondition (config .APIServerReady , dspa , config .MinimumReplicasAvailable )
244
244
err = r .ReconcileAPIServer (ctx , dspa , params )
245
245
if err != nil {
246
246
return ctrl.Result {}, err
247
247
}
248
248
249
- if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline" ) {
250
- apiServerReady .Status = metav1 .ConditionTrue
251
- }
252
- conditions = append (conditions , apiServerReady )
253
-
254
- persistenceAgentReady := r .buildCondition (config .PersistenceAgentReady , dspa , config .MinimumReplicasAvailable )
255
249
err = r .ReconcilePersistenceAgent (dspa , params )
256
250
if err != nil {
257
251
return ctrl.Result {}, err
258
252
}
259
253
260
- if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline-persistenceagent" ) {
261
- persistenceAgentReady .Status = metav1 .ConditionTrue
262
- }
263
- conditions = append (conditions , persistenceAgentReady )
264
-
265
- scheduledWorkflowReady := r .buildCondition (config .ScheduledWorkflowReady , dspa , config .MinimumReplicasAvailable )
266
254
err = r .ReconcileScheduledWorkflow (dspa , params )
267
255
if err != nil {
268
256
return ctrl.Result {}, err
269
257
}
270
258
271
- if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline-scheduledworkflow" ) {
272
- scheduledWorkflowReady .Status = metav1 .ConditionTrue
273
- }
274
- conditions = append (conditions , scheduledWorkflowReady )
275
-
276
259
err = r .ReconcileUI (dspa , params )
277
260
if err != nil {
278
261
return ctrl.Result {}, err
@@ -291,6 +274,62 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
291
274
return ctrl.Result {}, err
292
275
}
293
276
277
+ conditions := r .GenerateStatus (ctx , dspa )
278
+ dspa .Status .Conditions = conditions
279
+
280
+ // Update Status
281
+ err = r .Status ().Update (ctx , dspa )
282
+ if err != nil {
283
+ log .Info (err .Error ())
284
+ return ctrl.Result {}, err
285
+ }
286
+
287
+ r .PublishMetrics (
288
+ dspa ,
289
+ GetConditionByType (config .APIServerReady , conditions ),
290
+ GetConditionByType (config .PersistenceAgentReady , conditions ),
291
+ GetConditionByType (config .ScheduledWorkflowReady , conditions ),
292
+ GetConditionByType (config .CrReady , conditions ),
293
+ )
294
+
295
+ return ctrl.Result {}, nil
296
+ }
297
+
298
+ // GetConditionByType returns condition of type T if it exists in conditions, otherwise
299
+ // return empty condition struct.
300
+ func GetConditionByType (t string , conditions []metav1.Condition ) metav1.Condition {
301
+ for _ , c := range conditions {
302
+ if c .Type == t {
303
+ return c
304
+ }
305
+ }
306
+ return metav1.Condition {}
307
+ }
308
+
309
+ func (r * DSPAReconciler ) GenerateStatus (ctx context.Context , dspa * dspav1alpha1.DataSciencePipelinesApplication ) []metav1.Condition {
310
+ var conditions []metav1.Condition
311
+
312
+ apiServerReady := r .buildCondition (config .APIServerReady , dspa , config .MinimumReplicasAvailable )
313
+ deploymentAvailable , _ := r .isDeploymentInCondition (ctx , dspa , "ds-pipeline" , appsv1 .DeploymentAvailable )
314
+ if deploymentAvailable {
315
+ apiServerReady .Status = metav1 .ConditionTrue
316
+ }
317
+ conditions = append (conditions , apiServerReady )
318
+
319
+ persistenceAgentReady := r .buildCondition (config .PersistenceAgentReady , dspa , config .MinimumReplicasAvailable )
320
+ deploymentAvailable , _ = r .isDeploymentInCondition (ctx , dspa , "ds-pipeline-persistenceagent" , appsv1 .DeploymentAvailable )
321
+ if deploymentAvailable {
322
+ persistenceAgentReady .Status = metav1 .ConditionTrue
323
+ }
324
+ conditions = append (conditions , persistenceAgentReady )
325
+
326
+ scheduledWorkflowReady := r .buildCondition (config .ScheduledWorkflowReady , dspa , config .MinimumReplicasAvailable )
327
+ deploymentAvailable , _ = r .isDeploymentInCondition (ctx , dspa , "ds-pipeline-scheduledworkflow" , appsv1 .DeploymentAvailable )
328
+ if deploymentAvailable {
329
+ scheduledWorkflowReady .Status = metav1 .ConditionTrue
330
+ }
331
+ conditions = append (conditions , scheduledWorkflowReady )
332
+
294
333
crReady := r .buildCondition (config .CrReady , dspa , config .MinimumReplicasAvailable )
295
334
crReady .Type = config .CrReady
296
335
@@ -309,18 +348,8 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
309
348
conditions [i ].LastTransitionTime = condition .LastTransitionTime
310
349
}
311
350
}
312
- dspa .Status .Conditions = conditions
313
351
314
- // Update Status
315
- err = r .Status ().Update (ctx , dspa )
316
- if err != nil {
317
- log .Info (err .Error ())
318
- return ctrl.Result {}, err
319
- }
320
-
321
- r .PublishMetrics (dspa , apiServerReady , persistenceAgentReady , scheduledWorkflowReady , crReady )
322
-
323
- return ctrl.Result {}, nil
352
+ return conditions
324
353
}
325
354
326
355
func (r * DSPAReconciler ) PublishMetrics (dspa * dspav1alpha1.DataSciencePipelinesApplication ,
0 commit comments