Class: Kubes::Kubectl::Fetch::Base

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Logging, Util::Sh
Defined in:
lib/kubes/kubectl/fetch/base.rb

Direct Known Subclasses

Deployment, Pods

Instance Method Summary collapse

Methods included from Util::Sh

#sh, #sh_capture

Methods included from Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/kubes/kubectl/fetch/base.rb', line 9

def initialize(options={})
  @options = options
end

Instance Method Details

#fetch(kind) ⇒ Object



13
14
15
16
17
# File 'lib/kubes/kubectl/fetch/base.rb', line 13

def fetch(kind)
  return [] unless namespace
  data = Kubes::Kubectl.capture("get #{kind} -o json -n #{namespace}")
  data['items'] || [] # Note: When fetching only 1 resource, items is not part of structure
end

#namespaceObject



19
20
21
22
23
24
# File 'lib/kubes/kubectl/fetch/base.rb', line 19

def namespace
  path = ".kubes/output/shared/namespace.yaml"
  return unless File.exist?(path)
  data = Kubes::Kubectl.capture("get -f #{path} -o json")
  data['metadata']['name']
end