class Podjumper::Pod

Attributes

description[R]

Public Class Methods

_get_pods(namespace: nil, subdomain: nil) click to toggle source
# File lib/podjumper/pod.rb, line 79
def _get_pods(namespace: nil, subdomain: nil)
  ns_flag = namespace ? "--namespace=#{namespace}" : '--all-namespaces'
  sd_flag = subdomain ? "--selector=subdomain=#{subdomain}" : nil
  %w[kubectl get pods --output=json]
    .push(ns_flag, sd_flag)
    .compact
end
new(description) click to toggle source
# File lib/podjumper/pod.rb, line 3
def initialize(description)
  @description = description
  validate_resource!
  validate_version!
end
where(**opts) click to toggle source
# File lib/podjumper/pod.rb, line 71
def where(**opts)
  output = TTY::Command.new(printer: :null).run(*_get_pods(opts)).out

  JSON.parse(output)
      .fetch('items', [])
      .map { |h| Pod.new(h) }
end

Public Instance Methods

container(name) click to toggle source
# File lib/podjumper/pod.rb, line 25
def container(name)
  container_names.find { |container_name| container_name =~ /#{name}/ }
end
container_names() click to toggle source
# File lib/podjumper/pod.rb, line 29
def container_names
  containers.map { |container| container['name'] }
end
labels() click to toggle source
# File lib/podjumper/pod.rb, line 21
def labels
  metadata['labels'] || {}
end
name() click to toggle source
# File lib/podjumper/pod.rb, line 17
def name
  metadata['name']
end
namespace() click to toggle source
# File lib/podjumper/pod.rb, line 9
def namespace
  metadata['namespace']
end
subdomain() click to toggle source
# File lib/podjumper/pod.rb, line 13
def subdomain
  labels['subdomain']
end
to_h() click to toggle source
# File lib/podjumper/pod.rb, line 33
def to_h
  JSON.parse(to_json)
end
to_json() click to toggle source
# File lib/podjumper/pod.rb, line 37
def to_json
  description.to_json
end

Private Instance Methods

api_version() click to toggle source
# File lib/podjumper/pod.rb, line 49
def api_version
  description['apiVersion']
end
containers() click to toggle source
# File lib/podjumper/pod.rb, line 57
def containers
  description['spec']['containers']
end
kind() click to toggle source
# File lib/podjumper/pod.rb, line 45
def kind
  description['kind']
end
metadata() click to toggle source
# File lib/podjumper/pod.rb, line 53
def metadata
  description['metadata']
end
validate_resource!() click to toggle source
# File lib/podjumper/pod.rb, line 61
def validate_resource!
  raise "Expected a pod, got #{kind.inspect}" if kind != 'Pod'
end
validate_version!() click to toggle source
# File lib/podjumper/pod.rb, line 65
def validate_version!
  raise "Invalid API version #{api_version.inspect}" if api_version != 'v1'
end