-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Ensure Deployment labels adopted ReplicaSets and pods #21030
Ensure Deployment labels adopted ReplicaSets and pods #21030
Conversation
Labelling this PR as size/L |
GCE e2e test build/test passed for commit 00d2a46e858927e0cad4670872a082ca0f51a213. |
@@ -93,3 +106,30 @@ func CloneSelectorAndAddLabel(selector *unversioned.LabelSelector, labelKey stri | |||
|
|||
return newSelector | |||
} | |||
|
|||
// AddLabelToSelector returns a selector with the given key and value added to the given selector's MatchLabels. | |||
func AddLabelToSelector(selector *unversioned.LabelSelector, labelKey string, labelValue uint32) *unversioned.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.
In general, label values are strings, so this function should probably take a string labelValue.
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.
Fixed
00d2a46
to
449f81b
Compare
It's ready for review now. PTAL @bgrant0607 @Kargakis Addressed comments. Added e2e tests. I also add pod-template-hash to rs's labels (the first commit only added to rs's selector and template label). |
GCE e2e test build/test passed for commit 449f81b764785120960e213b9b4edf6d8cab8d96. |
return nil, err | ||
} | ||
for _, pod := range podList.Items { | ||
pod.Labels = labelsutil.AddLabel(pod.Labels, extensions.DefaultDeploymentUniqueLabelKey, hash) |
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.
Should we check if the pod already has the label? It may happen that we start labeling some pods and then fail. I think we wouldn't want to relabel those pods.
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.
Fixed
@bgrant0607 I am worried that we are running the pod relabeling as part of an utility for deployments instead of in the rs controller loop. Can't we look up the pod-template-hash label in the rs controller and trigger the relabeling there? |
@@ -25,9 +25,11 @@ import ( | |||
"k8s.io/kubernetes/pkg/api/unversioned" | |||
"k8s.io/kubernetes/pkg/apis/extensions" | |||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" | |||
extensions_unversioned "k8s.io/kubernetes/pkg/client/typed/generated/extensions/unversioned" |
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.
IIRC, we should not use under_scores in imported package names. see #15319
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.
@mqliang noted. cc @caesarxuchao
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.
Thanks. I'll revise the other occurrences.
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.
Fixed in #21325
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.
Fixed
@Kargakis Regarding doing the pod relabeling in the RS controller: My immediate motivation for relabeling is so that adopted ReplicaSets don't overlap with ones created by a Deployment due to lack of the unique label. An alternative would be to implement That said, I think we'll want to propagate pod template label updates in the future. This is just one example of an in-place update: #9043. In-place updates make sense for cases where we want to minimize disruption. Even label updates can disrupt containers, in the case that they are visible to the containers via the downward API. In the future we may need to roll out such changes progressively, as we do for the regular rollout process. I don't want ReplicaSet to need progressive rollout logic, as well. That logic should live in Deployment. If we think this is too tricky/risky, we could wait until the next release. With pause, adoption shouldn't be needed as often. We would need to document the problem this was trying to solve as a known issue with the beta implementation. |
I just wrote up a |
PR needs rebase |
4c361d3
to
4b4609f
Compare
@bgrant0607 @Kargakis PTAL |
GCE e2e test build/test passed for commit 4c361d326014720f86153d9e38041ef64a38333b. |
GCE e2e test build/test passed for commit 4b4609f55781b4c863b18e59febf276a15dfb1a9. |
|
} | ||
} | ||
// Make sure rs pod template is updated so that it won't create pods without the new label (orphaned pods). | ||
if updatedRS.Generation != updatedRS.Status.ObservedGeneration { |
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.
Should be >.
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.
Fixed
A couple minor comments and a test failure, but otherwise looks pretty good. Thanks. |
return updatedRS, nil | ||
} | ||
|
||
func waitForReplicaSetUpdated(c clientset.Interface, desiredGeneration int64, namespace, name string) error { |
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.
Move this to pkg/client/conditions.go
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 you mean pkg/client/unversioned/conditions.go
? We use the generated client instead of the unversioned one in this function, so this function should not be there. cc @caesarxuchao
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.
Yes, sorry. How about creating pkg/client/clientset_generated/internalclientset/conditions.go
then?
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.
No, because code in pkg/client/clientset_generated
should be auto-generated. How about making a standalone condition
package at pkg/client/conditions/conditions.go
?
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.
Let's figure out the best place in another PR.
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.
ok
4b4609f
to
4699a6d
Compare
GCE e2e test build/test passed for commit 4699a6d. |
@bgrant0607 @Kargakis Addressed comments and fixed the unit test failure; PTAL |
LGTM |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
GCE e2e test build/test passed for commit 4699a6d. |
Automatic merge from submit-queue |
Auto commit by PR queue bot
Ensure Deployment labels adopted ReplicaSets and pods. Otherwise, new RCs produced by Deployment will overlap we pre-existing ones that aren't constrained by the pod-template-hash.
Fixes #20755
Ignore the first commit (from #20994)
cc @bgrant0607 @nikhiljindal @ironcladlou @Kargakis @kubernetes/sig-config @madhusudancs @mqliang