kubernetes: Warn users about CRD alias naming conflicts

Issue https://github.com/kubernetes/kubernetes/issues/94860 was closed as stale so opening a new one.

Another case in which this happens is with kubectl get img if both Knative Serving and kpack are installed.

Calling kubectl api-resources shows that a kpack Image resource should have four aliases:

$ k api-resources | grep kpack | grep -i image
images                            cnbimage,cnbimages,img,imgs   kpack.io/v1alpha2                           true         Image

Three of these aliases work:

$ k get cnbimage
NAME     LATESTIMAGE                                                                                                      READY
manual   gcr.io/fe-ciberkleid/demo/app@sha256:c3a9f2e8f8eced4f6779aa99419642c164665768872960c9c7737bd1146cd044   True

$ k get cnbimages
NAME     LATESTIMAGE                                                                                                      READY
manual   gcr.io/fe-ciberkleid/demo/app@sha256:c3a9f2e8f8eced4f6779aa99419642c164665768872960c9c7737bd1146cd044   True

$ k get imgs
NAME     LATESTIMAGE                                                                                                      READY
manual   gcr.io/fe-ciberkleid/demo/app@sha256:c3a9f2e8f8eced4f6779aa99419642c164665768872960c9c7737bd1146cd044   True

However, one of the aliases (img) does not work:

$ k get img
No resources found in default namespace.

I think it is important to inform the user that the img resource may refer to more than one type. The above results are misleading and can cause users to draw incorrect conclusions about what is or isn’t running.

Aside: I had originally logged this under kpack but was advised that it is a kubectl issues, hence bringing it up here. For reference, the kpack issue is https://github.com/pivotal/kpack/issues/929.

_Originally posted by @ciberkleid in https://github.com/kubernetes/kubernetes/issues/94860#issuecomment-1061063514_

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (15 by maintainers)

Most upvoted comments

This is not a bug, this is working as designed. I do understand that this is causing a lot of confusion, but in your case the problem is not with kubectl which is reading information from API discovery and picking one resource over the other, but rather it’s coming from the fact that you’re using an alias to a resource which any resource can define freely when registering CRD. In those cases where you have multiple resources with identical aliases, or even identical names I ALWAYS advise users to use fully qualified name to ensure they are retrieving requested resource.