-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kubectl label command crashes when a resource has no labels #4311
Conversation
kazegusuri
commented
Feb 11, 2015
I wonder if |
Modified |
Someone should check to ensure that this is a good change i.e. for |
@jlowdermilk reviewed ed9761f which originally added kubectl label and might also have an opinion. |
If it's any guide, the ObjectMeta api object specifies labels as an omitempty field. I suspect there may be other code which assumes that objectmeta returns nil labels if the object has no labels. I recommend you just keep the original change in label.go. |
@@ -46,5 +46,13 @@ func ObjectMetaFor(obj runtime.Object) (*ObjectMeta, error) { | |||
if err := runtime.FieldPtr(v, "ObjectMeta", &objectMeta); err != nil { | |||
return nil, err | |||
} | |||
|
|||
if objectMeta.Labels == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncomfortable with this - nil labels and nil annotations is a valid go-ism - making it here doesn't make this easier to consume.
I would prefer clients simply guard against labels being nil. |
Yeah, I think I'd prefer nil checks in the client also... @kazegusuri thanks for the PR and sorry for the run around... If you revert back to your original nil checks, I'll happily merge this PR. Thanks again. |
3d465e6
to
a841b91
Compare
OK, thank you for review. I reverted the second commit. |
LGTM. Merging. (sorry for the delay!) |
kubectl label command crashes when a resource has no labels