Skip to content

Refactor role validation logic, remove redundant for loop steps#880

Closed
nalan2012 wants to merge 1 commit intovolcano-sh:mainfrom
nalan2012:nalan2012-patch-5
Closed

Refactor role validation logic, remove redundant for loop steps#880
nalan2012 wants to merge 1 commit intovolcano-sh:mainfrom
nalan2012:nalan2012-patch-5

Conversation

@nalan2012
Copy link
Copy Markdown
Contributor

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Copilot AI review requested due to automatic review settings April 12, 2026 14:00
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lizhencheng9527 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the validateGangPolicy function to use a map for role lookups, which improves efficiency by eliminating a nested loop. However, a critical compilation error was introduced where the code attempts to access an undefined variable roleMap instead of the correctly initialized roleNames map.

for roleName, minReplicas := range minRoleReplicas {
// Check if the role exists
if !roleNames[roleName] {
role, ok := roleMap[roleName]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The variable roleMap is undefined in this scope. It should be roleNames to match the map initialized on line 212. This will cause a compilation error.

Suggested change
role, ok := roleMap[roleName]
role, ok := roleNames[roleName]

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors gangPolicy role validation to avoid repeatedly scanning roles when validating minRoleReplicas.

Changes:

  • Build a map of roles keyed by role name for O(1) lookup.
  • Remove the per-minRoleReplicas inner loop and directly compute replicas from the looked-up role.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +212 to 215
roleNames := make(map[string]workloadv1alpha1.Role)
for _, roleElement := range ms.Spec.Template.Roles {
roleNames[roleElement.Name] = roleElement
}
for roleName, minReplicas := range minRoleReplicas {
// Check if the role exists
if !roleNames[roleName] {
role, ok := roleMap[roleName]
roleNames := make(map[string]bool)
for _, role := range ms.Spec.Template.Roles {
roleNames[role.Name] = true
roleNames := make(map[string]workloadv1alpha1.Role)
@nalan2012 nalan2012 closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants