Module: Kdep::Kubectl

Defined in:
lib/kdep/kubectl.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.apply(file_path, namespace:) ⇒ Object



25
26
27
# File 'lib/kdep/kubectl.rb', line 25

def self.apply(file_path, namespace:)
  run("apply", "-f", file_path, "-n", namespace)
end

.current_contextObject



21
22
23
# File 'lib/kdep/kubectl.rb', line 21

def self.current_context
  run("config", "current-context").strip
end

.diff(file_path) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kdep/kubectl.rb', line 29

def self.diff(file_path)
  stdout, stderr, status = Open3.capture3("kubectl", "diff", "-f", file_path)
  case status.exitstatus
  when 0
    nil
  when 1
    stdout
  else
    raise Error, "kubectl diff failed (exit #{status.exitstatus}): #{stderr.strip}"
  end
end

.run(*args) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/kdep/kubectl.rb', line 8

def self.run(*args)
  stdout, stderr, status = Open3.capture3("kubectl", *args)
  unless status.success?
    raise Error, "kubectl #{args.first} failed: #{stderr.strip}"
  end
  stdout
end

.run_json(*args) ⇒ Object



16
17
18
19
# File 'lib/kdep/kubectl.rb', line 16

def self.run_json(*args)
  output = run(*args, "-o", "json")
  JSON.parse(output)
end