Class: Gitlab::Kubernetes::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/kubernetes/namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, client, labels: nil) ⇒ Namespace

Returns a new instance of Namespace.



8
9
10
11
12
# File 'lib/gitlab/kubernetes/namespace.rb', line 8

def initialize(name, client, labels: nil)
  @name = name
  @client = client
  @labels = labels
end

Instance Attribute Details

#labelsObject

Returns the value of attribute labels.



6
7
8
# File 'lib/gitlab/kubernetes/namespace.rb', line 6

def labels
  @labels
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/gitlab/kubernetes/namespace.rb', line 6

def name
  @name
end

Instance Method Details

#create!Object



20
21
22
23
24
25
# File 'lib/gitlab/kubernetes/namespace.rb', line 20

def create!
  resource = ::Kubeclient::Resource.new(metadata: { name: name, labels: labels })

  log_event(:begin_create)
  @client.create_namespace(resource)
end

#ensure_exists!Object



27
28
29
30
31
32
# File 'lib/gitlab/kubernetes/namespace.rb', line 27

def ensure_exists!
  exists? || create!
rescue ::Kubeclient::HttpError => error
  log_create_failed(error)
  raise
end

#exists?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/gitlab/kubernetes/namespace.rb', line 14

def exists?
  @client.get_namespace(name)
rescue ::Kubeclient::ResourceNotFoundError
  false
end