mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #4311 from kazegusuri/update_nil_label
kubectl label command crashes when a resource has no labels
This commit is contained in:
commit
86a0193f51
@ -160,6 +160,10 @@ func labelFunc(obj runtime.Object, overwrite bool, resourceVersion string, label
|
||||
}
|
||||
}
|
||||
|
||||
if meta.Labels == nil {
|
||||
meta.Labels = make(map[string]string)
|
||||
}
|
||||
|
||||
for key, value := range labels {
|
||||
meta.Labels[key] = value
|
||||
}
|
||||
|
@ -230,6 +230,17 @@ func TestLabelFunc(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
obj: &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{},
|
||||
},
|
||||
labels: map[string]string{"a": "b"},
|
||||
expected: &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{"a": "b"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
out, err := labelFunc(test.obj, test.overwrite, test.version, test.labels, test.remove)
|
||||
|
Loading…
Reference in New Issue
Block a user