Skip to content

Commit c5d97f8

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

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-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) < 0 {
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
}

0 commit comments

Comments
 (0)