mina-kubernetes 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56a5ae3aa0145710a9898716bcc074ce8eaf92b8bf7fe13878c495fdda8e9d08
4
- data.tar.gz: a652740b29a28d4bc03cf3090f202a81dacc14a45f5fa5d73d80d17546b1e9bc
3
+ metadata.gz: 3a40a0047704517ce7a6e10daf7373ca3fe7398d0f655280992f3bb76ba8fff0
4
+ data.tar.gz: d7efeb94f504ece35b47829c927429b502112f511b91b552ca9c03df20d0e28d
5
5
  SHA512:
6
- metadata.gz: 3c9c373ff7f6df13ab3179c86794d73dc905f897ca04cb4c67687dba557705f48eef3b3ab06acd9e40187428c4cff79b0e81b077c73964a740dea9aac51dff9d
7
- data.tar.gz: 5d134fdf9f30eaf816c7300634b2d3c094f446b3855e4a09bf0c770570bbe4774e81f6b01952a686e4dbacb8940c2022135c15aa3a352a79432d8cc187e63f15
6
+ metadata.gz: 3aaf4c5a80be9b84e75be8d2b15be9e79622ff58ed75e43ae90cde743ba944071707fee26d47e95ae6f8a504ceaa85225c18ed3c8eba5833bc3a6ff84ccbde04
7
+ data.tar.gz: 5045d3eeaae653fede93ae8bdba3631d8cdcd3297210ec8d8d3add742fbd9e5a0a062af5eaf85edd579604275e80cb89215ed97f3ad96cc84e50ba4cf2ffa67c
@@ -1,5 +1,14 @@
1
+ ## 2.7.0
2
+
3
+ *Enhancements*
4
+
5
+ - `kubernetes:command` allows to choose pod name
6
+ - `kubernetes:command` offers to kill & start fresh pod or start other pod with different name if pod already exists
7
+
1
8
  ## 2.6.0
2
9
 
10
+ *Fixes*
11
+
3
12
  - Update krane gem to ~> 2.1 for compatibility with k8s >= 1.17
4
13
 
5
14
  ## 2.5.0
@@ -84,34 +84,54 @@ end
84
84
 
85
85
  def run_command(command, env_hash = {})
86
86
  env = env_hash.collect{|k,v| "--env #{k}=#{v}" }.join(" ")
87
- label = command.downcase.gsub(" ", "-").gsub(":", "-")+ "-#{`whoami`}".strip + "-#{fetch(:branch)}"
88
87
  proxy_env = "HTTPS_PROXY=#{fetch(:proxy)}" if fetch(:proxy)
89
88
 
89
+ default_pod_name = "#{`whoami`.strip}-#{command}-#{fetch(:branch)}".downcase.gsub(" ", "-").gsub(":", "-")
90
+ pod_name = TTY::Prompt.new.ask("What name for the pod?", :value => default_pod_name)
91
+
90
92
  run :local do
91
- comment "Lauching Pod #{color(label, 36)} to run #{color(command, 36)}"
93
+ comment "Lauching pod #{color(pod_name, 36)} to run #{color(command, 36)}"
92
94
  end
93
95
 
94
- pod_description = `#{proxy_env} kubectl get pod #{label} -o json --ignore-not-found --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)}`
96
+ pod_run_command = "#{proxy_env} kubectl run #{pod_name} --rm -i --tty --restart=Never --overrides='#{fetch(:kubectl_pod_overrides)}' --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)} --image #{fetch(:image_repo)}:#{fetch(:image_tag)} #{env}"
97
+ running_pod_info = `#{proxy_env} kubectl get pod #{pod_name} -o json --ignore-not-found --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)}`
95
98
 
96
- if pod_description.empty?
97
- wait_until_image_ready(fetch(:image_tag))
98
- run_command = "#{proxy_env} kubectl run #{label} --rm -i --tty --restart=Never --overrides='#{fetch(:kubectl_pod_overrides)}' --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)} --image #{fetch(:image_repo)}:#{fetch(:image_tag)} #{env}"
99
- system "#{run_command} -- #{command}"
99
+ if running_pod_info.empty?
100
+ wait_for_image_and_run_command("#{pod_run_command} -- #{command}")
100
101
  else
101
- started_at = Time.parse(JSON.parse(pod_description)["status"]["startTime"]).strftime('%b %e, %H:%M')
102
- choice = TTY::Prompt.new.select("Pod already exists, running since #{started_at} UTC, what would you like to do?", {"Reattach session" => 1, "Kill it" => 0})
102
+ started_at = Time.parse(JSON.parse(running_pod_info)["status"]["startTime"]).strftime('%b %e, %H:%M')
103
+ choice = TTY::Prompt.new.select(
104
+ "Pod already exists, running since #{started_at} UTC, what would you like to do?",
105
+ {
106
+ "Reattach to its container" => :attach,
107
+ "Kill it and launch a fresh one" => :replace,
108
+ "Keep it and start one with a different name" => :other,
109
+ }
110
+ )
103
111
 
104
- attach_command = "#{proxy_env} kubectl attach #{label} -i --tty -c #{label} --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)}"
105
- delete_command = "#{proxy_env} kubectl delete pod #{label} --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)}"
112
+ delete_command = "#{proxy_env} kubectl delete pod #{pod_name} --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)}"
106
113
 
107
- if choice == 1
114
+ case choice
115
+ when :attach
116
+ attach_command = "#{proxy_env} kubectl attach #{pod_name} -i --tty -c #{pod_name} --context=#{fetch(:kubernetes_context)} --namespace=#{fetch(:namespace)}"
108
117
  system "#{attach_command} && #{delete_command}"
109
- else
118
+ when :replace
110
119
  system delete_command
120
+ run :local do
121
+ comment "Lauching Pod #{color(pod_name, 36)} to run #{color(command, 36)}"
122
+ end
123
+ wait_for_image_and_run_command("#{pod_run_command} -- #{command}")
124
+ when :other
125
+ run_command(command, env_hash)
111
126
  end
112
127
  end
113
128
  end
114
129
 
130
+ def wait_for_image_and_run_command(command)
131
+ wait_until_image_ready(fetch(:image_tag))
132
+ system command
133
+ end
134
+
115
135
  def apply_kubernetes_resources(options)
116
136
  run :local do
117
137
  comment "Applying all Kubernetes resources..."
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Kubernetes
3
- VERSION = "2.6.0"
3
+ VERSION = "2.7.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-kubernetes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Sabourin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.0.3
144
+ rubygems_version: 3.1.2
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Mina plugin to streamline deployment of resources to Kubernetes cluster