-
Notifications
You must be signed in to change notification settings - Fork 40.4k
remove apps/v1beta2 defaulting codes for obj.Spec.Selector and obj.Labels #50164
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
@@ -416,13 +406,6 @@ func TestSetDefaultReplicaSet(t *testing.T) { | |||
t.Errorf("unexpected object: %v", rs2) | |||
t.FailNow() | |||
} | |||
if test.expectSelector != reflect.DeepEqual(rs2.Spec.Selector.MatchLabels, rs2.Spec.Template.Labels) { |
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not default the selector to anything.
Did you meanobj.Spec.Selector
should benil
?obj.Spec.Selector
will benil
without explicitly setting it.
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 set the labels on the specification objects based on the PodTemplateSpecs.
pkg/apis/apps/v1beta2/defaults.go
Outdated
if len(obj.Labels) == 0 { | ||
obj.Labels = labels | ||
} | ||
if labels != nil && len(obj.Labels) == 0 { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kow3ns Noted! I will remove this. Same applies for other comments. :)
pkg/apis/apps/v1beta2/defaults.go
Outdated
obj.Labels = labels | ||
} | ||
if labels != nil && len(obj.Labels) == 0 { | ||
obj.Labels = labels |
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.
Delete this. You are setting the labels of the StatefulSet to the labels of the PodTemplateSpec. You do not want to do this.
pkg/apis/apps/v1beta2/defaults.go
Outdated
if len(obj.Labels) == 0 { | ||
obj.Labels = labels | ||
} | ||
if labels != nil && len(obj.Labels) == 0 { |
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.
Delete this. You are setting the labels of the Deployment to the labels of the PodTemplateSpec. You do not want to do this.
pkg/apis/apps/v1beta2/defaults.go
Outdated
if len(obj.Labels) == 0 { | ||
obj.Labels = labels | ||
} | ||
if labels != nil && len(obj.Labels) == 0 { |
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.
Delete this. You are setting the labels of the ReplicaSet to the labels of the PodTemplateSpec. You do not want to do this.
@@ -416,13 +406,6 @@ func TestSetDefaultReplicaSet(t *testing.T) { | |||
t.Errorf("unexpected object: %v", rs2) | |||
t.FailNow() | |||
} | |||
if test.expectSelector != reflect.DeepEqual(rs2.Spec.Selector.MatchLabels, rs2.Spec.Template.Labels) { |
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.
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.
@@ -133,7 +133,7 @@ var etcdStorageData = map[schema.GroupVersionResource]struct { | |||
|
|||
// k8s.io/kubernetes/pkg/apis/apps/v1beta1 | |||
gvr("apps", "v1beta1", "statefulsets"): { | |||
stub: `{"metadata": {"name": "ss1"}, "spec": {"template": {"metadata": {"labels": {"a": "b"}}}}}`, | |||
stub: `{"metadata": {"name": "ss1"}, "spec": {"selector": {"matchLabels": {"a": "b"}}, "template": {"metadata": {"labels": {"a": "b"}}}}}`, |
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.
@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.
@@ -149,7 +149,7 @@ var etcdStorageData = map[schema.GroupVersionResource]struct { | |||
|
|||
// k8s.io/kubernetes/pkg/apis/apps/v1beta2 | |||
gvr("apps", "v1beta2", "statefulsets"): { | |||
stub: `{"metadata": {"name": "ss2"}, "spec": {"template": {"metadata": {"labels": {"a": "b"}}}}}`, | |||
stub: `{"metadata": {"name": "ss2"}, "spec": {"selector": {"matchLabels": {"a": "b"}}, "template": {"metadata": {"labels": {"a": "b"}}}}}`, |
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.
@kow3ns Same here.
/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.
Needs 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 |
What this PR does / why we need it:
This PR removes defaulting codes for
obj.Spec.Selector
. Currently,obj.Spec.Selector.MatchLabels
is set toobj.Spec.Template.Labels
ifobj.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/v1beta2
only. The defaulting codes for validation will be removed in another PR.Release note: