stax-helm 0.0.2 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stax/helm.rb +4 -0
- data/lib/stax/helm/base.rb +16 -0
- data/lib/stax/helm/cmd.rb +9 -6
- data/lib/stax/helm/deployment.rb +56 -0
- data/lib/stax/helm/ingress.rb +19 -0
- data/lib/stax/helm/kubectl.rb +11 -41
- data/lib/stax/helm/pod.rb +49 -0
- data/lib/stax/helm/stern.rb +2 -1
- data/lib/stax/helm/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce6add2c9a7276df7ed801b49c7f3a7151ba4d98c34b3690a4fdaca6678fdeb5
|
4
|
+
data.tar.gz: c04af79c0c1fe2a14d7493e175980aeef5864f074f2f405bc67bd7fef35696c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb825149e84265f3f50ea1d17554f4514d2db401d771251063f9f1ce81fb90cfe221053b4a7f9c168797777493679a11f56d850af34fbb3c548cff32237174c3
|
7
|
+
data.tar.gz: 29ff4a39a0ac91b12ea218cff57fd6afa81658ff9fc4ec26d8a90019bab133e8ef3fe5cf7adf3ae895a89a0c3b79f946a8b819e801093ffdf13e8d89418f668f
|
data/lib/stax/helm.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stax
|
2
|
+
class Base < Thor
|
3
|
+
|
4
|
+
no_commands do
|
5
|
+
def helm_release_name
|
6
|
+
@_helm_release_name ||= helm_safe("#{app_name}-#{branch_name}")
|
7
|
+
end
|
8
|
+
|
9
|
+
## make string safe to use in naming helm stuff
|
10
|
+
def helm_safe(string)
|
11
|
+
string.slice(0, 53).gsub(/[\W_]/, '-').downcase
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/stax/helm/cmd.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
module Stax
|
2
2
|
module Helm
|
3
|
+
|
3
4
|
class Cmd < Base
|
4
|
-
class_option :
|
5
|
+
class_option :recon, aliases: '--just-print', type: :boolean, default: false, desc: 'print command that would be run'
|
5
6
|
|
6
7
|
no_commands do
|
7
|
-
def helm_release_name
|
8
|
-
@_helm_release_name ||= "#{app_name}-#{branch_name}"
|
9
|
-
end
|
10
|
-
|
11
8
|
## location of helm chart
|
12
9
|
def helm_dir
|
13
10
|
File.join(Stax.root_path, 'helm')
|
@@ -21,7 +18,12 @@ module Stax
|
|
21
18
|
## run helm with args
|
22
19
|
def helm_run(*args)
|
23
20
|
cmd = [helm_bin, *args].join(' ')
|
24
|
-
options[:
|
21
|
+
options[:recon] ? puts(cmd) : system(cmd)
|
22
|
+
end
|
23
|
+
|
24
|
+
## description added to release
|
25
|
+
def helm_description
|
26
|
+
Git.sha
|
25
27
|
end
|
26
28
|
|
27
29
|
## override with full path to a values.yaml file
|
@@ -37,6 +39,7 @@ module Stax
|
|
37
39
|
## construct args for install and upgrade commands
|
38
40
|
def helm_update_args
|
39
41
|
[].tap do |args|
|
42
|
+
args.push("--description #{helm_description}") if helm_description
|
40
43
|
args.push("-f #{helm_values_file}") if helm_values_file
|
41
44
|
args.push(helm_values&.map { |k,v| "--set #{k}=#{v}" })
|
42
45
|
end.flatten
|
@@ -0,0 +1,56 @@
|
|
1
|
+
## tasks to work on deployments
|
2
|
+
module Stax
|
3
|
+
module Helm
|
4
|
+
class Cmd < Base
|
5
|
+
|
6
|
+
no_commands do
|
7
|
+
def helm_deployments
|
8
|
+
jsonpath = '{.items[*].metadata.name}'
|
9
|
+
%x[kubectl get deployments -o=jsonpath='#{jsonpath}' -l #{helm_selector}].split
|
10
|
+
end
|
11
|
+
|
12
|
+
## prompt user with a list of deployments to choose
|
13
|
+
def helm_ask_deployments(msg)
|
14
|
+
deployments = helm_deployments
|
15
|
+
if deployments.count > 1
|
16
|
+
puts deployments.each_with_index.map { |d, i| "#{i}: #{d}" }
|
17
|
+
resp = ask(msg, default: 'all')
|
18
|
+
if resp != 'all'
|
19
|
+
indices = resp.split.map(&:to_i)
|
20
|
+
deployments = Array(deployments.slice(*indices))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
deployments
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'deployments', 'list deployments'
|
28
|
+
def deployments
|
29
|
+
kubectl_run(:get, :deployments, '-l', helm_selector)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'restart', 'restart deployments'
|
33
|
+
def restart
|
34
|
+
helm_ask_deployments('choose deployments').each do |deployment|
|
35
|
+
kubectl_run(:rollout, :restart, :deployment, deployment)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'scale', 'show/set scale for deployments'
|
40
|
+
method_option :replicas, aliases: '-r', type: :numeric, default: nil, desc: 'replicas'
|
41
|
+
def scale
|
42
|
+
if options[:replicas]
|
43
|
+
deployments = helm_ask_deployments('choose deployments').join(' ')
|
44
|
+
kubectl_run(:scale, :deployment, deployments, '--replicas', options[:replicas])
|
45
|
+
else
|
46
|
+
debug("Deployment replicas for #{helm_release_name}")
|
47
|
+
deployments = kubectl_json(:get, :deployments, '-l', helm_selector)
|
48
|
+
print_table deployments['items'].map { |i|
|
49
|
+
[ i['metadata']['name'], i['status']['replicas'] || 0 ]
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
## tasks to get ingress details
|
2
|
+
module Stax
|
3
|
+
module Helm
|
4
|
+
class Cmd < Base
|
5
|
+
|
6
|
+
desc 'ingresses', 'list ingresses'
|
7
|
+
def ingresses
|
8
|
+
kubectl_run(:get, :ingresses, '-l', helm_selector)
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'dns', 'list external-dns hostnames'
|
12
|
+
def dns
|
13
|
+
jsonpath = '{.items[].metadata.annotations.external-dns\.alpha\.kubernetes\.io/hostname}' + "\n"
|
14
|
+
kubectl_run(:get, :ingresses, "-o=jsonpath='#{jsonpath}'", '-l', helm_selector)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/stax/helm/kubectl.rb
CHANGED
@@ -9,54 +9,24 @@ module Stax
|
|
9
9
|
|
10
10
|
def kubectl_run(*args)
|
11
11
|
cmd = [kubectl_bin, *args].join(' ')
|
12
|
-
options[:
|
12
|
+
options[:recon] ? puts(cmd) : system(cmd)
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def kubectl_json(*args)
|
16
|
+
args.push('-o=json')
|
17
|
+
cmd = [kubectl_bin, *args].join(' ')
|
18
|
+
options[:recon] ? puts(cmd) : JSON.parse(%x(#{cmd}))
|
19
|
+
end
|
20
|
+
|
21
|
+
## override this to match all objects in your helm release
|
22
|
+
def helm_selector
|
23
|
+
"app.kubernetes.io/instance=#{helm_release_name}"
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
27
|
desc 'services', 'list services'
|
22
28
|
def services
|
23
|
-
kubectl_run(:get, :services,
|
24
|
-
end
|
25
|
-
|
26
|
-
desc 'ingresses', 'list ingresses'
|
27
|
-
def ingresses
|
28
|
-
kubectl_run(:get, :ingresses, selector('app.kubernetes.io/instance': helm_release_name))
|
29
|
-
end
|
30
|
-
|
31
|
-
desc 'deployments', 'list deployments'
|
32
|
-
def deployments
|
33
|
-
kubectl_run(:get, :deployments, selector('app.kubernetes.io/instance': helm_release_name))
|
34
|
-
end
|
35
|
-
|
36
|
-
desc 'pods', 'list pods'
|
37
|
-
def pods
|
38
|
-
kubectl_run(:get, :pods, selector('app.kubernetes.io/instance': helm_release_name))
|
39
|
-
end
|
40
|
-
|
41
|
-
desc 'containers', 'list containers'
|
42
|
-
def containers
|
43
|
-
columns = 'NAME:.metadata.name,CONTAINERS:.spec.containers[*].name'
|
44
|
-
kubectl_run(:get, :pods, '-o', "custom-columns=#{columns}", selector('app.kubernetes.io/instance': helm_release_name))
|
45
|
-
end
|
46
|
-
|
47
|
-
## FIXME this is terrible, will be replaced with something better later
|
48
|
-
desc 'logs COMPONENT [CONTAINER]', 'show container logs'
|
49
|
-
method_option :container, aliases: '-c', type: :string, default: nil, desc: 'container from pod'
|
50
|
-
def logs(component)
|
51
|
-
container = options[:container] ? "-c #{options[:container]}" : ''
|
52
|
-
kubectl_run(
|
53
|
-
:logs,
|
54
|
-
container,
|
55
|
-
selector(
|
56
|
-
'app.kubernetes.io/instance': helm_release_name,
|
57
|
-
'app.kubernetes.io/component': component,
|
58
|
-
)
|
59
|
-
)
|
29
|
+
kubectl_run(:get, :services, '-l', helm_selector)
|
60
30
|
end
|
61
31
|
|
62
32
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
## tasks to work on pods
|
2
|
+
module Stax
|
3
|
+
module Helm
|
4
|
+
class Cmd < Base
|
5
|
+
|
6
|
+
no_commands do
|
7
|
+
def helm_pods
|
8
|
+
jsonpath = '{.items[*].metadata.name}'
|
9
|
+
%x[kubectl get pods -o=jsonpath='#{jsonpath}' -l #{helm_selector}].split
|
10
|
+
end
|
11
|
+
|
12
|
+
def helm_ask_pod(msg)
|
13
|
+
pods = helm_pods
|
14
|
+
index = 0
|
15
|
+
if pods.count > 1
|
16
|
+
puts pods.each_with_index.map { |p, i| "#{i}: #{p}" }
|
17
|
+
index = ask(msg, default: index)
|
18
|
+
end
|
19
|
+
pods[index.to_i]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'pods', 'list pods'
|
24
|
+
def pods
|
25
|
+
kubectl_run(:get, :pods, '-l', helm_selector)
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'containers', 'list containers'
|
29
|
+
def containers
|
30
|
+
columns = 'NAME:.metadata.name,CONTAINERS:.spec.containers[*].name'
|
31
|
+
kubectl_run(:get, :pods, '-o', "custom-columns=#{columns}", '-l', helm_selector)
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'logs [OPTIONS]', 'run kubectl logs with same options'
|
35
|
+
def logs(*args)
|
36
|
+
trap('SIGINT', 'EXIT') # clean exit with ctrl-c
|
37
|
+
args = [ '--all-containers', '--prefix', '--follow' ] if args.empty? # helpful default args
|
38
|
+
kubectl_run(:logs, '-l', helm_selector, *args)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'exec [CMD]', 'exec command in a web pod'
|
42
|
+
def exec(cmd = 'sh')
|
43
|
+
pod = helm_ask_pod('choose a pod')
|
44
|
+
kubectl_run(:exec, '-it', pod, '--', cmd)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/stax/helm/stern.rb
CHANGED
@@ -16,7 +16,8 @@ module Stax
|
|
16
16
|
## pass through args to stern
|
17
17
|
desc 'stern [STERN_ARGS]', 'use stern to show logs'
|
18
18
|
def stern(*args)
|
19
|
-
|
19
|
+
trap('SIGINT', 'EXIT') # clean exit with ctrl-c
|
20
|
+
stern_run('-l', helm_selector, *args)
|
20
21
|
end
|
21
22
|
|
22
23
|
end
|
data/lib/stax/helm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stax-helm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,8 +67,12 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
69
|
- lib/stax/helm.rb
|
70
|
+
- lib/stax/helm/base.rb
|
70
71
|
- lib/stax/helm/cmd.rb
|
72
|
+
- lib/stax/helm/deployment.rb
|
73
|
+
- lib/stax/helm/ingress.rb
|
71
74
|
- lib/stax/helm/kubectl.rb
|
75
|
+
- lib/stax/helm/pod.rb
|
72
76
|
- lib/stax/helm/stern.rb
|
73
77
|
- lib/stax/helm/version.rb
|
74
78
|
- stax-helm.gemspec
|
@@ -76,7 +80,7 @@ homepage: https://github.com/rlister/stax-helm
|
|
76
80
|
licenses:
|
77
81
|
- MIT
|
78
82
|
metadata: {}
|
79
|
-
post_install_message:
|
83
|
+
post_install_message:
|
80
84
|
rdoc_options: []
|
81
85
|
require_paths:
|
82
86
|
- lib
|
@@ -92,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
96
|
version: '0'
|
93
97
|
requirements: []
|
94
98
|
rubygems_version: 3.0.3
|
95
|
-
signing_key:
|
99
|
+
signing_key:
|
96
100
|
specification_version: 4
|
97
101
|
summary: Control helm charts with stax.
|
98
102
|
test_files: []
|