mirror of https://github.com/k3s-io/k3s
Merge pull request #54073 from liggitt/node-default-label
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Do not remove kubelet labels during startup Fixes #54070 ```release-note kubelet: prevent removal of default labels from Node API objects on startup ```pull/6/head
commit
abb7789cd8
|
@ -169,6 +169,10 @@ func (kl *Kubelet) updateDefaultLabels(initialNode, existingNode *v1.Node) bool
|
||||||
var needsUpdate bool = false
|
var needsUpdate bool = false
|
||||||
//Set default labels but make sure to not set labels with empty values
|
//Set default labels but make sure to not set labels with empty values
|
||||||
for _, label := range defaultLabels {
|
for _, label := range defaultLabels {
|
||||||
|
if _, hasInitialValue := initialNode.Labels[label]; !hasInitialValue {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if existingNode.Labels[label] != initialNode.Labels[label] {
|
if existingNode.Labels[label] != initialNode.Labels[label] {
|
||||||
existingNode.Labels[label] = initialNode.Labels[label]
|
existingNode.Labels[label] = initialNode.Labels[label]
|
||||||
needsUpdate = true
|
needsUpdate = true
|
||||||
|
|
|
@ -1233,6 +1233,37 @@ func TestUpdateDefaultLabels(t *testing.T) {
|
||||||
"please-persist": "foo",
|
"please-persist": "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "make sure existing labels do not get deleted when initial node has no opinion",
|
||||||
|
initialNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
existingNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
kubeletapis.LabelHostname: "new-hostname",
|
||||||
|
kubeletapis.LabelZoneFailureDomain: "new-zone-failure-domain",
|
||||||
|
kubeletapis.LabelZoneRegion: "new-zone-region",
|
||||||
|
kubeletapis.LabelInstanceType: "new-instance-type",
|
||||||
|
kubeletapis.LabelOS: "new-os",
|
||||||
|
kubeletapis.LabelArch: "new-arch",
|
||||||
|
"please-persist": "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
needsUpdate: false,
|
||||||
|
finalLabels: map[string]string{
|
||||||
|
kubeletapis.LabelHostname: "new-hostname",
|
||||||
|
kubeletapis.LabelZoneFailureDomain: "new-zone-failure-domain",
|
||||||
|
kubeletapis.LabelZoneRegion: "new-zone-region",
|
||||||
|
kubeletapis.LabelInstanceType: "new-instance-type",
|
||||||
|
kubeletapis.LabelOS: "new-os",
|
||||||
|
kubeletapis.LabelArch: "new-arch",
|
||||||
|
"please-persist": "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "no update needed",
|
name: "no update needed",
|
||||||
initialNode: &v1.Node{
|
initialNode: &v1.Node{
|
||||||
|
|
Loading…
Reference in New Issue