Skip to content

Commit e45b4f2

Browse files
committed
feature(webhook): add BackendRuntimeConfig resources validation
1 parent 39923ee commit e45b4f2

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/webhook/playground_webhook.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package webhook
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
"k8s.io/apimachinery/pkg/runtime"
2324
"k8s.io/apimachinery/pkg/util/validation"
@@ -122,5 +123,21 @@ func (w *PlaygroundWebhook) generateValidate(obj runtime.Object) field.ErrorList
122123
allErrs = append(allErrs, field.Forbidden(specPath.Child("modelClaims", "models"), "only one main model is allowed"))
123124
}
124125
}
126+
127+
if playground.Spec.BackendRuntimeConfig != nil && playground.Spec.BackendRuntimeConfig.Resources != nil {
128+
requirements := playground.Spec.BackendRuntimeConfig.Resources
129+
for resourceName, limit := range requirements.Limits {
130+
request, ok := requirements.Requests[resourceName]
131+
if !ok {
132+
continue
133+
}
134+
135+
if limit.Cmp(request) == -1 {
136+
allErrs = append(allErrs, field.Forbidden(specPath.Child("backendRuntimeConfig", "resources"),
137+
fmt.Sprintf("limit (%v) for %s must be greater than or equal to request (%v)", limit, resourceName, request)))
138+
}
139+
}
140+
}
141+
125142
return allErrs
126143
}

test/integration/webhook/playground_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ var _ = ginkgo.Describe("Playground default and validation", func() {
6969
},
7070
failed: true,
7171
}),
72+
ginkgo.Entry("invalid BackendRuntime resources", &testValidatingCase{
73+
playground: func() *inferenceapi.Playground {
74+
return wrapper.MakePlayground("playground", ns.Name).Replicas(1).ModelClaim("llama3-8b").BackendRuntimeRequest("cpu", "10").BackendRuntimeLimit("cpu", "5").Obj()
75+
},
76+
failed: true,
77+
}),
78+
ginkgo.Entry("valid BackendRuntime resources with limit but without request", &testValidatingCase{
79+
playground: func() *inferenceapi.Playground {
80+
return wrapper.MakePlayground("playground", ns.Name).Replicas(1).ModelClaim("llama3-8b").BackendRuntimeLimit("cpu", "5").Obj()
81+
},
82+
failed: false,
83+
}),
7284
ginkgo.Entry("no model claim declared", &testValidatingCase{
7385
playground: func() *inferenceapi.Playground {
7486
return wrapper.MakePlayground("playground", ns.Name).Replicas(1).Obj()

0 commit comments

Comments
 (0)