Skip to content
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

allow external hpa #520

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions config/internal/base/deployment.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ metadata:
app.kubernetes.io/name: modelmesh-controller
name: {{.ServiceName}}-{{.Name}}
spec:
{{if ge .Replicas 0}}
replicas: {{.Replicas}}
{{end}}
selector:
matchLabels:
modelmesh-service: {{.ServiceName}}
Expand Down
4 changes: 4 additions & 0 deletions controllers/autoscaler/autoscaler_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func createAutoscaler(client client.Client,
// Set HPA reconciler even though AutoscalerClass is None to delete existing hpa
as.HPA = hpa.NewHPAReconciler(client, scheme, runtimeMeta, mmDeploymentName, mmNamespace)
return as, nil
case constants.AutoscalerClassExternal:
// Set HPA reconciler even though AutoscalerClass is External to delete existing hpa
as.HPA = hpa.NewHPAReconciler(client, scheme, runtimeMeta, mmDeploymentName, mmNamespace)
return as, nil
default:
return nil, errors.New("unknown autoscaler class type.")
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/modelmesh/modelmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Deployment struct {
PullerImage string
PullerImageCommand []string
PullerResources *corev1.ResourceRequirements
Replicas uint16
Replicas int32
Port uint16
TLSSecretName string
TLSClientAuth string
Expand Down
12 changes: 9 additions & 3 deletions controllers/servingruntime_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

kserveapi "github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
"github.com/kserve/kserve/pkg/apis/serving/v1beta1"
"github.com/kserve/kserve/pkg/constants"
api "github.com/kserve/modelmesh-serving/apis/serving/v1alpha1"
"github.com/kserve/modelmesh-serving/controllers/autoscaler"
"github.com/kserve/modelmesh-serving/controllers/modelmesh"
Expand Down Expand Up @@ -291,7 +292,12 @@ func (r *ServingRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Reque

//ScaleToZero or None autoscaler case
if replicas == uint16(0) || as.Autoscaler.AutoscalerClass == autoscaler.AutoscalerClassNone {
mmDeployment.Replicas = replicas
mmDeployment.Replicas = int32(replicas)
if _, err = as.Reconcile(true); err != nil {
return ctrl.Result{}, fmt.Errorf("HPA reconcile error: %w", err)
}
} else if as.Autoscaler.AutoscalerClass == constants.AutoscalerClassExternal {
mmDeployment.Replicas = -1
if _, err = as.Reconcile(true); err != nil {
return ctrl.Result{}, fmt.Errorf("HPA reconcile error: %w", err)
}
Expand All @@ -309,9 +315,9 @@ func (r *ServingRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, fmt.Errorf("Could not get the deployment for the servingruntime : %w", err)
}
if *existingDeployment.Spec.Replicas == int32(0) {
mmDeployment.Replicas = uint16(*(as.Autoscaler.HPA.HPA).Spec.MinReplicas)
mmDeployment.Replicas = *(as.Autoscaler.HPA.HPA).Spec.MinReplicas
} else {
mmDeployment.Replicas = uint16(*(existingDeployment.Spec.Replicas))
mmDeployment.Replicas = *(existingDeployment.Spec.Replicas)
}
}

Expand Down