Module: Dctl::Kubernetes

Defined in:
lib/dctl/kubernetes.rb,
lib/dctl/cli/kubernetes.rb

Defined Under Namespace

Classes: Cli

Class Method Summary collapse

Class Method Details

.live_image(service, namespace: nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dctl/kubernetes.rb', line 2

def self.live_image(service, namespace: nil)
  # Check if namespace exists
  if namespace && `kubectl get ns #{namespace}`.empty?
    error = "Could not find namespace #{namespace}"
    puts Rainbow(error).fg ERROR_COLOR
    exit 1
  end

  # Check if deployment exists
  deploy_check_command = "kubectl get deploy #{service}"
  deploy_check_command += " -n #{namespace}" if namespace
  if `#{deploy_check_command}`.empty?
    error = "Could not find deployment for #{service}"
    error += " in namespace #{namespace}" if namespace
    puts Rainbow(error).fg ERROR_COLOR
    exit 1
  end

  jsonpath = "{$.spec.template.spec.containers[:1].image}"
  live_image_command = "kubectl get deploy #{service}"
  live_image_command += " -ojsonpath='#{jsonpath}'"
  live_image_command += " -n #{namespace}" if namespace

  `#{live_image_command}`
end