-
-
Notifications
You must be signed in to change notification settings - Fork 44
Add new conditions to Playground #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "reflect" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
@@ -85,18 +86,11 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |
| service := &inferenceapi.Service{} | ||
| if err := r.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service); err == nil { | ||
| if !controllerutil.HasControllerReference(service) { | ||
| condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundProgressing, | ||
| Status: metav1.ConditionFalse, | ||
| Reason: "AbortProcessing", | ||
| Message: "Playground owns the same name with an existing Service", | ||
| err = fmt.Errorf("the Playground %v owns the same name with an exist Service", klog.KObj(playground)) | ||
| if changed := handleUnexpectedCondition(playground, true, false); changed { | ||
| err = r.Client.Status().Update(ctx, playground) | ||
| } | ||
| apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| if err := r.Client.Status().Update(ctx, playground); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
| // No need to requeue. Once the Service is deleted, the Playground will be reconciled. | ||
| return ctrl.Result{}, nil | ||
| return ctrl.Result{}, err | ||
kerthcet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -106,13 +100,19 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |
| if playground.Spec.ModelClaim != nil { | ||
| model := &coreapi.OpenModel{} | ||
| if err := r.Get(ctx, types.NamespacedName{Name: string(playground.Spec.ModelClaim.ModelName)}, model); err != nil { | ||
| if apierrors.IsNotFound(err) && handleUnexpectedCondition(playground, false, true) { | ||
| return ctrl.Result{}, r.Client.Status().Update(ctx, playground) | ||
| } | ||
| return ctrl.Result{}, err | ||
| } | ||
| models = append(models, model) | ||
| } else if playground.Spec.MultiModelsClaim != nil { | ||
| for _, modelName := range playground.Spec.MultiModelsClaim.ModelNames { | ||
| model := &coreapi.OpenModel{} | ||
| if err := r.Get(ctx, types.NamespacedName{Name: string(modelName)}, model); err != nil { | ||
| if apierrors.IsNotFound(err) && handleUnexpectedCondition(playground, false, true) { | ||
| return ctrl.Result{}, r.Client.Status().Update(ctx, playground) | ||
| } | ||
| return ctrl.Result{}, err | ||
| } | ||
| models = append(models, model) | ||
|
|
@@ -130,11 +130,6 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |
| } | ||
|
|
||
| // Handle status. | ||
| service = &inferenceapi.Service{} | ||
| if err := r.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
|
|
||
| setPlaygroundCondition(playground, service) | ||
| if err := r.Client.Status().Update(ctx, playground); err != nil { | ||
| return ctrl.Result{}, err | ||
|
|
@@ -308,17 +303,40 @@ func buildWorkerTemplate(models []*coreapi.OpenModel, playground *inferenceapi.P | |
| return template | ||
| } | ||
|
|
||
| func setPlaygroundCondition(playground *inferenceapi.Playground, service *inferenceapi.Service) { | ||
| // For the start up. | ||
| if len(playground.Status.Conditions) == 0 || !apimeta.IsStatusConditionTrue(service.Status.Conditions, inferenceapi.PlaygroundProgressing) { | ||
| func handleUnexpectedCondition(playground *inferenceapi.Playground, modelExists bool, serviceHasOwner bool) (changed bool) { | ||
| // Put it in the first place as more serious. | ||
| if !serviceHasOwner { | ||
kerthcet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundProgressing, | ||
| Status: metav1.ConditionFalse, | ||
| Reason: "AbortProcessing", | ||
| Message: "Playground owns the same name with an existing Service", | ||
| } | ||
| return apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| } | ||
|
|
||
| if !modelExists { | ||
| condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundProgressing, | ||
| Status: metav1.ConditionFalse, | ||
| Reason: "AbortProcessing", | ||
| Message: "Waiting for model creation", | ||
| } | ||
| return apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func setPlaygroundCondition(playground *inferenceapi.Playground, service *inferenceapi.Service) (changed bool) { | ||
| // For the start up or Playground is recovered from AbortProcessing. | ||
| if len(playground.Status.Conditions) == 0 || apimeta.IsStatusConditionFalse(playground.Status.Conditions, inferenceapi.PlaygroundProgressing) { | ||
| condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundProgressing, | ||
| Status: metav1.ConditionTrue, | ||
| Reason: "Pending", | ||
| Message: "Waiting for inferenceService ready", | ||
| } | ||
| apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| return | ||
| return apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| } | ||
|
|
||
| if apimeta.IsStatusConditionTrue(service.Status.Conditions, inferenceapi.ServiceAvailable) { | ||
|
|
@@ -328,11 +346,11 @@ func setPlaygroundCondition(playground *inferenceapi.Playground, service *infere | |
| Reason: "PlaygroundReady", | ||
| Message: "Playground is ready", | ||
| } | ||
| apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| return apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| } else { | ||
| // Still in starting up, no need to populate the condition. | ||
| if apimeta.FindStatusCondition(playground.Status.Conditions, inferenceapi.PlaygroundAvailable) == nil { | ||
| return | ||
| return false | ||
| } | ||
|
|
||
| condition := metav1.Condition{ | ||
|
|
@@ -341,14 +359,16 @@ func setPlaygroundCondition(playground *inferenceapi.Playground, service *infere | |
| Reason: "PlaygroundInProgress", | ||
| Message: "Playground is progressing", | ||
| } | ||
| apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| changed = apimeta.SetStatusCondition(&playground.Status.Conditions, condition) || changed | ||
|
|
||
| // Set the available to false | ||
| new_condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundAvailable, | ||
| Status: metav1.ConditionFalse, | ||
| Reason: "PlaygroundNotReady", | ||
|
||
| } | ||
| apimeta.SetStatusCondition(&playground.Status.Conditions, new_condition) | ||
| changed = apimeta.SetStatusCondition(&playground.Status.Conditions, new_condition) || changed | ||
| return changed | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.