mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #66307 from guoshimin/fixnilmap
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>. fix a panic due to assignment to nil map **What this PR does / why we need it**: fix a panic due to assignment to nil map **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: **Special notes for your reviewer**: **Release note**: ```release-note Fixed a panic in the node status update logic when existing node has nil labels. ```
This commit is contained in:
commit
d4ac54ad64
@ -162,6 +162,9 @@ func (kl *Kubelet) updateDefaultLabels(initialNode, existingNode *v1.Node) bool
|
||||
}
|
||||
|
||||
var needsUpdate bool = false
|
||||
if existingNode.Labels == nil {
|
||||
existingNode.Labels = make(map[string]string)
|
||||
}
|
||||
//Set default labels but make sure to not set labels with empty values
|
||||
for _, label := range defaultLabels {
|
||||
if _, hasInitialValue := initialNode.Labels[label]; !hasInitialValue {
|
||||
|
@ -1414,6 +1414,33 @@ func TestUpdateDefaultLabels(t *testing.T) {
|
||||
kubeletapis.LabelArch: "new-arch",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "not panic when existing node has nil labels",
|
||||
initialNode: &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",
|
||||
},
|
||||
},
|
||||
},
|
||||
existingNode: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{},
|
||||
},
|
||||
needsUpdate: true,
|
||||
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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user