2018-11-16 19:37:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-07 07:50:39 -05:00
|
|
|
module Gitlab
|
|
|
|
module Kubernetes
|
|
|
|
class Namespace
|
|
|
|
attr_accessor :name
|
|
|
|
|
|
|
|
def initialize(name, client)
|
2017-11-07 11:51:30 -05:00
|
|
|
@name = name
|
2017-11-07 07:50:39 -05:00
|
|
|
@client = client
|
|
|
|
end
|
|
|
|
|
|
|
|
def exists?
|
|
|
|
@client.get_namespace(name)
|
2018-11-13 07:46:01 -05:00
|
|
|
rescue ::Kubeclient::ResourceNotFoundError
|
2017-11-07 07:50:39 -05:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def create!
|
|
|
|
resource = ::Kubeclient::Resource.new(metadata: { name: name })
|
|
|
|
|
|
|
|
@client.create_namespace(resource)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_exists!
|
|
|
|
exists? || create!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|