stax-helm 0.0.1 → 0.0.6

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: a39d86691aa95175038ebb17eea1a61d0c5c10c494de2a620cfa896621c646a5
4
- data.tar.gz: 0bb2e82a0901daf51b69aaff4eda6b34edf8b77f2feecd991b127b797a0c2d86
3
+ metadata.gz: 7beb0767d7b08899165a52b8e58886c667a3d4d74a1a9e0e5918d599d0e755f8
4
+ data.tar.gz: 913a768e730ccdb511c1e2477d25d0b4438e1f14cdd81bd79099fd1766ccf1ba
5
5
  SHA512:
6
- metadata.gz: 7c13bf85d7e78a3ae7494fb56d89cda5e7366d660c8b92bf7065dd859ba2b04761ef35db2e93a835a2f0945f629664fc53e495866e3fc639fb9264e5e59ade58
7
- data.tar.gz: 13e34d76337048c8ab014427139f4f9f4373c1561ae29ee78b0b6a7ab4f0526d159557cb39f9f0fec97b359b6150d31d552d259b345f0a08c1faedb2b927c629
6
+ metadata.gz: 7b8aee9ce577d1ec38b3a33ce446ff00f44bde274bae2aa0b8cf5934eebae30f7831683c0ac8b79e6330951cacc98e3aa8b78e1f50fff31bffab5fbb90ca0283
7
+ data.tar.gz: 566b8097eb9e92660459b4cc252b7aa3c922df810417435a578c6a7d183111c6a70bc00322e6ee1e20a324ab7ada73b076cc7b11649343a0ac21c421ccde4dfc
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Stax::Helm
2
2
 
3
+ [Stax](https://github.com/rlister/stax) is a highly-opionated framework for managing Cloudformation stacks.
4
+
5
+ Stax::Helm is highly-opionated framework for managing helm releases alongside their supporting Cloudformation stacks
6
+
3
7
  ## Installation
4
8
 
5
9
  Add this line to your application's Gemfile:
@@ -16,24 +20,32 @@ Or install it yourself as:
16
20
 
17
21
  $ gem install stax-helm
18
22
 
19
- ## Usage
23
+ ## Opinions
20
24
 
21
- TODO: Write usage instructions here
25
+ - you have one chart per application repo
26
+ - chart lives in `helm` dir alongside your `Staxfile`
27
+ - objects are labeled per the suggestions in
28
+ https://helm.sh/docs/chart_best_practices/labels/ and
29
+ https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
22
30
 
23
- ## Development
31
+ ## Usage
24
32
 
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+ In your `Staxfile` add:
26
34
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+ ```ruby
36
+ require 'stax/helm'
37
+ ```
28
38
 
29
- ## Contributing
39
+ and use commands like:
30
40
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/rlister/stax-helm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
41
+ ```
42
+ stax helm create
43
+ stax helm update
44
+ stax helm delete
45
+ ```
46
+
47
+ See inline help for other tasks.
32
48
 
33
49
  ## License
34
50
 
35
51
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the Stax::Helm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rlister/stax-helm/blob/master/CODE_OF_CONDUCT.md).
@@ -1,2 +1,8 @@
1
+ require 'stax/helm/base'
1
2
  require 'stax/helm/cmd'
3
+ require 'stax/helm/kubectl'
4
+ require 'stax/helm/ingress'
5
+ require 'stax/helm/pod'
6
+ require 'stax/helm/deployment'
7
+ require 'stax/helm/stern'
2
8
  Stax.add_command(:helm, Stax::Helm::Cmd)
@@ -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
@@ -1,13 +1,10 @@
1
1
  module Stax
2
2
  module Helm
3
+
3
4
  class Cmd < Base
4
- class_option :dry_run, type: :boolean, default: false, desc: 'print command that would be run'
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[:dry_run] ? puts(cmd) : system(cmd)
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
@@ -86,6 +89,11 @@ module Stax
86
89
  helm_run(:rollback, helm_release_name, revision)
87
90
  end
88
91
 
92
+ desc 'ls', 'list helm release'
93
+ def ls
94
+ helm_run(:ls, "--filter '^#{helm_release_name}$'")
95
+ end
96
+
89
97
  end
90
98
  end
91
99
  end
@@ -0,0 +1,41 @@
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
+ end
40
+ end
41
+ 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
@@ -0,0 +1,28 @@
1
+ module Stax
2
+ module Helm
3
+ class Cmd < Base
4
+
5
+ no_commands do
6
+ def kubectl_bin
7
+ 'kubectl'
8
+ end
9
+
10
+ def kubectl_run(*args)
11
+ cmd = [kubectl_bin, *args].join(' ')
12
+ options[:recon] ? puts(cmd) : system(cmd)
13
+ end
14
+
15
+ ## override this to match all objects in your helm release
16
+ def helm_selector
17
+ "app.kubernetes.io/instance=#{helm_release_name}"
18
+ end
19
+ end
20
+
21
+ desc 'services', 'list services'
22
+ def services
23
+ kubectl_run(:get, :services, '-l', helm_selector)
24
+ end
25
+
26
+ end
27
+ end
28
+ 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
@@ -0,0 +1,25 @@
1
+ module Stax
2
+ module Helm
3
+ class Cmd < Base
4
+
5
+ no_commands do
6
+ def stern_bin
7
+ 'stern'
8
+ end
9
+
10
+ def stern_run(*args)
11
+ cmd = [stern_bin, *args].join(' ')
12
+ options[:dry_run] ? puts(cmd) : system(cmd)
13
+ end
14
+ end
15
+
16
+ ## pass through args to stern
17
+ desc 'stern [STERN_ARGS]', 'use stern to show logs'
18
+ def stern(*args)
19
+ trap('SIGINT', 'EXIT') # clean exit with ctrl-c
20
+ stern_run('-l', helm_selector, *args)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Stax
2
2
  module Helm
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
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.1
4
+ version: 0.0.6
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-05-24 00:00:00.000000000 Z
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,14 +67,20 @@ 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
74
+ - lib/stax/helm/kubectl.rb
75
+ - lib/stax/helm/pod.rb
76
+ - lib/stax/helm/stern.rb
71
77
  - lib/stax/helm/version.rb
72
78
  - stax-helm.gemspec
73
79
  homepage: https://github.com/rlister/stax-helm
74
80
  licenses:
75
81
  - MIT
76
82
  metadata: {}
77
- post_install_message:
83
+ post_install_message:
78
84
  rdoc_options: []
79
85
  require_paths:
80
86
  - lib
@@ -90,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
96
  version: '0'
91
97
  requirements: []
92
98
  rubygems_version: 3.0.3
93
- signing_key:
99
+ signing_key:
94
100
  specification_version: 4
95
101
  summary: Control helm charts with stax.
96
102
  test_files: []