fix: ignore apps.kubernetes.io/pod-index when generating network policies - #396
Merged
matthyx merged 1 commit intoSep 7, 2026
Merged
Conversation
…cies Sanitize legacy ContainerProfile neighbors that still carry per-replica StatefulSet labels so GenerateNetworkPolicy collapses them into a single workload-level peer rule valid after scale-up. Related: kubescape/node-agent#942 Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
matthyx
approved these changes
Sep 7, 2026
matthyx
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the generation-time compatibility fix. Ignoring apps.kubernetes.io/pod-index alongside statefulset.kubernetes.io/pod-name correctly collapses legacy per-replica selectors, and the ingress/egress regression coverage exercises the intended behavior. I found no blockers. Verified with go test ./... -count=1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sanitize legacy
ContainerProfileneighbors that still carry per-replica StatefulSet labels soGenerateNetworkPolicycollapses them into a single workload-level peer rule that remains valid after scale-up.Related: kubescape/node-agent#942
Overview
Current behavior:
IsIgnoredLabelalready stripsstatefulset.kubernetes.io/pod-name, but notapps.kubernetes.io/pod-index. Legacy learned neighbors that differ only by per-replica identity labels therefore become one GeneratedNetworkPolicy peer rule per StatefulSet replica, so scaling up denies traffic to new pods.Future behavior:
apps.kubernetes.io/pod-indexis ignored inremoveLabels()(viaIsIgnoredLabel). Three otherwise-identical neighbors (replicas0/1/2) collapse into one ingress peer and one egress peer with only workload labels (e.g.app.kubernetes.io/name=db).This is the generation-time / backward-compatibility half of the fix. New profiles should stop learning replica-specific selectors in the companion
kubescape/node-agentchange.How to Test
Expected:
TestRemoveLabelsstrips bothapps.kubernetes.io/pod-indexandstatefulset.kubernetes.io/pod-nameTestGenerateNetworkPolicy_StatefulSetPeerCollapsesReplicasingress and egress subtests each assertlen(rules)==1, one peer, selector{"app.kubernetes.io/name":"db"}, no identity labelsRelated issues/PRs
kubescape/node-agentPR — strip StatefulSet pod-identity labels from network peer selectors (link after opening)Checklist before requesting a review
go test ./...not re-run in this environment)