Skip to content

Commit

Permalink
fix creating namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Jun 17, 2021
1 parent 5d5646b commit 9db00b4
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/kubetruth/kubeapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def ensure_namespace(ns = namespace)
rescue Kubeclient::ResourceNotFoundError
newns = Kubeclient::Resource.new
newns.metadata = {}
newns.metadata.name = namespace
newns.metadata.name = ns
set_managed(newns)
client.create_namespace(newns)
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions spec/kubetruth/kubeapi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def apiserver; "https://127.0.0.1"; end
ns = kapi.client.get_namespace(kapi.namespace)
expect(ns.kind).to eq("Namespace")
expect(ns.metadata.name).to eq(kapi.namespace)

newns = "#{namespace}-newns2"
expect { kapi.client.get_namespace(newns) }.to raise_error(Kubeclient::ResourceNotFoundError, /namespaces.*not found/)
kapi.ensure_namespace(newns)
ns = kapi.client.get_namespace(newns)
expect(ns.kind).to eq("Namespace")
expect(ns.metadata.name).to eq(newns)
end

it "sets labels when creating namespace" do
Expand Down

0 comments on commit 9db00b4

Please sign in to comment.