kubeclient create_namespace NoMethodError

6/6/2018

I have a program in ruby which creates deployments, services and ing in a specific namespace. When I want to create a namespace, it complains for NoMethodError.

This is the code:

namespace = Kubeclient::Resource.new
namespace.metadata = {}
namespace.metadata.name = ns
@kube_client.create_daemon_set namespace

And this is the exception:

Exception occurred undefined method `create_namespace' for #<Kubeclient::Client:0x0000000267b810>

All other functions including creating deployment and service works fine.

-- ma ra
kubernetes
namespaces
ruby

1 Answer

6/8/2018

This is a snippet from a test:

namespace = Kubeclient::Resource.new
namespace.metadata = {}
namespace.metadata.name = 'development'

client = Kubeclient::Client.new('http://localhost:8080/api/')
created_namespace = client.create_namespace(namespace)
assert_instance_of(Kubeclient::Resource, created_namespace)
assert_equal(namespace.metadata.name, created_namespace.metadata.name)

You forgot parenthesis.

-- Nicola Ben
Source: StackOverflow