-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
feature(pkg/api): warning for Pod with null labelSelector in PodAffinity and TopologySpread #117025
feature(pkg/api): warning for Pod with null labelSelector in PodAffinity and TopologySpread #117025
Conversation
…ity and TopologySpread
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 Mar 30 22:31:05 UTC 2023. |
/sig scheduling |
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
/release-note-edit
|
/release-note-edit
|
pkg/api/pod/warnings.go
Outdated
|
||
// warn if labelSelector is empty which is no-match. | ||
if t.LabelSelector == nil { | ||
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Child("spec", "topologySpreadConstraints").Index(i).Child("labelSelector"))) |
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.
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Child("spec", "topologySpreadConstraints").Index(i).Child("labelSelector"))) | |
warnings = append(warnings, fmt.Sprintf("%s: a null labelSelector results in matching no pod", fieldPath.Child("spec", "topologySpreadConstraints").Index(i).Child("labelSelector"))) |
pkg/api/pod/warnings.go
Outdated
var warnings []string | ||
for i, t := range terms { | ||
if t.LabelSelector == nil { | ||
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Index(i).Child("labelSelector"))) |
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.
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Index(i).Child("labelSelector"))) | |
warnings = append(warnings, fmt.Sprintf("%s: a null labelSelector results in matching no pod", fieldPath.Index(i).Child("labelSelector"))) |
pkg/api/pod/warnings.go
Outdated
for i, t := range terms { | ||
// warn if labelSelector is empty which is no-match. | ||
if t.PodAffinityTerm.LabelSelector == nil { | ||
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Index(i).Child("podAffinityTerm", "labelSelector"))) |
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.
same recommendation
pkg/api/pod/warnings_test.go
Outdated
@@ -502,6 +520,85 @@ func TestWarnings(t *testing.T) { | |||
`spec.terminationGracePeriodSeconds: must be >= 0; negative values are invalid and will be treated as 1`, | |||
}, | |||
}, | |||
{ | |||
name: "empty LabelSelector in topologySpreadConstraints", |
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.
name: "empty LabelSelector in topologySpreadConstraints", | |
name: "null LabelSelector in topologySpreadConstraints", |
/approve |
@alculquicondor Thanks. I've fixed it as you suggested. |
/lgtm |
LGTM label has been added. Git tree hash: 3dea8fd9b790026f9a052c4b429c897d83428ba5
|
/lgtm API changes lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alculquicondor, msau42, sanposhiho The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
warning for Pod with null labelSelector in PodAffinity and TopologySpread.
The null lebalSelector means no-match. So, it doesn't make sense to use null labelSelector in PodAffinity or TopologySpread.
Which issue(s) this PR fixes:
Fixes #115873
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: