Skip to content

fix(webhook): count main models by role in playground validation - #522

Open
amalsaidov wants to merge 1 commit into
InftyAI:mainfrom
amalsaidov:fix/playground-main-model-count
Open

amalsaidov wants to merge 1 commit into
InftyAI:mainfrom
amalsaidov:fix/playground-main-model-count

Conversation

@amalsaidov

Copy link
Copy Markdown

What this PR does / why we need it

The Playground validating webhook is meant to reject a spec that declares
more than one main model (only one main model is allowed). However the
count was computed by comparing each model's name against the main
role constant:

if model.Name == coreapi.ModelName(coreapi.MainRole) {
    mainModelCount += 1
}

Since coreapi.MainRole is a role ("main"), this compared the model name
to the literal string "main", so mainModelCount stayed 0 for any
real-world model name and the mainModelCount > 1 guard never fired. A
Playground with several main-role models therefore passed admission.

This switches the check to inspect model.Role (treating a nil role as
main, consistent with the kubebuilder default), which matches the logic
already used in the Service webhook and the Playground defaulter.

Which issue(s) this PR fixes

Special notes for your reviewer

Added a unit test (pkg/webhook/playground_webhook_test.go) that fails
before this change and passes after it: one main model is accepted, two
main models are rejected with only one main model is allowed.

Does this PR introduce a user-facing change?

Fix Playground validation so that specifying more than one main model is correctly rejected.

The playground validation webhook counted main models by comparing the
model name against the "main" role constant instead of inspecting the
model role. As a result mainModelCount was effectively always zero and
the "only one main model is allowed" check never triggered, letting a
Playground with multiple main-role models pass admission.

Compare against model.Role (defaulting a nil role to main), matching the
logic already used by the Service webhook and the Playground defaulter.
Add a unit test covering the single-main and multiple-main cases.

Signed-off-by: Amal Saidhanov <amalsaidov@users.noreply.github.com>
@InftyAI-Agent InftyAI-Agent added needs-triage Indicates an issue or PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. do-not-merge/needs-kind Indicates a PR lacks a label and requires one. labels Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-kind Indicates a PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. needs-triage Indicates an issue or PR lacks a label and requires one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants