jsonnet-libs / k8s

Code generator for Jsonnet Kubernetes libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Namespace should be required for all namespaced resource types

captncraig opened this issue · comments

I would love to see this library offer better help for avoiding omitted namespaces on objects, and thus going into the default namespace unintentionally. This is an opinionated stance, but I strongly hold the opinion that it is too easy to forget a namespace, and too tricky to declare it when you want to.

My desire in brief: each namespaced type should have a constructor that requires a namespace to be declared. If all types have a new(name,namespace) generated, users physically cannot forget a namespace. If they want to put something in default, they must do so explicitly.

So you would have deployment.new(name, namespace), but clusterRole.new(name) only.

Now, implementation is tricky. The swagger definitions this generator relies on does not have that info. I am not sure the absolute authoritative source, but it is in the depths of the k8s source, possibly hidden in comments. I have 3 ideas:

  1. Petition kubernetes project to include the Namespaced metadata in the swagger definitions. Even if possible, this is not a fast or easy solution for us now.
  2. Generate our own list of namespaced/unnamespaced resource types with kubectl and preserve it in config.yaml. Use this in the config to make the appropriate constructors.
  3. Assume all resources with ObjectMetadata are namespaced and generate the full new(name,namespace) constructor. Make it smart enough to omit the namespace if you explicitly set the namespace to default.

Option 3 is by far the easiest to implement, but has the downside that the only way to make something like a ClusterRole work, you'd need to do clusterRole.new(name, 'default'), which is a bit of a lie.

Perhaps something like "assume all types are namespaced" except for a smaller list of only the global kinds, or perhaps custom overrides for those types that continue to cause problems.

If the k8s library solved this problem, it would ease up the need for tools like tanka to even care about such things.

Thoughts?

This is not relevant anymore, Tanka handles this just fine.