Class: Services::Kube

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/busbar_cli/services/kube.rb

Class Method Summary collapse

Class Method Details

.config_download(force = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/busbar_cli/services/kube.rb', line 61

def config_download(force = nil)
  puts 'Config file up-to-date and no force option specified...' unless \
    Helpers::Kube.config_outdated? || force
  puts 'Nothing to do.' unless Helpers::Kube.config_outdated? || force
  return unless Helpers::Kube.config_outdated? || force

  puts 'Updating kubeconfig...'
  old_version = Helpers::Kube.config_local_version
  Helpers::Kube.config_download_file
  Helpers::Kube.config_update_local_version
  puts "Kubeconfig file update from version #{old_version} to #{Helpers::Kube.config_local_version}."
rescue SocketError
  Helpers::Kube.config_exit_with_no_connection_error
end

.configure_temporary_profile(profile = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/busbar_cli/services/kube.rb', line 29

def configure_temporary_profile(profile = nil)
  setup
  return if profile.nil?
  validate_profile(profile)
  @current_profile = profile
end

.contextsObject



23
24
25
26
27
# File 'lib/busbar_cli/services/kube.rb', line 23

def contexts
  setup
  `grep 'name:' #{KUBECTL_CONFIG_FILE} | grep -v '\\- name' |
  grep -v 'username' | sort | uniq | sed "s/name\://g; s/ //g"`.split("\n")
end

.current_profileObject



36
37
38
39
# File 'lib/busbar_cli/services/kube.rb', line 36

def current_profile
  setup
  @current_profile || BUSBAR_PROFILE
end

.public_address_info_for(environment:) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/busbar_cli/services/kube.rb', line 41

def public_address_info_for(environment:)
  setup
  service = JSON.parse(`#{Helpers::Kube.public_info_command_for(environment)}`)
  {
    address: service['status']['loadBalancer']['ingress'][0]['hostname'],
    port: service['spec']['ports'][0]['port']
  }
end

.setupObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/busbar_cli/services/kube.rb', line 10

def setup
  return if File.exist?(KUBECTL) && File.exist?(KUBECTL_CONFIG_FILE) && \
            File.exist?(KUBECTL_CONFIG_VERSION_FILE)
  puts
  puts 'Running kubectl setup...'
  puts
  FileUtils.mkdir_p(KUBECTL_LOCAL_FOLDER) unless File.exist?(KUBECTL_LOCAL_FOLDER)
  FileUtils.mkdir_p(KUBECTL_LOCAL_BIN_FOLDER) unless File.exist?(KUBECTL_LOCAL_BIN_FOLDER)
  Helpers::Kube.install
  Helpers::Kube.config_download_file
  Helpers::Kube.config_update_local_version
end

.validate_profile(profile) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/busbar_cli/services/kube.rb', line 50

def validate_profile(profile)
  setup
  puts profile
  return true if contexts.include?(profile)
  puts
  puts 'Validation Error!'
  puts "Profile must be one of the following:\n#{contexts.to_yaml}"
  puts
  exit(1)
end