remove apps/v1beta2 defaulting codes for obj.Spec.Selector and obj.Labels#50164
Conversation
There was a problem hiding this comment.
@kow3ns I spent some time thinking whether to set obj.Spec.Selector to nil or &metav1.LabelSelector{MatchLabels: map[string]string{}}. In the end, i chose nil for simplicity. As a result, the test to compare rs2.Spec.Selector.MatchLabels and rs2.Spec.Template.Labels became unnecessary and was removed.
There was a problem hiding this comment.
Do not default the selector to anything. We want to eliminate setting the Selector, or any field for that matter, based on another field of the same object. Doing so has caused us pain wrt apply and patch.
There was a problem hiding this comment.
Do not default the selector to anything.
Did you meanobj.Spec.Selectorshould benil?obj.Spec.Selectorwill benilwithout explicitly setting it.
kow3ns
left a comment
There was a problem hiding this comment.
Don't set the labels on the specification objects based on the PodTemplateSpecs.
There was a problem hiding this comment.
Delete this. You are setting the labels of the DaemonSet to the labels of the PodTemplateSpec. You do not want to do this.
There was a problem hiding this comment.
@kow3ns Noted! I will remove this. Same applies for other comments. :)
There was a problem hiding this comment.
Delete this. You are setting the labels of the StatefulSet to the labels of the PodTemplateSpec. You do not want to do this.
There was a problem hiding this comment.
Delete this. You are setting the labels of the Deployment to the labels of the PodTemplateSpec. You do not want to do this.
There was a problem hiding this comment.
Delete this. You are setting the labels of the ReplicaSet to the labels of the PodTemplateSpec. You do not want to do this.
There was a problem hiding this comment.
Do not default the selector to anything. We want to eliminate setting the Selector, or any field for that matter, based on another field of the same object. Doing so has caused us pain wrt apply and patch.
There was a problem hiding this comment.
@kow3ns The test case for statefulset did not have spec.selector, but similar test cases for deployments, daemonsets, and replicasets all have spec.selector. Hence, i modified the test case.
|
/lgtm |
|
/lgtm |
|
/approve |
|
We still ensure the pod spec has labels and the selector matches the labels in validation, right? |
|
Current validation for apps and extensions is still in place. We will issue a subsequent PR for validation changes (where necessary) in the apps and extensions groups. As none of the controllers handle selector mutation in a sane way, we intend to make selectors immutable for v1. We may lift this restriction at a future date when controllers can handle coordinated label updates and selector mutation. This PR for defaults has been done separately because it is isolated to the defaults in the v1beta2 group. |
|
/lgtm |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: crimsonfaith91, erictune, kow3ns Associated issue: 50339 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue |
Automatic merge from submit-queue remove apps/v1beta2 defaulting codes for obj.Spec.Selector and obj.Labels **What this PR does / why we need it**: This PR removes defaulting codes for `obj.Spec.Selector`. Currently, `obj.Spec.Selector.MatchLabels` is set to `obj.Spec.Template.Labels` if `obj.Spec.Template.Labels != nil && obj.Spec.Selector == nil`. We should not perform this defaulting operation as controllers selectors are immutable. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes kubernetes#50339 **Special notes for your reviewer**: This PR removes defaulting codes for `apps/v1beta2` only. The defaulting codes for validation will be removed in another PR. **Release note**: ```NONE ```
What this PR does / why we need it:
This PR removes defaulting codes for
obj.Spec.Selector. Currently,obj.Spec.Selector.MatchLabelsis set toobj.Spec.Template.Labelsifobj.Spec.Template.Labels != nil && obj.Spec.Selector == nil. We should not perform this defaulting operation as controllers selectors are immutable.Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close that issue when PR gets merged): fixes #50339Special notes for your reviewer:
This PR removes defaulting codes for
apps/v1beta2only. The defaulting codes for validation will be removed in another PR.Release note: