Class: Seira::Helpers

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/helpers.rb

Class Method Summary collapse

Methods included from Commands

#gcloud, gcloud, kubectl, #kubectl

Class Method Details

.fetch_pod(name, context:) ⇒ Object



20
21
22
23
# File 'lib/helpers.rb', line 20

def fetch_pod(name, context:)
  output = Seira::Commands.kubectl("get pod #{name} -o json", context: context, return_output: true)
  JSON.parse(output) unless output.empty?
end

.fetch_pods(filters:, context:) ⇒ Object



14
15
16
17
18
# File 'lib/helpers.rb', line 14

def fetch_pods(filters:, context:)
  filter_string = { app: context[:app] }.merge(filters).map { |k, v| "#{k}=#{v}" }.join(',')
  output = Seira::Commands.kubectl("get pods -o json --selector=#{filter_string}", context: context, return_output: true)
  JSON.parse(output)['items']
end

.get_current_replicas(deployment:, context:) ⇒ Object



38
39
40
41
# File 'lib/helpers.rb', line 38

def get_current_replicas(deployment:, context:)
  output = Seira::Commands.kubectl("get deployment #{deployment} -o json", context: context, return_output: true)
  JSON.parse(output)['spec']['replicas']
end

.get_secret(key:, context:) ⇒ Object



34
35
36
# File 'lib/helpers.rb', line 34

def get_secret(key:, context:)
  Secrets.new(app: context[:app], action: 'get', args: [], context: context).get(key)
end


25
26
27
28
29
30
31
32
# File 'lib/helpers.rb', line 25

def log_link(context:, query:)
  link = context[:settings].log_link_format
  return nil if link.nil?
  link.gsub! 'APP', context[:app]
  link.gsub! 'CLUSTER', context[:cluster]
  link.gsub! 'QUERY', query
  link
end

.rails_env(context:) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/helpers.rb', line 6

def rails_env(context:)
  if context[:cluster] == 'internal'
    'production'
  else
    context[:cluster]
  end
end

.shell_usernameObject



43
44
45
46
47
# File 'lib/helpers.rb', line 43

def shell_username
  `whoami`
rescue
  'unknown'
end