Class: Gitlab::Kubernetes::Helm::API

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

Instance Method Summary collapse

Constructor Details

#initialize(kubeclient) ⇒ API

Returns a new instance of API.


7
8
9
10
11
12
13
14
# File 'lib/gitlab/kubernetes/helm/api.rb', line 7

def initialize(kubeclient)
  @kubeclient = kubeclient
  @namespace = Gitlab::Kubernetes::Namespace.new(
    Gitlab::Kubernetes::Helm::NAMESPACE,
    kubeclient,
    labels: Gitlab::Kubernetes::Helm::NAMESPACE_LABELS
  )
end

Instance Method Details

#delete_pod!(pod_name) ⇒ Object


52
53
54
55
56
# File 'lib/gitlab/kubernetes/helm/api.rb', line 52

def delete_pod!(pod_name)
  kubeclient.delete_pod(pod_name, namespace.name)
rescue ::Kubeclient::ResourceNotFoundError
  # no-op
end

#get_config_map(config_map_name) ⇒ Object


58
59
60
61
62
# File 'lib/gitlab/kubernetes/helm/api.rb', line 58

def get_config_map(config_map_name)
  namespace.ensure_exists!

  kubeclient.get_config_map(config_map_name, namespace.name)
end

#install(command) ⇒ Object Also known as: update


16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/kubernetes/helm/api.rb', line 16

def install(command)
  namespace.ensure_exists!

  (command)
  create_cluster_role_binding(command)
  create_config_map(command)

  delete_pod!(command.pod_name)
  kubeclient.create_pod(command.pod_resource)
end

#log(pod_name) ⇒ Object


48
49
50
# File 'lib/gitlab/kubernetes/helm/api.rb', line 48

def log(pod_name)
  kubeclient.get_pod_log(pod_name, namespace.name).body
end

#status(pod_name) ⇒ Object

Returns Pod phase

kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase

values: “Pending”, “Running”, “Succeeded”, “Failed”, “Unknown”


44
45
46
# File 'lib/gitlab/kubernetes/helm/api.rb', line 44

def status(pod_name)
  kubeclient.get_pod(pod_name, namespace.name).status.phase
end

#uninstall(command) ⇒ Object


29
30
31
32
33
34
35
# File 'lib/gitlab/kubernetes/helm/api.rb', line 29

def uninstall(command)
  namespace.ensure_exists!
  create_config_map(command)

  delete_pod!(command.pod_name)
  kubeclient.create_pod(command.pod_resource)
end