@@ -203,17 +203,17 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
203203 }
204204
205205 // Wait for deployment
206- ready , err := r .isDeploymentReady (ctx , & namespacedName )
206+ msg , ready , err := r .isDeploymentReady (ctx , & namespacedName )
207207 if err != nil {
208208 return ctrl.Result {}, err
209209 }
210210
211211 if ! ready {
212212 // 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 )
214214 } else {
215215 // 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 )
217217 }
218218
219219 if err != nil {
@@ -278,22 +278,40 @@ func (r *NIMServiceReconciler) renderAndSyncResource(ctx context.Context, nimSer
278278}
279279
280280// 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 )
284284 if err != nil {
285285 if errors .IsNotFound (err ) {
286- return false , nil
286+ return "" , false , nil
287287 }
288- return false , err
288+ return "" , false , err
289289 }
290290
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
294312 }
295313 }
296- return false , nil
314+ return nil
297315}
298316
299317func (r * NIMServiceReconciler ) syncResource (ctx context.Context , obj client.Object , desired client.Object , namespacedName types.NamespacedName ) error {
0 commit comments