-
Couldn't load subscription status.
- Fork 259
Fix CNS IP demand overcounting by filtering terminal Pods in IPAMv2 #3697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: rejain456 <155685406+rejain456@users.noreply.github.com>
| @copilot, please fix the issue you noted for line: "for _, pod := range pods {" with the comment: "rangeValCopy: each iteration copies 1112 bytes (consider pointers or indexing) (gocritic)" |
Co-authored-by: rejain456 <155685406+rejain456@users.noreply.github.com>
Fixed the gocritic rangeValCopy issue by changing the loop from Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
| Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…ndexer Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
| Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| /azp run Azure Container Networking PR |
| Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances IP demand calculation by excluding terminal Pods and updates the reconciler to index Pod phases.
- Adds a new
status.phaseindexer in the Pod reconciler - Modifies
PodIPDemandListenerto filter outSucceeded/FailedPods - Introduces unit tests covering active vs. terminal Pod scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cns/kubecontroller/pod/reconciler.go | Renamed notifier comment and added status.phase indexer |
| cns/ipampool/v2/adapter.go | Updated PodIPDemandListener to count only non-terminal Pods |
| cns/ipampool/v2/adapter_test.go | Added tests verifying exclusion of terminal Pods from demand counts |
Comments suppressed due to low confidence (4)
cns/ipampool/v2/adapter.go:32
- Add or update the function comment to describe that this listener now filters out terminal pod phases (Succeeded/Failed) before sending the count.
func PodIPDemandListener(ch chan<- int) func([]v1.Pod) { cns/ipampool/v2/adapter.go:37
- [nitpick] Consider replacing the index variable
iwith a more descriptive name (e.g.,idx) or usefor _, pod := range podsfor clarity.
for i := range pods { cns/ipampool/v2/adapter_test.go:32
- [nitpick] The test name includes a pending pod; consider renaming to something like
multiple active podsto better reflect the scenario.
name: "multiple running pods", There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting is failing on the changed files and needs to be fixed:
cns/ipampool/v2/adapter.go:45: File is not `gci`-ed with --skip-generated -s standard -s default (gci) cns/ipampool/v2/adapter_test.go:101: File is not `gci`-ed with --skip-generated -s standard -s default (gci) cns/kubecontroller/pod/reconciler.go:83: File is not `gci`-ed with --skip-generated -s standard -s default (gci) cns/ipampool/v2/adapter.go:46: File is not `gofumpt`-ed (gofumpt) cns/ipampool/v2/adapter_test.go:102: File is not `gofumpt`-ed (gofumpt) bump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting is failing on the changed files and needs to be fixed:
cns/ipampool/v2/adapter.go:45: File is not `gci`-ed with --skip-generated -s standard -s default (gci) cns/ipampool/v2/adapter_test.go:101: File is not `gci`-ed with --skip-generated -s standard -s default (gci) cns/kubecontroller/pod/reconciler.go:83: File is not `gci`-ed with --skip-generated -s standard -s default (gci) cns/ipampool/v2/adapter.go:46: File is not `gofumpt`-ed (gofumpt) cns/ipampool/v2/adapter_test.go:102: File is not `gofumpt`-ed (gofumpt) | @copilot address my previous comment on linting |
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
| /azp run Azure Container Networking PR |
| Azure Pipelines successfully started running 1 pipeline(s). |
…3697) * Initial plan for issue * Fix CNS IP demand overcounting by filtering terminal Pods in IPAMv2 Co-authored-by: rejain456 <155685406+rejain456@users.noreply.github.com> * Fix gocritic rangeValCopy performance issue in PodIPDemandListener Co-authored-by: rejain456 <155685406+rejain456@users.noreply.github.com> * Implement server-side Pod filtering with indexer for status.phase Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com> * Revert to client-side filtering strategy while keeping status.phase indexer Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com> * Fix linting issues: remove trailing blank lines in modified files Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rejain456 <155685406+rejain456@users.noreply.github.com> Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
When configured for IPAMv2, CNS watches Pods to calculate IP demand for dynamic Podsubnet scenarios. However, CNS was overcounting the IP demand by including Pods in terminal states (Succeeded/Failed), even though these Pods no longer have network sandboxes and their IPs have been released.
Problem
The
PodIPDemandListenerfunction incns/ipampool/v2/adapter.gowas counting all Pods that matched the filter criteria (hostNetwork: false), including terminal Pods. This caused:Solution
Modified
PodIPDemandListenerto filter out Pods in terminal phases (PodSucceededandPodFailed) when calculating IP demand. According to the Kubernetes Pod lifecycle documentation, these terminal phases are non-retriable and indicate the Pod is dead.Changes
cns/ipampool/v2/adapter.go: UpdatedPodIPDemandListenerto exclude terminal Pods from demand countcns/ipampool/v2/adapter_test.go: Comprehensive unit tests covering various Pod phase scenariosTesting
Added unit tests that verify:
Compatibility
This change is compatible with SwiftV2 multitenancy scenarios, as terminal Pods should not contribute to IP demand regardless of their tenancy configuration.
Fixes #3696.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
http://168.63.129.16:80/machine//usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.