-
Notifications
You must be signed in to change notification settings - Fork 40.7k
Fix: Clarify optional podSelector in NetworkPolicy docs and schema #131354
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
base: master
Are you sure you want to change the base?
Conversation
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Thu Apr 17 13:31:58 UTC 2025. |
Hi @tomoish. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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-sigs/prow repository. |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
/remove-sig api-machinery |
// This field is optional. If it is not specified, it defaults to an empty selector, | ||
// which matches all pods in this namespace. | ||
// An explicitly specified empty selector also matches all pods. | ||
// +optional |
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.
Hm. I don't like talking about the default and then going back to add more detail about the non-default case.
Also, the existing text turns out to have another bug; it shouldn't say "ingress rules" since this applies to egress as well.
So how about
// podSelector selects the pods to which this NetworkPolicy object applies.
// The array of rules is applied to any pods selected by this field. An empty
// selector matches all pods in the policy's namespace.
// Multiple network policies can select the same set of pods. In this case,
// the ingress rules for each are combined additively.
// This field is optional. If it is not specified, it defaults to an empty selector.
// +optional
and then the same in the other copy.
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.
@danwinship Thank you for the suggestion.
I agree that we shouldn’t repeat the default behavior twice.
I’ll fix it and remove the remaining mentions of “ingress rules.”
/ok-to-test |
377f3e7
to
b0a5c77
Compare
/remove-sig api-machinery |
/lgtm |
LGTM label has been added. Git tree hash: 721c3dd1ead961b7bf31b7c459d9ab6088623b6e
|
/assign @thockin |
PodSelector metav1.LabelSelector `json:"podSelector" protobuf:"bytes,1,opt,name=podSelector"` | ||
// This field is optional. If it is not specified, it defaults to an empty selector. | ||
// +optional | ||
PodSelector metav1.LabelSelector `json:"podSelector,omitempty" protobuf:"bytes,1,opt,name=podSelector"` |
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.
don't add omitempty
, which has serialization implications, just add the +optional
bit
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.
@liggitt Thank you for your review. I've fixed it.
Clarify that podSelector is optional and defaults to an empty selector, matching all pods. Replace “ingress rules” with “rules” to reflect both directions. Update podSelector descriptions in NetworkPolicy documentation for clarity
b0a5c77
to
7a95f3e
Compare
New changes are detected. LGTM label has been removed. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: danwinship, tomoish The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Updates references and descriptions to reflect that
podSelector
inNetworkPolicy
objects can be omitted, defaulting to matching all pods in the namespace.What type of PR is this?
/kind bug
What this PR does / why we need it:
What this PR does
This PR addresses the documentation and schema inconsistencies regarding the
podSelector
field in KubernetesNetworkPolicy
objects.This change updates the documentation, OpenAPI specifications, Go structs, and generated Protobuf files to accurately reflect that
podSelector
is optional. When omitted, it defaults to an empty selector, which matches all pods within the policy's namespace.Why we need it.
Previous documentation and comments were misleading: they implied
podSelector
was required and only governed ingress behavior. This update aligns all docs, schemas, and code comments with the actual behavior—makingpodSelector
optional and applicable to both ingress and egress.Which issue(s) this PR fixes:
Fixes #130896
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: