Class: Kubecontrol::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kubecontrol/client.rb

Constant Summary collapse

DEFAULT_NAMESPACE =
'default'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = DEFAULT_NAMESPACE) ⇒ Client

Returns a new instance of Client.



13
14
15
# File 'lib/kubecontrol/client.rb', line 13

def initialize(namespace = DEFAULT_NAMESPACE)
  @namespace = namespace
end

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



11
12
13
# File 'lib/kubecontrol/client.rb', line 11

def namespace
  @namespace
end

Instance Method Details

#deploymentsObject



21
22
23
# File 'lib/kubecontrol/client.rb', line 21

def deployments
  get_resource(Deployment, 5)
end

#find_deployment_by_name(name_regex) ⇒ Object



41
42
43
# File 'lib/kubecontrol/client.rb', line 41

def find_deployment_by_name(name_regex)
  deployments.find { |deployment| deployment.name.match?(name_regex) }
end

#find_pod_by_name(name_regex) ⇒ Object



37
38
39
# File 'lib/kubecontrol/client.rb', line 37

def find_pod_by_name(name_regex)
  pods.find { |pod| pod.name.match?(name_regex) }
end

#find_service_by_name(name_regex) ⇒ Object



33
34
35
# File 'lib/kubecontrol/client.rb', line 33

def find_service_by_name(name_regex)
  services.find { |service| service.name.match?(name_regex) }
end

#find_stateful_set_by_name(name_regex) ⇒ Object



45
46
47
# File 'lib/kubecontrol/client.rb', line 45

def find_stateful_set_by_name(name_regex)
  stateful_sets.find { |stateful_set| stateful_set.name.match?(name_regex) }
end

#kubectl_command(command) ⇒ Object



49
50
51
52
53
54
# File 'lib/kubecontrol/client.rb', line 49

def kubectl_command(command)
  stdout_data, stderr_data, status = Open3.capture3("kubectl -n #{namespace} #{command}")
  exit_code = status.exitstatus

  [stdout_data, stderr_data, exit_code]
end

#podsObject



17
18
19
# File 'lib/kubecontrol/client.rb', line 17

def pods
  get_resource(Pod, 5)
end

#servicesObject



29
30
31
# File 'lib/kubecontrol/client.rb', line 29

def services
  get_resource(Service, 6)
end

#stateful_setsObject



25
26
27
# File 'lib/kubecontrol/client.rb', line 25

def stateful_sets
  get_resource(StatefulSet, 3)
end