@@ -19,15 +19,18 @@ 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
"github.com/project-codeflare/codeflare-operator/controllers/config"
25
26
26
27
codeflarev1alpha1 "github.com/project-codeflare/codeflare-operator/api/v1alpha1"
28
+ appsv1 "k8s.io/api/apps/v1"
27
29
corev1 "k8s.io/api/core/v1"
28
30
rbacv1 "k8s.io/api/rbac/v1"
29
31
apierrs "k8s.io/apimachinery/pkg/api/errors"
30
32
"k8s.io/apimachinery/pkg/runtime"
33
+ "k8s.io/apimachinery/pkg/types"
31
34
ctrl "sigs.k8s.io/controller-runtime"
32
35
"sigs.k8s.io/controller-runtime/pkg/client"
33
36
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -186,13 +189,43 @@ func (r *MCADReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
186
189
return ctrl.Result {}, err
187
190
}
188
191
192
+ err = updateReadyStatus (ctx , r , req , mcadCustomResource )
193
+ if err != nil {
194
+ return ctrl.Result {}, err
195
+ }
196
+ err = r .Client .Status ().Update (context .Background (), mcadCustomResource )
197
+ if err != nil {
198
+ return ctrl.Result {}, err
199
+ }
200
+
189
201
return ctrl.Result {}, nil
190
202
}
191
203
204
+ func updateReadyStatus (ctx context.Context , r * MCADReconciler , req ctrl.Request , mcadCustomResource * codeflarev1alpha1.MCAD ) error {
205
+ deployment := & appsv1.Deployment {}
206
+ err := r .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("mcad-controller-%s" , req .Name ), Namespace : req .Namespace }, deployment )
207
+ if err != nil {
208
+ return err
209
+ }
210
+ r .Log .Info ("Checking if deployment is ready." )
211
+ isDeploymentReady := false
212
+ for _ , condition := range deployment .Status .Conditions {
213
+ r .Log .Info (fmt .Sprintf ("%v: %v" , condition .Type , condition .Status ))
214
+ if condition .Type == appsv1 .DeploymentAvailable && condition .Status == corev1 .ConditionTrue {
215
+ isDeploymentReady = true
216
+ r .Log .Info ("Deployment ready" )
217
+ break
218
+ }
219
+ }
220
+ mcadCustomResource .Status .Ready = isDeploymentReady
221
+ return nil
222
+ }
223
+
192
224
// SetupWithManager sets up the controller with the Manager.
193
225
func (r * MCADReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
194
226
return ctrl .NewControllerManagedBy (mgr ).
195
227
For (& codeflarev1alpha1.MCAD {}).
228
+ Owns (& appsv1.Deployment {}).
196
229
Owns (& corev1.ConfigMap {}).
197
230
Owns (& corev1.Service {}).
198
231
Owns (& corev1.ServiceAccount {}).
0 commit comments