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

Client expects to see namespace on all resources #32

Open
jnummelin opened this issue Aug 23, 2018 · 6 comments
Open

Client expects to see namespace on all resources #32

jnummelin opened this issue Aug 23, 2018 · 6 comments

Comments

@jnummelin
Copy link
Contributor

It doesn't seem to use the contexts namespace from the config. IMO it should take that into account.

@SpComb
Copy link
Contributor

SpComb commented Aug 23, 2018

There's some haphazard namespace support at the Client level, but it's not really very well tested. I'm not entirely sure how the APIClient should behave in terms of non-namespaced resources / resources with a default namespace.

@SpComb
Copy link
Contributor

SpComb commented Aug 23, 2018

IMO it should take that into account.

In what kind of usages, as examples?

@jnummelin
Copy link
Contributor Author

jnummelin commented Aug 23, 2018

Let's say I want to push a plain pod like

kind: Pod
apiVersion: v1
metadata:
  name: myapp
  labels:
    name: myapp
spec:
  containers:
  - name: myapp
    image: foobar
    ports:
      - containerPort: 8080

With kubectl I could just apply it and kubectl would respect the config contexts default namespace, or just use the default namespace. I'd expect k8s-client to have the same logic.

@SpComb
Copy link
Contributor

SpComb commented Aug 23, 2018

So that would be:

client = K8s::Client.config(K8s::Config.load_file(ENV['KUBECONFIG']))
client.create_resource(K8s::Resource.from_file('pod.yml'))

You can already get pretty close with client.client_for_resource(resource, namespace: config.context.namespace).create_resource(resource), except it seems like:

  • K8s::Client.config doesn't set @namespace from the config.context.namespace
  • K8s::Client#client_for_resource doesn't take an optional namespace: ... param, defaulting to @namespace
  • K8s::ResourceClient#create_resource doesn't have a namespace: ... param, it requires the resource.metadata.namespace to be set

There's going to be quite a lot of those kinds of small places to fix, so it would be good to go through some of the usecases to figure out the details.

@SpComb
Copy link
Contributor

SpComb commented Aug 24, 2018

This isn't as simple as just having K8s::Client#client_for_resource pass the client's default @namespace to the ResourceClient, because not all resources are namespaced... fixing this to work correctly for all methods will probably need some general changes to how the ResourceClient @namespace defaulting works.

@SpComb
Copy link
Contributor

SpComb commented Aug 24, 2018

There are three cases to consider:

  • namespace: 'default' for GET/PUT/POST /api/v1/namespaces/default/services/foo of namespaced resources
  • namespace: nil for GET /api/v1/services to list all namespaced resources
  • namespace: nil for GET/PUT/POST /api/v1/namespaces/foo of non-namespaced resources

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

No branches or pull requests

2 participants