@@ -22,6 +22,7 @@ import (
2222 "reflect"
2323
2424 corev1 "k8s.io/api/core/v1"
25+ apierrors "k8s.io/apimachinery/pkg/api/errors"
2526 apimeta "k8s.io/apimachinery/pkg/api/meta"
2627 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728 "k8s.io/apimachinery/pkg/runtime"
@@ -84,19 +85,8 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8485
8586 service := & inferenceapi.Service {}
8687 if err := r .Get (ctx , types.NamespacedName {Name : playground .Name , Namespace : playground .Namespace }, service ); err == nil {
87- if ! controllerutil .HasControllerReference (service ) {
88- condition := metav1.Condition {
89- Type : inferenceapi .PlaygroundProgressing ,
90- Status : metav1 .ConditionFalse ,
91- Reason : "AbortProcessing" ,
92- Message : "Playground owns the same name with an existing Service" ,
93- }
94- apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
95- if err := r .Client .Status ().Update (ctx , playground ); err != nil {
96- return ctrl.Result {}, err
97- }
98- // No need to requeue. Once the Service is deleted, the Playground will be reconciled.
99- return ctrl.Result {}, nil
88+ if changed := handleUnexpectedCondition (playground , true , controllerutil .HasControllerReference (service )); changed {
89+ return ctrl.Result {}, r .Client .Status ().Update (ctx , playground )
10090 }
10191 }
10292
@@ -106,13 +96,19 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
10696 if playground .Spec .ModelClaim != nil {
10797 model := & coreapi.OpenModel {}
10898 if err := r .Get (ctx , types.NamespacedName {Name : string (playground .Spec .ModelClaim .ModelName )}, model ); err != nil {
99+ if apierrors .IsNotFound (err ) && handleUnexpectedCondition (playground , false , true ) {
100+ return ctrl.Result {}, r .Client .Status ().Update (ctx , playground )
101+ }
109102 return ctrl.Result {}, err
110103 }
111104 models = append (models , model )
112105 } else if playground .Spec .MultiModelsClaim != nil {
113106 for _ , modelName := range playground .Spec .MultiModelsClaim .ModelNames {
114107 model := & coreapi.OpenModel {}
115108 if err := r .Get (ctx , types.NamespacedName {Name : string (modelName )}, model ); err != nil {
109+ if apierrors .IsNotFound (err ) && handleUnexpectedCondition (playground , false , true ) {
110+ return ctrl.Result {}, r .Client .Status ().Update (ctx , playground )
111+ }
116112 return ctrl.Result {}, err
117113 }
118114 models = append (models , model )
@@ -130,11 +126,6 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request)
130126 }
131127
132128 // Handle status.
133- service = & inferenceapi.Service {}
134- if err := r .Get (ctx , types.NamespacedName {Name : playground .Name , Namespace : playground .Namespace }, service ); err != nil {
135- return ctrl.Result {}, err
136- }
137-
138129 setPlaygroundCondition (playground , service )
139130 if err := r .Client .Status ().Update (ctx , playground ); err != nil {
140131 return ctrl.Result {}, err
@@ -308,17 +299,40 @@ func buildWorkerTemplate(models []*coreapi.OpenModel, playground *inferenceapi.P
308299 return template
309300}
310301
311- func setPlaygroundCondition (playground * inferenceapi.Playground , service * inferenceapi.Service ) {
312- // For the start up.
313- if len (playground .Status .Conditions ) == 0 || ! apimeta .IsStatusConditionTrue (service .Status .Conditions , inferenceapi .PlaygroundProgressing ) {
302+ func handleUnexpectedCondition (playground * inferenceapi.Playground , modelExists bool , serviceHasOwner bool ) (changed bool ) {
303+ // Put it in the first place as more serious.
304+ if ! serviceHasOwner {
305+ condition := metav1.Condition {
306+ Type : inferenceapi .PlaygroundProgressing ,
307+ Status : metav1 .ConditionFalse ,
308+ Reason : "AbortProcessing" ,
309+ Message : "Playground owns the same name with an existing Service" ,
310+ }
311+ return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
312+ }
313+
314+ if ! modelExists {
315+ condition := metav1.Condition {
316+ Type : inferenceapi .PlaygroundProgressing ,
317+ Status : metav1 .ConditionFalse ,
318+ Reason : "AbortProcessing" ,
319+ Message : "Waiting for model creation" ,
320+ }
321+ return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
322+ }
323+ return false
324+ }
325+
326+ func setPlaygroundCondition (playground * inferenceapi.Playground , service * inferenceapi.Service ) (changed bool ) {
327+ // For the start up or Playground is recovered from AbortProcessing.
328+ if len (playground .Status .Conditions ) == 0 || apimeta .IsStatusConditionFalse (playground .Status .Conditions , inferenceapi .PlaygroundProgressing ) {
314329 condition := metav1.Condition {
315330 Type : inferenceapi .PlaygroundProgressing ,
316331 Status : metav1 .ConditionTrue ,
317332 Reason : "Pending" ,
318333 Message : "Waiting for inferenceService ready" ,
319334 }
320- apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
321- return
335+ return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
322336 }
323337
324338 if apimeta .IsStatusConditionTrue (service .Status .Conditions , inferenceapi .ServiceAvailable ) {
@@ -328,11 +342,11 @@ func setPlaygroundCondition(playground *inferenceapi.Playground, service *infere
328342 Reason : "PlaygroundReady" ,
329343 Message : "Playground is ready" ,
330344 }
331- apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
345+ return apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
332346 } else {
333347 // Still in starting up, no need to populate the condition.
334348 if apimeta .FindStatusCondition (playground .Status .Conditions , inferenceapi .PlaygroundAvailable ) == nil {
335- return
349+ return false
336350 }
337351
338352 condition := metav1.Condition {
@@ -341,14 +355,16 @@ func setPlaygroundCondition(playground *inferenceapi.Playground, service *infere
341355 Reason : "PlaygroundInProgress" ,
342356 Message : "Playground is progressing" ,
343357 }
344- apimeta .SetStatusCondition (& playground .Status .Conditions , condition )
358+ changed = apimeta .SetStatusCondition (& playground .Status .Conditions , condition ) || changed
345359
346360 // Set the available to false
347361 new_condition := metav1.Condition {
348362 Type : inferenceapi .PlaygroundAvailable ,
349363 Status : metav1 .ConditionFalse ,
364+ Reason : "PlaygroundNotReady" ,
350365 }
351- apimeta .SetStatusCondition (& playground .Status .Conditions , new_condition )
366+ changed = apimeta .SetStatusCondition (& playground .Status .Conditions , new_condition ) || changed
367+ return changed
352368 }
353369}
354370
0 commit comments