Skip to content

Commit fd77f80

Browse files
authored
feat: make elasticConfig.maxReplicas to a required parameter (#331)
1 parent 79d833c commit fd77f80

File tree

6 files changed

+11
-16
lines changed

6 files changed

+11
-16
lines changed

api/inference/v1alpha1/playground_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type PlaygroundSpec struct {
4444
BackendRuntimeConfig *BackendRuntimeConfig `json:"backendRuntimeConfig,omitempty"`
4545
// ElasticConfig defines the configuration for elastic usage,
4646
// e.g. the max/min replicas.
47+
// +optional
4748
ElasticConfig *ElasticConfig `json:"elasticConfig,omitempty"`
4849
}
4950

@@ -56,8 +57,9 @@ type ElasticConfig struct {
5657
MinReplicas *int32 `json:"minReplicas,omitempty"`
5758
// MaxReplicas indicates the maximum number of inference workloads based on the traffic.
5859
// Default to nil means there's no limit for the instance number.
59-
// +optional
60-
MaxReplicas *int32 `json:"maxReplicas,omitempty"`
60+
// +kubebuilder:validation:Required
61+
// +kubebuilder:validation:Minimum:=1
62+
MaxReplicas int32 `json:"maxReplicas,omitempty"`
6163
// ScaleTrigger defines the rules to scale the workloads.
6264
// Only one trigger cloud work at a time, mostly used in Playground.
6365
// ScaleTrigger defined here will "overwrite" the scaleTrigger in the recommendedConfig.

api/inference/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/inference.llmaz.io_playgrounds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ spec:
242242
MaxReplicas indicates the maximum number of inference workloads based on the traffic.
243243
Default to nil means there's no limit for the instance number.
244244
format: int32
245+
minimum: 1
245246
type: integer
246247
minReplicas:
247248
default: 1
@@ -864,6 +865,8 @@ spec:
864865
type: array
865866
type: object
866867
type: object
868+
required:
869+
- maxReplicas
867870
type: object
868871
modelClaim:
869872
description: |-

pkg/controller/inference/playground_controller.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,7 @@ func newHPA(playground *inferenceapi.Playground) *autoscalingv2.HorizontalPodAut
557557
}
558558

559559
hpa.Spec.MinReplicas = playground.Spec.ElasticConfig.MinReplicas
560-
if playground.Spec.ElasticConfig.MaxReplicas == nil {
561-
// The value is hardcoded, because maxReplicas is required by HPA.
562-
hpa.Spec.MaxReplicas = 99999
563-
} else {
564-
hpa.Spec.MaxReplicas = *playground.Spec.ElasticConfig.MaxReplicas
565-
}
560+
hpa.Spec.MaxReplicas = playground.Spec.ElasticConfig.MaxReplicas
566561

567562
return hpa
568563
}

pkg/webhook/playground_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func (w *PlaygroundWebhook) generateValidate(obj runtime.Object) field.ErrorList
145145
allErrs = append(allErrs, field.Forbidden(specPath.Child("elasticConfig.minReplicas"), "minReplicas couldn't be 0"))
146146
}
147147

148-
if playground.Spec.ElasticConfig.MinReplicas != nil && playground.Spec.ElasticConfig.MaxReplicas != nil {
149-
if *playground.Spec.ElasticConfig.MinReplicas >= *playground.Spec.ElasticConfig.MaxReplicas {
148+
if playground.Spec.ElasticConfig.MinReplicas != nil {
149+
if *playground.Spec.ElasticConfig.MinReplicas >= playground.Spec.ElasticConfig.MaxReplicas {
150150
allErrs = append(allErrs, field.Invalid(specPath.Child("elasticConfig.scaleTrigger.hpa"), *playground.Spec.ElasticConfig.MinReplicas, "minReplicas must be less than maxReplicas"))
151151
}
152152
}

test/util/wrapper/playground.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (w *PlaygroundWrapper) ElasticConfig(minReplicas, maxReplicas int32) *Playg
160160
if w.Spec.ElasticConfig == nil {
161161
w.Spec.ElasticConfig = &inferenceapi.ElasticConfig{}
162162
}
163-
w.Spec.ElasticConfig.MaxReplicas = ptr.To[int32](maxReplicas)
163+
w.Spec.ElasticConfig.MaxReplicas = maxReplicas
164164
w.Spec.ElasticConfig.MinReplicas = ptr.To[int32](minReplicas)
165165
return w
166166
}

0 commit comments

Comments
 (0)