Skip to content

Commit

Permalink
allow external hpa
Browse files Browse the repository at this point in the history
Signed-off-by: Robin van Dijk <[email protected]>
  • Loading branch information
Robin committed Jul 16, 2024
1 parent f8cc7aa commit 2ea3c3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
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

0 comments on commit 2ea3c3c

Please sign in to comment.