Skip to content
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

Merged
merged 1 commit into from
Feb 20, 2015

Conversation

kazegusuri
Copy link
Contributor

$ cat redis-master.json
{
  "id": "redis-master",
  "kind": "Pod",
  "apiVersion": "v1beta1",
  "desiredState": {
    "manifest": {
      "version": "v1beta1",
      "id": "redis-master",
      "containers": [{
        "name": "master",
        "image": "dockerfile/redis",
        "cpu": 100,
        "ports": [{
          "containerPort": 6379,
          "hostPort": 6379
        }]
      }]
    }
  }
}
$ kubectl create -f redis-master.json
$ kubectl get po
POD                 IP                  CONTAINER(S)        IMAGE(S)            HOST                        LABELS              STATUS
redis-master       10.244.23.2         master              dockerfile/redis    172.17.8.103/172.17.8.103   <none>              Running

$ kubectl label po redis-master name=bar 
# crash

@satnam6502
Copy link
Contributor

I wonder if api.ObjectMetaFor should make sure it returns an empty map rather than nil and requiring this check for its callers?

@bgrant0607
Copy link
Member

@brendandburns

@kazegusuri
Copy link
Contributor Author

Modified api.ObjectMetaFor to returns an empty map.

@satnam6502
Copy link
Contributor

Someone should check to ensure that this is a good change i.e. for api.ObjectMetaFor to return an empty map for empty labels rather than nil. @brendandburns or @bgrant0607 can probably make a pronouncement.

@roberthbailey
Copy link
Contributor

@jlowdermilk reviewed ed9761f which originally added kubectl label and might also have an opinion.

@j3ffml
Copy link
Contributor

j3ffml commented Feb 11, 2015

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 {
Copy link
Contributor

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.

@smarterclayton
Copy link
Contributor

I would prefer clients simply guard against labels being nil.

@brendandburns
Copy link
Contributor

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.

@kazegusuri
Copy link
Contributor Author

OK, thank you for review. I reverted the second commit.

@brendandburns
Copy link
Contributor

LGTM. Merging.

(sorry for the delay!)

brendandburns added a commit that referenced this pull request Feb 20, 2015
kubectl label command crashes when a resource has no labels
@brendandburns brendandburns merged commit 86a0193 into kubernetes:master Feb 20, 2015
@kazegusuri kazegusuri deleted the update_nil_label branch May 23, 2015 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants