8000 Stop and resume a model [Raw Deployment] by hdefazio · Pull Request #4455 · kserve/kserve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Stop and resume a model [Raw Deployment] #4455

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

Merged
merged 14 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions pkg/apis/serving/v1beta1/inference_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ limitations under the License.
package v1beta1

import (
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kserve/kserve/pkg/constants"
)

// InferenceServiceSpec is the top level type for this resource
Expand Down Expand Up @@ -140,15 +136,3 @@ type InferenceServiceList struct {
func init() {
SchemeBuilder.Register(&InferenceService{}, &InferenceServiceList{})
}

func (isvc *InferenceService) GetForceStopRuntime() bool {
forceStopRuntime := false
if isvc == nil || isvc.Annotations == nil {
return forceStopRuntime
}
if val, exist := isvc.Annotations[constants.StopAnnotationKey]; exist {
forceStopRuntime = strings.EqualFold(val, "true")
}

return forceStopRuntime
}
3 changes: 3 additions & 0 deletions pkg/apis/serving/v1beta1/inference_service_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ const (
FailedToLoad ModelState = "FailedToLoad"
)

// Stopped Inference Service reason
const StoppedISVCReason = "Stopped"

// FailureReason enum
// +kubebuilder:validation:Enum=ModelLoadFailed;RuntimeUnhealthy;RuntimeDisabled;NoSupportingRuntime;RuntimeNotRecognized;InvalidPredictorSpec
type FailureReason string
Expand Down
71 changes: 39 additions & 32 deletions pkg/controller/v1beta1/inferenceservice/components/predictor.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,43 +193,47 @@ func (p *Predictor) Reconcile(ctx context.Context, isvc *v1beta1.InferenceServic
if kstatus, err = p.reconcileKnativeDeployment(ctx, isvc, &objectMeta, &podSpec); err != nil {
return ctrl.Result{}, err
}
if isvc.GetForceStopRuntime() {
// Exit early if we have already set the status to stopped
existing_stopped_condition := isvc.Status.GetCondition(v1beta1.Stopped)
if existing_stopped_condition != nil && existing_stopped_condition.Status == corev1.ConditionTrue {
return ctrl.Result{}, nil
}
}

deployMode := isvc.Status.DeploymentMode
// Handle InferenceService status updates based on the force stop annotation.
// If true, transition the service to a stopped and unready state; otherwise, ensure it's not marked as stopped.
if utils.GetForceStopRuntime(isvc) {
// Exit early if we have already set the status to stopped
existingStoppedCondition := isvc.Status.GetCondition(v1beta1.Stopped)
if existingStoppedCondition != nil && existingStoppedCondition.Status == corev1.ConditionTrue {
return ctrl.Result{}, nil
}

// Clear all statuses
isvc.Status = v1beta1.InferenceServiceStatus{}
deployMode := isvc.Status.DeploymentMode

// Preserve the deployment mode value
isvc.Status.DeploymentMode = deployMode
// Clear all statuses
isvc.Status = v1beta1.InferenceServiceStatus{}

// Set the ready condition
predictor_ready_condition := &apis.Condition{
Type: v1beta1.PredictorReady,
Status: corev1.ConditionFalse,
}
isvc.Status.SetCondition(v1beta1.PredictorReady, predictor_ready_condition)
// Preserve the deployment mode value
isvc.Status.DeploymentMode = deployMode

// Add the stopped condition
stopped_condition := &apis.Condition{
Type: v1beta1.Stopped,
Status: corev1.ConditionTrue,
}
isvc.Status.SetCondition(v1beta1.Stopped, stopped_condition)
// Set the ready condition
predictorReadyCondition := &apis.Condition{
Type: v1beta1.PredictorReady,
Status: corev1.ConditionFalse,
Reason: v1beta1.StoppedISVCReason,
}
isvc.Status.SetCondition(v1beta1.PredictorReady, predictorReadyCondition)

return ctrl.Result{}, nil
} else {
resume_condition := &apis.Condition{
Type: v1beta1.Stopped,
Status: corev1.ConditionFalse,
}
isvc.Status.SetCondition(v1beta1.Stopped, resume_condition)
// Add the stopped condition
stoppedCondition := &apis.Condition{
Type: v1beta1.Stopped,
Status: corev1.ConditionTrue,
}
isvc.Status.SetCondition(v1beta1.Stopped, stoppedCondition)

return ctrl.Result{}, nil
} else {
resumeCondition := &apis.Condition{
Type: v1beta1.Stopped,
Status: corev1.ConditionFalse,
}
isvc.Status.SetCondition(v1beta1.Stopped, resumeCondition)
}

statusSpec := isvc.Status.Components[v1beta1.PredictorComponent]
Expand Down Expand Up @@ -700,7 +704,10 @@ func (p *Predictor) reconcileRawDeployment(ctx context.Context, isvc *v1beta1.In
return errors.Wrapf(err, "fails to reconcile predictor")
}

isvc.Status.PropagateRawStatus(v1beta1.PredictorComponent, deploymentList, r.URL)
if !utils.GetForceStopRuntime(isvc) {
isvc.Status.PropagateRawStatus(v1beta1.PredictorComponent, deploymentList, r.URL)
}

return nil
}

Expand All @@ -715,7 +722,7 @@ func (p *Predictor) reconcileKnativeDeployment(ctx context.Context, isvc *v1beta
if err != nil {
return nil, errors.Wrapf(err, "fails to reconcile predictor")
}
if !isvc.GetForceStopRuntime() {
if !utils.GetForceStopRuntime(isvc) {
isvc.Status.PropagateStatus(v1beta1.PredictorComponent, kstatus)
}
return kstatus, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/v1beta1/inferenceservice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (r *InferenceServiceReconciler) Reconcile(ctx context.Context, req ctrl.Req
if isvc.Spec.Explainer != nil {
componentList = append(componentList, v1beta1.ExplainerComponent)
}
if !isvc.GetForceStopRuntime() {
if !utils.GetForceStopRuntime(isvc) {
isvc.Status.PropagateCrossComponentStatus(componentList, v1beta1.RoutesReady)
isvc.Status.PropagateCrossComponentStatus(componentList, v1beta1.LatestDeploymentReady)
}
Expand Down
Loading
Loading
0