Commit 86a0193f authored by Brendan Burns's avatar Brendan Burns

Merge pull request #4311 from kazegusuri/update_nil_label

kubectl label command crashes when a resource has no labels
parents 93d77ab6 a841b91a
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment