Merge pull request #4311 from kazegusuri/update_nil_label

kubectl label command crashes when a resource has no labels
This commit is contained in:
Brendan Burns 2015-02-20 15:52:05 -08:00
commit 86a0193f51
2 changed files with 15 additions and 0 deletions

View File

@ -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
}

View File

@ -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)