mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
fix a panic due to assignment to nil map
This commit is contained in:
parent
da1bb02830
commit
e8cd28ae57
@ -162,6 +162,9 @@ func (kl *Kubelet) updateDefaultLabels(initialNode, existingNode *v1.Node) bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
var needsUpdate bool = false
|
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
|
//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 {
|
if _, hasInitialValue := initialNode.Labels[label]; !hasInitialValue {
|
||||||
|
@ -1414,6 +1414,33 @@ func TestUpdateDefaultLabels(t *testing.T) {
|
|||||||
kubeletapis.LabelArch: "new-arch",
|
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 {
|
for _, tc := range cases {
|
||||||
|
Loading…
Reference in New Issue
Block a user