stax-helm 0.0.7 → 0.0.11
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/base.rb +1 -1
- data/lib/stax/helm/cronjobs.rb +13 -0
- data/lib/stax/helm/jobs.rb +13 -0
- data/lib/stax/helm/runcmd.rb +109 -0
- data/lib/stax/helm/version.rb +1 -1
- data/lib/stax/helm.rb +3 -0
- data/stax-helm.gemspec +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e468498945819346be38bcecf9196c53f1710899e8d2818ba24e6e8d39e99f73
|
4
|
+
data.tar.gz: d63fcefed8ded8b86229794205e06fe9b7d3b83d61e0f29223e993219171e32d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca3ffab05c1866c546deaf0a8fac5361ecdadecdd6a2bebc5bb9b46321b6a36824680c36a9294288b5007dd5903b86d89ea435ea5d42c45ee88f3f195c58f1d1
|
7
|
+
data.tar.gz: f0f59bceb82dee3cd0f9b8ef236e49b7c4f7b6737218ba76d6c79c107f38aa15dc099847467bcbfa234fbd8a3a74686cc49d45d03aa6243e7349e41df5fe5538
|
data/lib/stax/helm/base.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Stax
|
4
|
+
module Helm
|
5
|
+
class Cmd
|
6
|
+
|
7
|
+
no_commands do
|
8
|
+
## construct a Job template
|
9
|
+
def helm_run_template(name)
|
10
|
+
{
|
11
|
+
apiVersion: 'batch/v1',
|
12
|
+
kind: :Job,
|
13
|
+
metadata: {
|
14
|
+
name: name,
|
15
|
+
labels: {
|
16
|
+
'app.kubernetes.io/managed-by' => :stax
|
17
|
+
}
|
18
|
+
},
|
19
|
+
spec: {
|
20
|
+
template: {
|
21
|
+
spec: {
|
22
|
+
restartPolicy: :Never
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
## Deployment to clone for container
|
30
|
+
def helm_run_deployment
|
31
|
+
"#{helm_release_name}-web"
|
32
|
+
end
|
33
|
+
|
34
|
+
## name of container to clone from Deployment
|
35
|
+
def helm_run_container
|
36
|
+
'web'
|
37
|
+
end
|
38
|
+
|
39
|
+
## name for Job to create based on container
|
40
|
+
def helm_run_job
|
41
|
+
"#{helm_release_name}-run-#{SecureRandom.hex(4)}"
|
42
|
+
end
|
43
|
+
|
44
|
+
## default command to run
|
45
|
+
def helm_run_cmd
|
46
|
+
'bash'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
## task creates a dedicated unique kubernetes Job, with
|
51
|
+
## container spec based on the helm release deployment
|
52
|
+
## requested, then does an interactive exec to the pod and
|
53
|
+
## container created, and deletes the Job on exit
|
54
|
+
desc 'runcmd [CMD]', 'run dedicated interactive container'
|
55
|
+
method_option :sleep, type: :string, default: '1h', description: 'kill container after time'
|
56
|
+
method_option :keep, type: :boolean, default: false, description: 'do not delete job'
|
57
|
+
def runcmd(*cmd)
|
58
|
+
## use default if not set
|
59
|
+
cmd = Array(helm_run_cmd) if cmd.empty?
|
60
|
+
|
61
|
+
## name of k8s Job to create, and basic template
|
62
|
+
job = helm_run_job
|
63
|
+
template = helm_run_template(job)
|
64
|
+
|
65
|
+
## get deployment and extract container spec
|
66
|
+
deployment = kubectl_json(:get, :deployment, helm_run_deployment)
|
67
|
+
spec = deployment.dig('spec', 'template', 'spec', 'containers').find do |c|
|
68
|
+
c['name'] == helm_run_container
|
69
|
+
end
|
70
|
+
|
71
|
+
## cleanup the container spec so we can use it in a Job
|
72
|
+
spec.delete('livenessProbe')
|
73
|
+
spec.delete('readinessProbe')
|
74
|
+
spec.delete('startupProbe')
|
75
|
+
spec.delete('volumeMounts')
|
76
|
+
spec['name'] = 'run'
|
77
|
+
spec['args'] = ['sleep', options[:sleep]]
|
78
|
+
|
79
|
+
## add container to Job template
|
80
|
+
template[:spec][:template][:spec][:containers] = [ spec ]
|
81
|
+
|
82
|
+
## get service account and add to template
|
83
|
+
service_account = deployment.dig('spec', 'template', 'spec', 'serviceAccountName')
|
84
|
+
template[:spec][:template][:spec][:serviceAccountName] = service_account if service_account
|
85
|
+
|
86
|
+
## create new unique Job based on the container spec
|
87
|
+
debug("Creating job #{job}")
|
88
|
+
Open3.popen2('kubectl create -f -') { |stdin, stdout, _|
|
89
|
+
stdin.print(template.to_json)
|
90
|
+
stdin.close
|
91
|
+
puts stdout.gets
|
92
|
+
}
|
93
|
+
|
94
|
+
## get name of the Pod created by the Job
|
95
|
+
pod = kubectl_json(:get, :pod, '-l', "job-name=#{job}")['items'].first['metadata']['name']
|
96
|
+
|
97
|
+
## exec into the pod and run interactive command
|
98
|
+
debug("Connecting to pod #{pod}")
|
99
|
+
kubectl_run(:wait, '--for=condition=Ready', '--timeout=5m', :pod, pod)
|
100
|
+
kubectl_run(:exec, '-it', pod, '--', *cmd)
|
101
|
+
rescue JSON::ParserError
|
102
|
+
fail_task('cannot get kubernetes resource')
|
103
|
+
ensure
|
104
|
+
## delete Job
|
105
|
+
kubectl_run(:delete, :job, job) unless options[:keep]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/stax/helm/version.rb
CHANGED
data/lib/stax/helm.rb
CHANGED
@@ -4,5 +4,8 @@ require 'stax/helm/kubectl'
|
|
4
4
|
require 'stax/helm/ingress'
|
5
5
|
require 'stax/helm/pod'
|
6
6
|
require 'stax/helm/deployment'
|
7
|
+
require 'stax/helm/jobs'
|
8
|
+
require 'stax/helm/cronjobs'
|
7
9
|
require 'stax/helm/stern'
|
10
|
+
require 'stax/helm/runcmd'
|
8
11
|
Stax.add_command(:helm, Stax::Helm::Cmd)
|
data/stax-helm.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
25
25
|
spec.add_development_dependency 'rake', '>= 12.3.3'
|
26
26
|
|
27
27
|
spec.add_dependency('stax')
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,10 +69,13 @@ files:
|
|
69
69
|
- lib/stax/helm.rb
|
70
70
|
- lib/stax/helm/base.rb
|
71
71
|
- lib/stax/helm/cmd.rb
|
72
|
+
- lib/stax/helm/cronjobs.rb
|
72
73
|
- lib/stax/helm/deployment.rb
|
73
74
|
- lib/stax/helm/ingress.rb
|
75
|
+
- lib/stax/helm/jobs.rb
|
74
76
|
- lib/stax/helm/kubectl.rb
|
75
77
|
- lib/stax/helm/pod.rb
|
78
|
+
- lib/stax/helm/runcmd.rb
|
76
79
|
- lib/stax/helm/stern.rb
|
77
80
|
- lib/stax/helm/version.rb
|
78
81
|
- stax-helm.gemspec
|
@@ -95,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: '0'
|
97
100
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.1.4
|
99
102
|
signing_key:
|
100
103
|
specification_version: 4
|
101
104
|
summary: Control helm charts with stax.
|