Skip to content

fix(webhook): preserve required affinity branch semantics#5757

Draft
hxrshxz wants to merge 4 commits intofluid-cloudnative:masterfrom
hxrshxz:test/requirenodewithfuse-node-selector-coverage
Draft

fix(webhook): preserve required affinity branch semantics#5757
hxrshxz wants to merge 4 commits intofluid-cloudnative:masterfrom
hxrshxz:test/requirenodewithfuse-node-selector-coverage

Conversation

@hxrshxz
Copy link
Copy Markdown
Contributor

@hxrshxz hxrshxz commented Apr 1, 2026

Ⅰ. Describe what this PR does

Fix shared webhook required-node-affinity merging so existing OR branches are preserved correctly while adding coverage for requirenodewithfuse and nodeaffinitywithcache.

Ⅱ. Does this pull request fix one issue?

#5676

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Add helper regression tests for cross-product node selector merging, empty-term handling, and MatchFields merging, plus plugin tests covering required-affinity branch preservation for requirenodewithfuse and nodeaffinitywithcache.

Ⅳ. Describe how to verify it

Run go test -count=1 ./pkg/utils -run TestInjectNodeSelectorTerms and go test -count=1 ./pkg/webhook/plugins/requirenodewithfuse ./pkg/webhook/plugins/nodeaffinitywithcache.

Ⅴ. Special notes for reviews

N/A

hxrshxz added 2 commits April 2, 2026 02:06
…ction branch

Signed-off-by: Harsh <harshmastic@gmail.com>
…s only into term[0]

Signed-off-by: Harsh <harshmastic@gmail.com>
Copilot AI review requested due to automatic review settings April 1, 2026 20:45
Copy link
Copy Markdown
Contributor

@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 adds unit tests for the RequireNodeWithFuse plugin to verify fuse node selector injection. A logical issue was identified: the implementation only appends the fuse requirement to the first NodeSelectorTerm. Because Kubernetes evaluates multiple terms using OR logic, pods could still be scheduled on nodes without the fuse if they match other terms. The reviewer suggests injecting the requirement into all existing terms to ensure strict enforcement.

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

Adds new Ginkgo/Gomega unit test coverage for the requirenodewithfuse mutating webhook plugin, focusing on node-affinity injection behavior used to require fuse-capable nodes for dataset-mounted pods.

Changes:

  • Add a spec validating fresh-pod injection of RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms based on runtimeInfo fuse selectors.
  • Add a spec documenting/verifying the current multi-term behavior where fuse match expressions are appended only to NodeSelectorTerms[0].

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

@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented Apr 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@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 adds unit tests for the RequireNodeWithFuse plugin to verify node selector injection, including a test case for pods with multiple pre-existing NodeSelectorTerms. A review comment identifies a correctness issue in the underlying logic: since NodeSelectorTerms are evaluated using a logical OR, appending the fuse requirement only to the first term fails to strictly enforce the constraint across all terms, which could allow pods to be scheduled on nodes lacking the required fuse.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.44%. Comparing base (bdc4ab0) to head (b7b4a61).
⚠️ Report is 29 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5757      +/-   ##
==========================================
+ Coverage   61.22%   61.44%   +0.21%     
==========================================
  Files         444      444              
  Lines       30557    30666     +109     
==========================================
+ Hits        18710    18842     +132     
+ Misses      10307    10278      -29     
- Partials     1540     1546       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


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

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented Apr 2, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@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 adds unit tests for the RequireNodeWithFuse plugin to verify node selector injection, including cases with multiple existing affinity terms. Feedback suggests refactoring repeated setup into a BeforeEach block, simplifying assertions using the ConsistOf matcher or direct struct comparison, and replacing magic strings with constants.

@hxrshxz hxrshxz marked this pull request as draft April 2, 2026 07:38
Signed-off-by: Harsh <harshmastic@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

@hxrshxz hxrshxz changed the title test(requirenodewithfuse): add Ginkgo/Gomega coverage for Mutate node-selector injection fix(webhook): preserve required affinity branch semantics Apr 2, 2026
@hxrshxz hxrshxz requested a review from Copilot April 2, 2026 10:36
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


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

Comment on lines +65 to +82
existingTerms := pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
combinedTerms := make([]corev1.NodeSelectorTerm, 0, len(existingTerms)*len(requiredSchedulingTerms))
for i := 0; i < len(existingTerms); i++ {
if len(existingTerms[i].MatchExpressions) == 0 && len(existingTerms[i].MatchFields) == 0 {
continue
}
for j := 0; j < len(requiredSchedulingTerms); j++ {
if len(requiredSchedulingTerms[j].MatchExpressions) == 0 && len(requiredSchedulingTerms[j].MatchFields) == 0 {
continue
}
combinedTerm := corev1.NodeSelectorTerm{
MatchExpressions: append(append([]corev1.NodeSelectorRequirement{}, existingTerms[i].MatchExpressions...), requiredSchedulingTerms[j].MatchExpressions...),
MatchFields: append(append([]corev1.NodeSelectorRequirement{}, existingTerms[i].MatchFields...), requiredSchedulingTerms[j].MatchFields...),
}
combinedTerms = append(combinedTerms, combinedTerm)
}
}
pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = combinedTerms
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

InjectNodeSelectorTerms can set RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms to an empty slice when all existing terms are empty (or all injected terms are empty and get skipped). This effectively wipes required node affinity and can make a pod unschedulable/invalid. Consider filtering out empty injected terms up front, and if no non-empty existing terms remain then fall back to setting NodeSelectorTerms to the (filtered) injected terms instead of overwriting with an empty combinedTerms (or treat empty existing term as a match-all branch and still combine).

Copilot uses AI. Check for mistakes.
@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Apr 3, 2026

[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 yangyuliufeng for approval by writing /assign @yangyuliufeng in a comment. 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

1 similar comment
@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Apr 3, 2026

[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 yangyuliufeng for approval by writing /assign @yangyuliufeng in a comment. 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

@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Apr 3, 2026

Hi @hxrshxz. Thanks for your PR.

I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants