Class: Helpers::Kube
- Inherits:
-
Object
- Object
- Helpers::Kube
- Includes:
- Singleton
- Defined in:
- lib/busbar_cli/helpers/kube.rb
Class Method Summary collapse
- .config_download_file ⇒ Object
- .config_exit_with_no_connection_error ⇒ Object
- .config_local_version ⇒ Object
- .config_outdated? ⇒ Boolean
- .config_remote_version ⇒ Object
- .config_update_local_version ⇒ Object
- .install ⇒ Object
- .public_info_command_for(environment) ⇒ Object
Class Method Details
.config_download_file ⇒ Object
48 49 50 51 52 53 |
# File 'lib/busbar_cli/helpers/kube.rb', line 48 def config_download_file response = Net::HTTP.get(URI(KUBECTL_CONFIG_FILE_URL)) open(KUBECTL_CONFIG_FILE, 'wb') do |file| file.write(response) end end |
.config_exit_with_no_connection_error ⇒ Object
61 62 63 64 65 66 |
# File 'lib/busbar_cli/helpers/kube.rb', line 61 def config_exit_with_no_connection_error puts 'No connection could be established with the Kubectl Config ' \ "repository (#{KUBECTL_CONFIG_FILE_URL}).\n" \ 'You may need to connect to a VPN to access it.' exit 0 end |
.config_local_version ⇒ Object
43 44 45 46 |
# File 'lib/busbar_cli/helpers/kube.rb', line 43 def config_local_version return 0 unless File.exist?(KUBECTL_CONFIG_VERSION_FILE) File.read(KUBECTL_CONFIG_VERSION_FILE).to_i end |
.config_outdated? ⇒ Boolean
33 34 35 |
# File 'lib/busbar_cli/helpers/kube.rb', line 33 def config_outdated? config_remote_version > config_local_version end |
.config_remote_version ⇒ Object
37 38 39 40 41 |
# File 'lib/busbar_cli/helpers/kube.rb', line 37 def config_remote_version Net::HTTP.get(URI(KUBECTL_CONFIG_VERSION_URL)).to_i rescue SocketError config_exit_with_no_connection_error end |
.config_update_local_version ⇒ Object
55 56 57 58 59 |
# File 'lib/busbar_cli/helpers/kube.rb', line 55 def config_update_local_version open(KUBECTL_CONFIG_VERSION_FILE, 'wb') do |file| file.write(config_remote_version) end end |
.install ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/busbar_cli/helpers/kube.rb', line 9 def install return if File.exist?(KUBECTL) uname = `uname` os = case uname when /Darwin/ 'darwin' when /Linux/ 'linux' end Net::HTTP.start('storage.googleapis.com') do |http| response = http.get("/kubernetes-release/release/v#{KUBECTL_VERSION}/bin/#{os}/amd64/kubectl") open(KUBECTL, 'wb') do |file| file.write(response.body) end FileUtils.chmod(0o755, KUBECTL) end end |
.public_info_command_for(environment) ⇒ Object
27 28 29 30 31 |
# File 'lib/busbar_cli/helpers/kube.rb', line 27 def public_info_command_for(environment) "#{KUBECTL} --context=#{Services::Kube.current_profile} get " \ "svc/#{environment.app_id}-#{environment.name}-public "\ "--namespace=#{environment.namespace} -o json" end |