@@ -19,6 +19,7 @@ package controllers
19
19
import (
20
20
"context"
21
21
"fmt"
22
+
22
23
"github.com/go-logr/logr"
23
24
mf "github.com/manifestival/manifestival"
24
25
dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1"
@@ -28,6 +29,7 @@ import (
28
29
corev1 "k8s.io/api/core/v1"
29
30
rbacv1 "k8s.io/api/rbac/v1"
30
31
apierrs "k8s.io/apimachinery/pkg/api/errors"
32
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
33
"k8s.io/apimachinery/pkg/runtime"
32
34
"k8s.io/apimachinery/pkg/types"
33
35
ctrl "sigs.k8s.io/controller-runtime"
@@ -106,6 +108,37 @@ func (r *DSPAReconciler) DeleteResourceIfItExists(ctx context.Context, obj clien
106
108
return err
107
109
}
108
110
111
+ func (r * DSPAReconciler ) buildCondition (conditionType string , dspa * dspav1alpha1.DataSciencePipelinesApplication , reason string ) metav1.Condition {
112
+ condition := metav1.Condition {}
113
+ condition .Type = conditionType
114
+ condition .ObservedGeneration = dspa .Generation
115
+ condition .Status = metav1 .ConditionFalse
116
+ condition .Reason = reason
117
+
118
+ if dspa .Status .Conditions == nil {
119
+ condition .LastTransitionTime = metav1 .Now ()
120
+ }
121
+
122
+ return condition
123
+ }
124
+
125
+ func (r * DSPAReconciler ) isDeploymentAvailable (ctx context.Context , dspa * dspav1alpha1.DataSciencePipelinesApplication , name string ) bool {
126
+ found := & appsv1.Deployment {}
127
+
128
+ // Every Deployment in DSPA is the name followed by the DSPA CR name
129
+ component := name + "-" + dspa .Name
130
+
131
+ err := r .Get (ctx , types.NamespacedName {Name : component , Namespace : dspa .Namespace }, found )
132
+ if err == nil {
133
+ for _ , s := range found .Status .Conditions {
134
+ if s .Type == "Available" && s .Status == corev1 .ConditionTrue {
135
+ return true
136
+ }
137
+ }
138
+ }
139
+ return false
140
+ }
141
+
109
142
//+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications,verbs=get;list;watch;create;update;patch;delete
110
143
//+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications/status,verbs=get;update;patch
111
144
//+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications/finalizers,verbs=update
@@ -189,46 +222,118 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
189
222
return ctrl.Result {}, nil
190
223
}
191
224
225
+ // Initialize conditions
226
+ var conditions []metav1.Condition
227
+
228
+ databaseReady := r .buildCondition (config .DatabaseReady , dspa , config .DatabaseReady )
192
229
err = r .ReconcileDatabase (ctx , dspa , params )
193
230
if err != nil {
194
231
return ctrl.Result {}, err
195
232
}
196
233
234
+ if r .isDeploymentAvailable (ctx , dspa , "mariadb" ) {
235
+ databaseReady .Status = metav1 .ConditionTrue
236
+ }
237
+ conditions = append (conditions , databaseReady )
238
+
239
+ objectStorageReady := r .buildCondition (config .ObjectStorageReady , dspa , config .ObjectStorageReady )
197
240
err = r .ReconcileStorage (ctx , dspa , params )
198
241
if err != nil {
199
242
return ctrl.Result {}, err
200
243
}
201
244
245
+ if r .isDeploymentAvailable (ctx , dspa , "minio" ) {
246
+ objectStorageReady .Status = metav1 .ConditionTrue
247
+ }
248
+ conditions = append (conditions , objectStorageReady )
249
+
202
250
err = r .ReconcileCommon (dspa , params )
203
251
if err != nil {
204
252
return ctrl.Result {}, err
205
253
}
206
254
255
+ apiServerReady := r .buildCondition (config .APIServerReady , dspa , config .MinimumReplicasAvailable )
207
256
err = r .ReconcileAPIServer (ctx , dspa , params )
208
257
if err != nil {
209
258
return ctrl.Result {}, err
210
259
}
211
260
261
+ if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline" ) {
262
+ apiServerReady .Status = metav1 .ConditionTrue
263
+ }
264
+ conditions = append (conditions , apiServerReady )
265
+
266
+ persistenceAgentReady := r .buildCondition (config .PersistenceAgentReady , dspa , config .MinimumReplicasAvailable )
212
267
err = r .ReconcilePersistenceAgent (dspa , params )
213
268
if err != nil {
214
269
return ctrl.Result {}, err
215
270
}
216
271
272
+ if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline-persistenceagent" ) {
273
+ persistenceAgentReady .Status = metav1 .ConditionTrue
274
+ }
275
+ conditions = append (conditions , persistenceAgentReady )
276
+
277
+ scheduledWorkflowReady := r .buildCondition (config .ScheduledWorkflowReady , dspa , config .MinimumReplicasAvailable )
217
278
err = r .ReconcileScheduledWorkflow (dspa , params )
218
279
if err != nil {
219
280
return ctrl.Result {}, err
220
281
}
221
282
283
+ if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline-scheduledworkflow" ) {
284
+ scheduledWorkflowReady .Status = metav1 .ConditionTrue
285
+ }
286
+ conditions = append (conditions , scheduledWorkflowReady )
287
+
288
+ userInterfaceReady := r .buildCondition (config .UserInterfaceReady , dspa , config .MinimumReplicasAvailable )
222
289
err = r .ReconcileUI (dspa , params )
223
290
if err != nil {
224
291
return ctrl.Result {}, err
225
292
}
226
293
294
+ if r .isDeploymentAvailable (ctx , dspa , "ds-pipeline-ui" ) {
295
+ userInterfaceReady .Status = metav1 .ConditionTrue
296
+ }
297
+ conditions = append (conditions , userInterfaceReady )
298
+
227
299
err = r .ReconcileViewerCRD (dspa , params )
228
300
if err != nil {
229
301
return ctrl.Result {}, err
230
302
}
231
303
304
+ log .Info ("Updating CR status" )
305
+
306
+ crReady := r .buildCondition (config .CrReady , dspa , config .MinimumReplicasAvailable )
307
+ crReady .Type = config .CrReady
308
+
309
+ // Compute Ready Logic for the CR
310
+ if ((apiServerReady .Status == metav1 .ConditionTrue ) &&
311
+ (persistenceAgentReady .Status == metav1 .ConditionTrue ) &&
312
+ (scheduledWorkflowReady .Status == metav1 .ConditionTrue ) &&
313
+ (databaseReady .Status == metav1 .ConditionTrue ) &&
314
+ (objectStorageReady .Status == metav1 .ConditionTrue )) &&
315
+ (userInterfaceReady .Status == metav1 .ConditionTrue || (userInterfaceReady .Status == metav1 .ConditionFalse && ! dspa .Spec .MlPipelineUI .Deploy )) {
316
+ crReady .Status = metav1 .ConditionTrue
317
+ } else {
318
+ crReady .Status = metav1 .ConditionFalse
319
+ }
320
+ conditions = append (conditions , crReady )
321
+
322
+ for i , condition := range dspa .Status .Conditions {
323
+ if condition .Status != conditions [i ].Status {
324
+ conditions [i ].LastTransitionTime = metav1 .Now ()
325
+ } else {
326
+ conditions [i ].LastTransitionTime = condition .LastTransitionTime
327
+ }
328
+ }
329
+ dspa .Status .Conditions = conditions
330
+
331
+ err = r .Status ().Update (ctx , dspa )
332
+ if err != nil {
333
+ log .Info (err .Error ())
334
+ return ctrl.Result {}, err
335
+ }
336
+
232
337
return ctrl.Result {}, nil
233
338
}
234
339
0 commit comments