@@ -203,17 +203,17 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
203
203
}
204
204
205
205
// Wait for deployment
206
- ready , err := r .isDeploymentReady (ctx , & namespacedName )
206
+ msg , ready , err := r .isDeploymentReady (ctx , & namespacedName )
207
207
if err != nil {
208
208
return ctrl.Result {}, err
209
209
}
210
210
211
211
if ! ready {
212
212
// Update status as NotReady
213
- err = r .updater .SetConditionsNotReady (ctx , nimService , conditions .NotReady , "Deployment is not ready" )
213
+ err = r .updater .SetConditionsNotReady (ctx , nimService , conditions .NotReady , msg )
214
214
} else {
215
215
// Update status as ready
216
- err = r .updater .SetConditionsReady (ctx , nimService , conditions .Ready , "Deployment is ready" )
216
+ err = r .updater .SetConditionsReady (ctx , nimService , conditions .Ready , msg )
217
217
}
218
218
219
219
if err != nil {
@@ -278,22 +278,40 @@ func (r *NIMServiceReconciler) renderAndSyncResource(ctx context.Context, nimSer
278
278
}
279
279
280
280
// CheckDeploymentReadiness checks if the Deployment is ready
281
- func (r * NIMServiceReconciler ) isDeploymentReady (ctx context.Context , namespacedName * types.NamespacedName ) (bool , error ) {
282
- dep := & appsv1.Deployment {}
283
- err := r .Get (ctx , client.ObjectKey {Name : namespacedName .Name , Namespace : namespacedName .Namespace }, dep )
281
+ func (r * NIMServiceReconciler ) isDeploymentReady (ctx context.Context , namespacedName * types.NamespacedName ) (string , bool , error ) {
282
+ deployment := & appsv1.Deployment {}
283
+ err := r .Get (ctx , client.ObjectKey {Name : namespacedName .Name , Namespace : namespacedName .Namespace }, deployment )
284
284
if err != nil {
285
285
if errors .IsNotFound (err ) {
286
- return false , nil
286
+ return "" , false , nil
287
287
}
288
- return false , err
288
+ return "" , false , err
289
289
}
290
290
291
- for _ , cond := range dep .Status .Conditions {
292
- if cond .Type == appsv1 .DeploymentAvailable && cond .Status == corev1 .ConditionTrue {
293
- return true , nil
291
+ cond := getDeploymentCondition (deployment .Status , appsv1 .DeploymentProgressing )
292
+ if cond != nil && cond .Reason == "ProgressDeadlineExceeded" {
293
+ return fmt .Sprintf ("deployment %q exceeded its progress deadline" , deployment .Name ), false , fmt .Errorf ("deployment %q exceeded its progress deadline" , deployment .Name )
294
+ }
295
+ if deployment .Spec .Replicas != nil && deployment .Status .UpdatedReplicas < * deployment .Spec .Replicas {
296
+ return fmt .Sprintf ("Waiting for deployment %q rollout to finish: %d out of %d new replicas have been updated...\n " , deployment .Name , deployment .Status .UpdatedReplicas , * deployment .Spec .Replicas ), false , nil
297
+ }
298
+ if deployment .Status .Replicas > deployment .Status .UpdatedReplicas {
299
+ return fmt .Sprintf ("Waiting for deployment %q rollout to finish: %d old replicas are pending termination...\n " , deployment .Name , deployment .Status .Replicas - deployment .Status .UpdatedReplicas ), false , nil
300
+ }
301
+ if deployment .Status .AvailableReplicas < deployment .Status .UpdatedReplicas {
302
+ return fmt .Sprintf ("Waiting for deployment %q rollout to finish: %d of %d updated replicas are available...\n " , deployment .Name , deployment .Status .AvailableReplicas , deployment .Status .UpdatedReplicas ), false , nil
303
+ }
304
+ return fmt .Sprintf ("deployment %q successfully rolled out\n " , deployment .Name ), true , nil
305
+ }
306
+
307
+ func getDeploymentCondition (status appsv1.DeploymentStatus , condType appsv1.DeploymentConditionType ) * appsv1.DeploymentCondition {
308
+ for i := range status .Conditions {
309
+ c := status .Conditions [i ]
310
+ if c .Type == condType {
311
+ return & c
294
312
}
295
313
}
296
- return false , nil
314
+ return nil
297
315
}
298
316
299
317
func (r * NIMServiceReconciler ) syncResource (ctx context.Context , obj client.Object , desired client.Object , namespacedName types.NamespacedName ) error {
0 commit comments