Skip to content
Open
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
56 changes: 26 additions & 30 deletions pkg/model-serving-controller/webhook/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ func validateGangPolicy(ms *workloadv1alpha1.ModelServing) field.ErrorList {
minRoleReplicasPath := field.NewPath("spec").Child("template").Child("gangPolicy").Child("minRoleReplicas")

// Create a map of role names for quick lookup
roleNames := make(map[string]bool)
roleMap := make(map[string]workloadv1alpha1.Role)
for _, role := range ms.Spec.Template.Roles {
roleNames[role.Name] = true
roleMap[role.Name] = role
}

// Validate each minRoleReplicas entry
for roleName, minReplicas := range minRoleReplicas {
// Check if the role exists
if !roleNames[roleName] {
roleElement, ok := roleMap[roleName]
if !ok {
allErrs = append(allErrs, field.Invalid(
minRoleReplicasPath.Key(roleName),
roleName,
Expand All @@ -226,35 +227,30 @@ func validateGangPolicy(ms *workloadv1alpha1.ModelServing) field.ErrorList {
continue
}

// Find the role to check its actual replicas
for _, role := range ms.Spec.Template.Roles {
if role.Name == roleName {
/// Calculate total replicas for this role
// minRoleReplicas is compared against the number of Role replicas
replicas := int32(1)
if role.Replicas != nil {
replicas = *role.Replicas
}
// Find the role in the roleMap then check its actual replicas
/// Calculate total replicas for this role
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

Go convention uses // for comments; /// is non-idiomatic and can be confusing in Go codebases. Replace with a single // (and consider folding it into the existing comment on the next line to avoid redundancy).

Suggested change
/// Calculate total replicas for this role
// Calculate total replicas for this role

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

The triple-slash comment marker (///) is inconsistent with typical Go commenting style and reads like an accidental duplication. Please replace with a normal // comment (or remove if redundant) to keep comments consistent and avoid confusion.

Suggested change
/// Calculate total replicas for this role
// Calculate total replicas for this role

Copilot uses AI. Check for mistakes.
// minRoleReplicas is compared against the number of Role replicas
replicas := int32(1)
if roleElement.Replicas != nil {
replicas = *roleElement.Replicas
}

// Validate minReplicas doesn't exceed total replicas
if minReplicas > replicas {
allErrs = append(allErrs, field.Invalid(
minRoleReplicasPath.Key(roleName),
minReplicas,
fmt.Sprintf("minRoleReplicas (%d) for role %s cannot exceed replicas (%d)", minReplicas, roleName, replicas),
))
}
// Validate minReplicas doesn't exceed total replicas
if minReplicas > replicas {
allErrs = append(allErrs, field.Invalid(
minRoleReplicasPath.Key(roleName),
minReplicas,
fmt.Sprintf("minRoleReplicas (%d) for role %s cannot exceed replicas (%d)", minReplicas, roleName, replicas),
))
}

// Validate minReplicas is non-negative
if minReplicas < 0 {
allErrs = append(allErrs, field.Invalid(
minRoleReplicasPath.Key(roleName),
minReplicas,
fmt.Sprintf("minRoleReplicas for role %s must be non-negative", roleName),
))
}
break
}
// Validate minReplicas is non-negative
if minReplicas < 0 {
allErrs = append(allErrs, field.Invalid(
minRoleReplicasPath.Key(roleName),
minReplicas,
fmt.Sprintf("minRoleReplicas for role %s must be non-negative", roleName),
))
}
}

Expand Down
Loading