Skip to content
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
17 changes: 17 additions & 0 deletions pkg/webhook/playground_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package webhook

import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation"
Expand Down Expand Up @@ -122,5 +123,21 @@ func (w *PlaygroundWebhook) generateValidate(obj runtime.Object) field.ErrorList
allErrs = append(allErrs, field.Forbidden(specPath.Child("modelClaims", "models"), "only one main model is allowed"))
}
}

if playground.Spec.BackendRuntimeConfig != nil && playground.Spec.BackendRuntimeConfig.Resources != nil {
requirements := playground.Spec.BackendRuntimeConfig.Resources
for resourceName, limit := range requirements.Limits {
request, ok := requirements.Requests[resourceName]
if !ok {
continue
}

if limit.Cmp(request) == -1 {
allErrs = append(allErrs, field.Forbidden(specPath.Child("backendRuntimeConfig", "resources"),
fmt.Sprintf("limit (%v) for %s must be greater than or equal to request (%v)", limit, resourceName, request)))
}
}
}

return allErrs
}
12 changes: 12 additions & 0 deletions test/integration/webhook/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ var _ = ginkgo.Describe("Playground default and validation", func() {
},
failed: true,
}),
ginkgo.Entry("invalid BackendRuntime resources", &testValidatingCase{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add another example to cover the scenario: resources in limits but not in requests to make sure there's no panic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

playground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).Replicas(1).ModelClaim("llama3-8b").BackendRuntimeRequest("cpu", "10").BackendRuntimeLimit("cpu", "5").Obj()
},
failed: true,
}),
ginkgo.Entry("valid BackendRuntime resources with limit but without request", &testValidatingCase{
playground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).Replicas(1).ModelClaim("llama3-8b").BackendRuntimeLimit("cpu", "5").Obj()
},
failed: false,
}),
ginkgo.Entry("no model claim declared", &testValidatingCase{
playground: func() *inferenceapi.Playground {
return wrapper.MakePlayground("playground", ns.Name).Replicas(1).Obj()
Expand Down
Loading