@@ -125,7 +125,6 @@ func (r *NIMCacheReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
125
125
}
126
126
return ctrl.Result {}, client .IgnoreNotFound (err )
127
127
}
128
-
129
128
logger .Info ("Reconciling" , "NIMCache" , nimCache .Name )
130
129
131
130
// Check if the instance is marked for deletion
@@ -153,14 +152,19 @@ func (r *NIMCacheReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
153
152
return ctrl.Result {}, nil
154
153
}
155
154
}
156
-
157
155
// Handle nim-cache reconciliation
158
156
result , err := r .reconcileNIMCache (ctx , nimCache )
159
157
if err != nil {
160
158
logger .Error (err , "error reconciling NIMCache" , "name" , nimCache .Name )
159
+ conditions .UpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionReconcileFailed , metav1 .ConditionTrue , "ReconcileFailed" , err .Error ())
160
+ nimCache .Status .State = appsv1alpha1 .NimCacheStatusNotReady
161
+ errUpdate := r .updateNIMCacheStatus (ctx , nimCache )
162
+ if errUpdate != nil {
163
+ logger .Error (err , "Failed to update NIMCache status" , "NIMCache" , nimCache .Name )
164
+ return result , errUpdate
165
+ }
161
166
return result , err
162
167
}
163
-
164
168
return result , nil
165
169
}
166
170
@@ -444,10 +448,6 @@ func (r *NIMCacheReconciler) reconcilePVC(ctx context.Context, nimCache *appsv1a
444
448
445
449
conditions .UpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionPVCCreated , metav1 .ConditionTrue , "PVCCreated" , "The PVC has been created for caching NIM model" )
446
450
nimCache .Status .State = appsv1alpha1 .NimCacheStatusPVCCreated
447
- if err := r .Status ().Update (ctx , nimCache ); err != nil {
448
- logger .Error (err , "Failed to update status" , "NIMCache" , nimCache .Name )
449
- return err
450
- }
451
451
} else {
452
452
logger .Error (err , "PVC doesn't exist and auto-creation is not enabled" , "name" , pvcNamespacedName )
453
453
return err
@@ -621,10 +621,6 @@ func (r *NIMCacheReconciler) reconcileModelSelection(ctx context.Context, nimCac
621
621
}
622
622
623
623
nimCache .Annotations [SelectedNIMProfilesAnnotationKey ] = string (profilesJSON )
624
- if err := r .Update (ctx , nimCache ); err != nil {
625
- logger .Error (err , "unable to update NIMCache with selected profiles annotation" )
626
- return err
627
- }
628
624
}
629
625
return nil
630
626
}
@@ -659,10 +655,6 @@ func (r *NIMCacheReconciler) reconcileJob(ctx context.Context, nimCache *appsv1a
659
655
conditions .UpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionJobCreated , metav1 .ConditionTrue , "JobCreated" , "The Job to cache NIM has been created" )
660
656
nimCache .Status .State = appsv1alpha1 .NimCacheStatusStarted
661
657
nimCache .Status .Profiles = []v1alpha1.NIMProfile {}
662
- if err := r .Status ().Update (ctx , nimCache ); err != nil {
663
- return err
664
- }
665
- // return to reconcile later on job status update
666
658
return nil
667
659
}
668
660
@@ -713,39 +705,24 @@ func (r *NIMCacheReconciler) reconcileJobStatus(ctx context.Context, nimCache *a
713
705
}
714
706
}
715
707
716
- if err := r .Status ().Update (ctx , nimCache ); err != nil {
717
- return fmt .Errorf ("failed to update status: %w" , err )
718
- }
719
-
720
708
case job .Status .Failed > 0 && nimCache .Status .State != appsv1alpha1 .NimCacheStatusFailed :
721
709
logger .Info ("Failed to cache NIM, job failed" , "job" , jobName )
722
710
conditions .UpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionJobCompleted , metav1 .ConditionFalse , "JobFailed" , "The Job to cache NIM has failed" )
723
711
nimCache .Status .State = appsv1alpha1 .NimCacheStatusFailed
724
712
nimCache .Status .Profiles = []v1alpha1.NIMProfile {}
725
713
726
- if err := r .Status ().Update (ctx , nimCache ); err != nil {
727
- return fmt .Errorf ("failed to update status: %w" , err )
728
- }
729
-
730
714
case job .Status .Active > 0 && nimCache .Status .State != appsv1alpha1 .NimCacheStatusInProgress :
731
715
logger .Info ("Caching NIM is in progress, job running" , "job" , jobName )
732
716
conditions .UpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionJobPending , metav1 .ConditionFalse , "JobRunning" , "The Job to cache NIM is in progress" )
733
717
nimCache .Status .State = appsv1alpha1 .NimCacheStatusInProgress
734
718
nimCache .Status .Profiles = []v1alpha1.NIMProfile {}
735
719
736
- if err := r .Status ().Update (ctx , nimCache ); err != nil {
737
- return fmt .Errorf ("failed to update status: %w" , err )
738
- }
739
-
740
720
case job .Status .Active == 0 && nimCache .Status .State != appsv1alpha1 .NimCacheStatusReady && nimCache .Status .State != appsv1alpha1 .NimCacheStatusPending :
741
721
logger .Info ("Caching NIM is in progress, job pending" , "job" , jobName )
742
722
conditions .UpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionJobPending , metav1 .ConditionTrue , "JobPending" , "The Job to cache NIM is in pending state" )
743
723
nimCache .Status .State = appsv1alpha1 .NimCacheStatusPending
744
724
nimCache .Status .Profiles = []v1alpha1.NIMProfile {}
745
725
746
- if err := r .Status ().Update (ctx , nimCache ); err != nil {
747
- return fmt .Errorf ("failed to update status: %w" , err )
748
- }
749
726
}
750
727
751
728
return nil
@@ -815,9 +792,33 @@ func (r *NIMCacheReconciler) reconcileNIMCache(ctx context.Context, nimCache *ap
815
792
logger .Error (err , "reconciliation of caching job failed" , "job" , getJobName (nimCache ))
816
793
return ctrl.Result {}, err
817
794
}
795
+
796
+ conditions .IfPresentUpdateCondition (& nimCache .Status .Conditions , appsv1alpha1 .NimCacheConditionReconcileFailed , metav1 .ConditionFalse , "Reconciled" , "" )
797
+
798
+ err = r .updateNIMCacheStatus (ctx , nimCache )
799
+ if err != nil {
800
+ logger .Error (err , "Failed to update NIMCache status" , "NIMCache" , nimCache .Name )
801
+ return ctrl.Result {}, err
802
+ }
818
803
return ctrl.Result {}, nil
819
804
}
820
805
806
+ func (r * NIMCacheReconciler ) updateNIMCacheStatus (ctx context.Context , nimCache * appsv1alpha1.NIMCache ) error {
807
+ logger := r .GetLogger ()
808
+ obj := & appsv1alpha1.NIMCache {}
809
+ errGet := r .Get (ctx , types.NamespacedName {Name : nimCache .Name , Namespace : nimCache .GetNamespace ()}, obj )
810
+ if errGet != nil {
811
+ logger .Error (errGet , "error getting NIMCache" , "name" , nimCache .Name )
812
+ return errGet
813
+ }
814
+ obj .Status = nimCache .Status
815
+ if err := r .Status ().Update (ctx , obj ); err != nil {
816
+ logger .Error (err , "Failed to update status" , "NIMCache" , nimCache .Name )
817
+ return err
818
+ }
819
+ return nil
820
+ }
821
+
821
822
func getJobName (nimCache * appsv1alpha1.NIMCache ) string {
822
823
return fmt .Sprintf ("%s-job" , nimCache .GetName ())
823
824
}
0 commit comments