kubeclient
kubeclient copied to clipboard
Better error creating namespaced resource without metadata.namespace
I am having issues creating a new secret in a local minikube cluster. I've tried debugging this myself but I think my Ruby-foo isn't sufficient.
Here is my example code which is throwing the following exception:
ruby poc.rb
/usr/local/lib/ruby/gems/2.4.0/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:107:in `rescue in handle_exception': the server does not allow this method on the requested resource (KubeException)
from /usr/local/lib/ruby/gems/2.4.0/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:99:in `handle_exception'
from /usr/local/lib/ruby/gems/2.4.0/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:313:in `create_entity'
from /usr/local/lib/ruby/gems/2.4.0/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:191:in `block (2 levels) in define_entity_methods'
from /usr/local/lib/ruby/gems/2.4.0/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:79:in `method_missing'
from poc.rb:31:in `push_secret'
from poc.rb:10:in `main'
from poc.rb:34:in `<main>'
Did I misread the documentation? I tried to stay close to the provided examples in the README.
The base64-encoded password is a throwaway, of course.
@cben can you look into this?
I just ran into this as well. A debugging session showed that it was trying to POST to /api/v1/secrets
whereas the correct path is /api/v1/namespaces/test/secrets
since this is a namespaced resource. It looks like the path is built based on whether the particular instance has set metadata.namespace
rather than whether the resource type is namespaced. Adding metadata.namespace
to the secret fixes this (I see it is missing in the gist too), but the error could definitely use improvement.
@KnVerey @dictvm @moolitayer @cben then it seems that in create_entity
we should check if a resource is namespaced (this information is in the API definition) and warn with a meaningful error if the metadata.namespace
is missing.