Class: Kubes::Kubectl::Fetch::Deployment

Inherits:
Base
  • Object
show all
Extended by:
Memoist
Defined in:
lib/kubes/kubectl/fetch/deployment.rb

Instance Method Summary collapse

Methods inherited from Base

#fetch, #initialize, #namespace

Methods included from Util::Sh

#sh, #sh_capture

Methods included from Logging

#logger

Constructor Details

This class inherits a constructor from Kubes::Kubectl::Fetch::Base

Instance Method Details

#deploymentObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kubes/kubectl/fetch/deployment.rb', line 13

def deployment
  items = fetch(:deployment)
  # Not checking if deployment exists because kubes will error on `kubes get` from missing deployments already
  deployments = items.select { |i| i['kind'] == "Deployment" }

  if !@options[:deployment] && !@options[:pod] && deployments.size > 1
    names = deployments.map { |d| d['metadata']['name'] }
    logger.info <<~EOL
      INFO: More than one deployment found.
      Deployment names: #{names.join(', ')}
      Using #{names.first}
      Note: You can specify the deployment to use with --deployment or -d
    EOL
  end

  find_deployment(deployments)
end

#find_deployment(deployments) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/kubes/kubectl/fetch/deployment.rb', line 36

def find_deployment(deployments)
  if @options[:deployment]
    deployments.find { |d| d['metadata']['name'] == @options[:deployment] }
  else
    deployments.first
  end
end

#foundObject



32
33
34
# File 'lib/kubes/kubectl/fetch/deployment.rb', line 32

def found
  !!deployment
end

#metadataObject



5
6
7
# File 'lib/kubes/kubectl/fetch/deployment.rb', line 5

def 
  deployment['metadata'] if found
end

#specObject



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

def spec
  deployment['spec'] if found
end