Skip to content
Closed
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
6 changes: 6 additions & 0 deletions pkg/kthena-router/webhook/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ func (v *KthenaRouterValidator) validateModelRoute(modelRoute *networkingv1alpha
if len(rule.TargetModels) == 0 {
allErrs = append(allErrs, field.Required(ruleField.Child("targetModels"), "each rule must have at least one target model"))
}
for j, target := range rule.TargetModels {
targetField := ruleField.Child("targetModels").Index(j)
if target != nil && target.ModelServerName == "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ptal // +kubebuilder:validation:required, so this is not needed

allErrs = append(allErrs, field.Required(targetField.Child("modelServerName"), "modelServerName must be specified"))
}
}
Comment on lines +183 to +188
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The validating webhook should also enforce consistency in the weight field across all targetModels in a rule. Currently, the datastore runtime (in toWeightedSlice) rejects rules where some targets have weights and others don't, but the webhook allows them. This leads to valid-looking objects being ignored at runtime, which is difficult to debug. Please add a check to ensure that either all targetModels have a weight specified or none of them do.

}

if len(allErrs) > 0 {
Expand Down
26 changes: 26 additions & 0 deletions pkg/kthena-router/webhook/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,32 @@ func TestValidateModelRoute(t *testing.T) {
expectValid: false,
expectedReason: "validation failed: - spec.rules[1].targetModels: Required value: each rule must have at least one target model",
},
{
name: "invalid model route - empty target model server name",
modelRoute: &networkingv1alpha1.ModelRoute{
TypeMeta: metav1.TypeMeta{
APIVersion: "networking.serving.volcano.sh/v1alpha1",
Kind: "ModelRoute",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-route",
Namespace: "default",
},
Spec: networkingv1alpha1.ModelRouteSpec{
ModelName: "test-model",
Rules: []*networkingv1alpha1.Rule{
{
Name: "empty-target-name-rule",
TargetModels: []*networkingv1alpha1.TargetModel{
{ModelServerName: ""},
},
},
},
},
},
expectValid: false,
expectedReason: "validation failed: - spec.rules[0].targetModels[0].modelServerName: Required value: modelServerName must be specified",
},
{
name: "invalid model route - nil rule",
modelRoute: &networkingv1alpha1.ModelRoute{
Expand Down
Loading