@@ -90,7 +90,7 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
9090 if err := r .Get (ctx , types.NamespacedName {Name : playground .Name , Namespace : playground .Namespace }, service ); err == nil {
9191 if ! metav1 .IsControlledBy (service , playground ) {
9292 logger .Info ("failed to construct inference Service as a Service with the same exists" , "Playground" , klog .KObj (playground ))
93- if changed := handleUnexpectedCondition (playground , true , true ); changed {
93+ if changed := handleUnexpectedCondition (playground , ServiceConflictCondition ); changed {
9494 err = r .Client .Status ().Update (ctx , playground )
9595 }
9696 // if update successfully, err will be nil and we'll hanging here until Playground or Service deleted.
@@ -100,7 +100,7 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
100100
101101 models , err := helper .FetchModelsByPlayground (ctx , r .Client , playground )
102102 if err != nil {
103- if apierrors .IsNotFound (err ) && handleUnexpectedCondition (playground , false , false ) {
103+ if apierrors .IsNotFound (err ) && handleUnexpectedCondition (playground , ModelMissingCondition ) {
104104 return ctrl.Result {}, r .Client .Status ().Update (ctx , playground )
105105 }
106106 return ctrl.Result {}, err
@@ -381,30 +381,43 @@ func buildTemplate(models []*coreapi.OpenModel, playground *inferenceapi.Playgro
381381 return template , nil
382382}
383383
384- func handleUnexpectedCondition (playground * inferenceapi.Playground , modelExists bool , serviceWithSameNameExists bool ) (changed bool ) {
385- // Put it in the first place as more serious.
386- if serviceWithSameNameExists {
387- condition := metav1.Condition {
388- Type : inferenceapi .PlaygroundProgressing ,
389- Status : metav1 .ConditionFalse ,
390- Reason : "AbortProcessing" ,
391- Message : "Playground owns the same name with an existing Service" ,
392- }
393- return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
394- }
384+ type UnexpectedConditionType string
395385
396- if ! modelExists {
397- condition := metav1.Condition {
398- Type : inferenceapi .PlaygroundProgressing ,
399- Status : metav1 .ConditionFalse ,
400- Reason : "AbortProcessing" ,
401- Message : "Waiting for model creation" ,
402- }
403- return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
386+ const (
387+ ServiceConflictCondition UnexpectedConditionType = "ServiceConflict"
388+ ModelMissingCondition UnexpectedConditionType = "ModelMissing"
389+ )
390+
391+ func handleUnexpectedCondition (playground * inferenceapi.Playground , unexpectedConditionType UnexpectedConditionType ) bool {
392+ switch unexpectedConditionType {
393+ case ServiceConflictCondition :
394+ return handleServiceConflictCondition (playground )
395+ case ModelMissingCondition :
396+ return handleModelMissingCondition (playground )
404397 }
405398 return false
406399}
407400
401+ func handleServiceConflictCondition (playground * inferenceapi.Playground ) (changed bool ) {
402+ condition := metav1.Condition {
403+ Type : inferenceapi .PlaygroundProgressing ,
404+ Status : metav1 .ConditionFalse ,
405+ Reason : "AbortProcessing" ,
406+ Message : "Playground owns the same name with an existing Service" ,
407+ }
408+ return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
409+ }
410+
411+ func handleModelMissingCondition (playground * inferenceapi.Playground ) (changed bool ) {
412+ condition := metav1.Condition {
413+ Type : inferenceapi .PlaygroundProgressing ,
414+ Status : metav1 .ConditionFalse ,
415+ Reason : "AbortProcessing" ,
416+ Message : "Waiting for model creation" ,
417+ }
418+ return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
419+ }
420+
408421func setPlaygroundCondition (playground * inferenceapi.Playground , service * inferenceapi.Service ) (changed bool ) {
409422 defer func () {
410423 if playground .Status .Selector != service .Status .Selector {
0 commit comments