helm-wrapper 0.1.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 +7 -0
- data/.gitignore +28 -0
- data/.gitlab-ci.yml +37 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +13 -0
- data/bin/console +16 -0
- data/bin/setup +18 -0
- data/helm-wrapper.gemspec +38 -0
- data/lib/helm-wrapper.rb +59 -0
- data/lib/helm-wrapper/common.rb +27 -0
- data/lib/helm-wrapper/shared.rb +16 -0
- data/lib/helm-wrapper/shared/auths.rb +9 -0
- data/lib/helm-wrapper/shared/auths/azure.rb +176 -0
- data/lib/helm-wrapper/shared/auths/common.rb +91 -0
- data/lib/helm-wrapper/shared/binary.rb +113 -0
- data/lib/helm-wrapper/shared/chart.rb +120 -0
- data/lib/helm-wrapper/shared/config.rb +145 -0
- data/lib/helm-wrapper/shared/latest.rb +79 -0
- data/lib/helm-wrapper/shared/logger.rb +80 -0
- data/lib/helm-wrapper/shared/logging.rb +77 -0
- data/lib/helm-wrapper/shared/runner.rb +250 -0
- data/lib/helm-wrapper/shared/variables.rb +66 -0
- data/lib/helm-wrapper/tasks.rb +11 -0
- data/lib/helm-wrapper/tasks/apply.rb +72 -0
- data/lib/helm-wrapper/tasks/binary.rb +195 -0
- data/lib/helm-wrapper/tasks/destroy.rb +70 -0
- data/lib/helm-wrapper/version.rb +13 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c3da406ae1f3c001d4b51c4f649f63f303c36b974190a94da96eac15a9fcb4aa
|
4
|
+
data.tar.gz: 22d5e3f7ba99bcdbc33b547630d8b7e48a347ebdf5e99773e9335277374c7eea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec9bf88db860c8e788f4c00a2216acd695b6de238f23c1e98ea90bb969523f8a60a721cdebce64d5c7629f61b2179d2194eadd446c6faeae8f261c976f0e09fd
|
7
|
+
data.tar.gz: 2e04c841ef35f60edcf7a2fa934b0f1f92af7b73970d431e501bccdf89a8a92fcfbf7d9a97cd57dc53ea62cde23351fe0f74ac1317d8e02dba842273a7b7edb5
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
**/*.DS_Store
|
4
|
+
**/*.swp
|
5
|
+
**/*.tmp
|
6
|
+
**/*~
|
7
|
+
|
8
|
+
###############################################################################
|
9
|
+
|
10
|
+
.idea
|
11
|
+
|
12
|
+
###############################################################################
|
13
|
+
|
14
|
+
/.bundle/
|
15
|
+
/.yardoc
|
16
|
+
/_yardoc/
|
17
|
+
/coverage/
|
18
|
+
/doc/
|
19
|
+
/pkg/
|
20
|
+
/spec/reports/
|
21
|
+
/tmp/
|
22
|
+
|
23
|
+
###############################################################################
|
24
|
+
|
25
|
+
/archlinux/
|
26
|
+
!/archlinux/PKGBUILD
|
27
|
+
|
28
|
+
###############################################################################
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
image: ruby
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
stages:
|
8
|
+
- test
|
9
|
+
- publish
|
10
|
+
|
11
|
+
###############################################################################
|
12
|
+
|
13
|
+
test:
|
14
|
+
stage : test
|
15
|
+
script:
|
16
|
+
- echo "-- Beginning Test --"
|
17
|
+
- echo "-- Tests not implemented yet --"
|
18
|
+
|
19
|
+
###############################################################################
|
20
|
+
|
21
|
+
deploy:
|
22
|
+
rules:
|
23
|
+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
|
24
|
+
stage: publish
|
25
|
+
script:
|
26
|
+
- echo "-- Beginning Publish --"
|
27
|
+
- test -n "${GEM_HOST_API_KEY}"
|
28
|
+
- echo "RubyGems API key found!"
|
29
|
+
- hash rake
|
30
|
+
- hash ruby
|
31
|
+
- hash gem
|
32
|
+
- echo "-- Publishing Gem --"
|
33
|
+
- rake release
|
34
|
+
- echo "-- Listing Sums --"
|
35
|
+
- sha256sum "pkg"/*.gem
|
36
|
+
|
37
|
+
###############################################################################
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
source "https://rubygems.org"
|
8
|
+
|
9
|
+
###############################################################################
|
10
|
+
|
11
|
+
gemspec
|
12
|
+
|
13
|
+
###############################################################################
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Richard Lees, BITServices Ltd.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
require "bundler/gem_tasks"
|
8
|
+
|
9
|
+
###############################################################################
|
10
|
+
|
11
|
+
task default: %i[]
|
12
|
+
|
13
|
+
###############################################################################
|
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
###############################################################################
|
3
|
+
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
###############################################################################
|
7
|
+
|
8
|
+
require "bundler/setup"
|
9
|
+
require "irb"
|
10
|
+
require "helm-wrapper"
|
11
|
+
|
12
|
+
###############################################################################
|
13
|
+
|
14
|
+
IRB.start(__FILE__)
|
15
|
+
|
16
|
+
###############################################################################
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
###############################################################################
|
3
|
+
|
4
|
+
set -euo pipefail
|
5
|
+
|
6
|
+
###############################################################################
|
7
|
+
|
8
|
+
IFS=$'\n\t'
|
9
|
+
|
10
|
+
###############################################################################
|
11
|
+
|
12
|
+
set -vx
|
13
|
+
|
14
|
+
###############################################################################
|
15
|
+
|
16
|
+
bundle install
|
17
|
+
|
18
|
+
###############################################################################
|
@@ -0,0 +1,38 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
require_relative "lib/helm-wrapper/version"
|
8
|
+
|
9
|
+
###############################################################################
|
10
|
+
|
11
|
+
Gem::Specification.new do |spec|
|
12
|
+
spec.name = "helm-wrapper"
|
13
|
+
spec.version = HelmWrapper::VERSION
|
14
|
+
spec.authors = ["Richard Lees"]
|
15
|
+
spec.email = ["git0@bitservices.io"]
|
16
|
+
|
17
|
+
spec.summary = "A ruby wrapper for managing Helm binaries and chart deployment."
|
18
|
+
spec.description = "A ruby wrapper for managing Helm binaries and chart deployment. Helm Wrapper also supports authenticating with specific Kubernetes clusters."
|
19
|
+
spec.homepage = "https://gitlab.com/rlees85-ruby/helm-wrapper/"
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
23
|
+
|
24
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
25
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
26
|
+
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:archlinux|test|spec|features)/}) or f.match(%r{\Aavatar(?:_group)?\.png\z}) }
|
29
|
+
end
|
30
|
+
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_dependency 'rake', '~> 13.0'
|
36
|
+
end
|
37
|
+
|
38
|
+
###############################################################################
|
data/lib/helm-wrapper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
require_relative 'helm-wrapper/shared'
|
4
|
+
require_relative 'helm-wrapper/tasks'
|
5
|
+
require_relative 'helm-wrapper/version'
|
6
|
+
|
7
|
+
###############################################################################
|
8
|
+
|
9
|
+
require_relative 'helm-wrapper/common'
|
10
|
+
|
11
|
+
###############################################################################
|
12
|
+
|
13
|
+
module HelmWrapper
|
14
|
+
|
15
|
+
###############################################################################
|
16
|
+
|
17
|
+
@logger = HelmWrapper::Shared::Logging.logger_for("HelmWrapper")
|
18
|
+
|
19
|
+
###############################################################################
|
20
|
+
|
21
|
+
@logger.info("Helm Wrapper for Ruby - version: #{HelmWrapper::VERSION}")
|
22
|
+
|
23
|
+
###############################################################################
|
24
|
+
|
25
|
+
def self.define_tasks(chart:, namespace:, release:, options: Hash.new)
|
26
|
+
@logger.info("Building tasks for chart: #{chart}...")
|
27
|
+
|
28
|
+
@logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
|
29
|
+
|
30
|
+
binary_options = Hash.new
|
31
|
+
binary_options["base"] = options.key?("binary-base") ? options["binary-base"] : File.join(Dir.pwd, "vendor", "helm")
|
32
|
+
binary_options["version"] = options.key?("binary-version") ? options["binary-version"] : Shared::Latest.instance.version
|
33
|
+
|
34
|
+
chart_options = Hash.new
|
35
|
+
chart_options["name"] = chart
|
36
|
+
chart_options["repos"] = options.key?("chart-repos") ? options["chart-repos"] : Array.new
|
37
|
+
|
38
|
+
config_options = Hash.new
|
39
|
+
config_options["auth-azure"] = options.key?("config-auth-azure") ? options["config-auth-azure"] : false
|
40
|
+
config_options["auth-azure-options"] = options.key?("config-auth-azure-options") ? options["config-auth-azure-options"] : Hash.new
|
41
|
+
config_options["base"] = options.key?("config-base") ? options["config-base"] : File.join(Dir.pwd, "config")
|
42
|
+
config_options["namespace"] = namespace
|
43
|
+
config_options["release"] = release
|
44
|
+
|
45
|
+
binary = HelmWrapper::Shared::Binary.new(options: binary_options)
|
46
|
+
chart = HelmWrapper::Shared::Chart.new(options: chart_options)
|
47
|
+
|
48
|
+
tasks = Array.new
|
49
|
+
tasks << HelmWrapper::Tasks::Apply.new(binary: binary, chart: chart, options: config_options)
|
50
|
+
tasks << HelmWrapper::Tasks::Binary.new(binary: binary)
|
51
|
+
tasks << HelmWrapper::Tasks::Destroy.new(binary: binary, chart: chart, options: config_options)
|
52
|
+
return tasks
|
53
|
+
end
|
54
|
+
|
55
|
+
###############################################################################
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
###############################################################################
|
@@ -0,0 +1,27 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
module HelmWrapper
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
def self.create_directory(directory:, purpose: nil, exists: true)
|
8
|
+
return exists if File.directory?(directory)
|
9
|
+
|
10
|
+
result = false
|
11
|
+
|
12
|
+
if not purpose.nil? and purpose.kind_of?(String) and not purpose.strip.empty? then
|
13
|
+
@logger.info("Creating directory for: #{purpose}, path: #{directory}")
|
14
|
+
else
|
15
|
+
@logger.info("Creating directory: #{directory}")
|
16
|
+
end
|
17
|
+
|
18
|
+
FileUtils.mkdir_p(directory)
|
19
|
+
|
20
|
+
result = File.directory?(directory)
|
21
|
+
end
|
22
|
+
|
23
|
+
###############################################################################
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
###############################################################################
|
@@ -0,0 +1,16 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
require_relative 'shared/logger'
|
4
|
+
require_relative 'shared/logging'
|
5
|
+
|
6
|
+
###############################################################################
|
7
|
+
|
8
|
+
require_relative 'shared/auths'
|
9
|
+
require_relative 'shared/binary'
|
10
|
+
require_relative 'shared/chart'
|
11
|
+
require_relative 'shared/config'
|
12
|
+
require_relative 'shared/latest'
|
13
|
+
require_relative 'shared/runner'
|
14
|
+
require_relative 'shared/variables'
|
15
|
+
|
16
|
+
###############################################################################
|
@@ -0,0 +1,9 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
require_relative 'auths/common'
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
require_relative 'auths/azure'
|
8
|
+
|
9
|
+
###############################################################################
|
@@ -0,0 +1,176 @@
|
|
1
|
+
###############################################################################
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
###############################################################################
|
6
|
+
|
7
|
+
module HelmWrapper
|
8
|
+
|
9
|
+
###############################################################################
|
10
|
+
|
11
|
+
module Shared
|
12
|
+
|
13
|
+
###############################################################################
|
14
|
+
|
15
|
+
module Auths
|
16
|
+
|
17
|
+
###############################################################################
|
18
|
+
|
19
|
+
class Azure < Common
|
20
|
+
|
21
|
+
###############################################################################
|
22
|
+
|
23
|
+
include HelmWrapper::Shared::Logging
|
24
|
+
|
25
|
+
###############################################################################
|
26
|
+
|
27
|
+
@@az = "az"
|
28
|
+
@@type = "azure"
|
29
|
+
|
30
|
+
###############################################################################
|
31
|
+
|
32
|
+
@ca_tempfile = nil
|
33
|
+
@token = nil
|
34
|
+
|
35
|
+
###############################################################################
|
36
|
+
|
37
|
+
attr_reader :ca
|
38
|
+
attr_reader :endpoint
|
39
|
+
|
40
|
+
###############################################################################
|
41
|
+
|
42
|
+
def initialize(options:, variables:)
|
43
|
+
construct(options: options, variables: variables)
|
44
|
+
end
|
45
|
+
|
46
|
+
###############################################################################
|
47
|
+
|
48
|
+
def auth()
|
49
|
+
@ca_tempfile = Tempfile.new('helm-wrapper-auths-azure-ca')
|
50
|
+
|
51
|
+
begin
|
52
|
+
@ca_tempfile.write(ca)
|
53
|
+
ensure
|
54
|
+
@ca_tempfile.close
|
55
|
+
end
|
56
|
+
|
57
|
+
logger.success("Azure authenticator successfully written Kubernetes CA to file!")
|
58
|
+
|
59
|
+
ENV["HELM_KUBECAFILE"] = @ca_tempfile.path
|
60
|
+
ENV["HELM_KUBEAPISERVER"] = @endpoint
|
61
|
+
ENV["HELM_KUBETOKEN"] = @token
|
62
|
+
|
63
|
+
logger.success("Azure authenticator environment variables set!")
|
64
|
+
end
|
65
|
+
|
66
|
+
###############################################################################
|
67
|
+
|
68
|
+
def clear()
|
69
|
+
unless @ca_tempfile.nil?
|
70
|
+
@ca_tempfile.unlink
|
71
|
+
@ca_tempfile = nil
|
72
|
+
|
73
|
+
logger.info("Azure authenticator Kubernetes CA file cleared!")
|
74
|
+
end
|
75
|
+
|
76
|
+
ENV.delete("HELM_KUBECAFILE")
|
77
|
+
ENV.delete("HELM_KUBEAPISERVER")
|
78
|
+
ENV.delete("HELM_KUBETOKEN")
|
79
|
+
|
80
|
+
logger.info("Azure authenticator environment variables cleared!")
|
81
|
+
end
|
82
|
+
|
83
|
+
###############################################################################
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
###############################################################################
|
88
|
+
|
89
|
+
def cli()
|
90
|
+
output = logger.colour ? "jsonc" : "json"
|
91
|
+
cmdline = "\"#{@@az}\" version --output \"#{output}\""
|
92
|
+
return(system(cmdline) || false)
|
93
|
+
end
|
94
|
+
|
95
|
+
###############################################################################
|
96
|
+
|
97
|
+
def secret(vault:, name:)
|
98
|
+
logger.info("Getting secret: #{name}, from key vault: #{vault}...")
|
99
|
+
|
100
|
+
cmdline = "\"#{@@az}\" keyvault secret show --vault-name \"#{vault}\" --name \"#{name}\" --query \"value\" --output \"tsv\""
|
101
|
+
stdout = `#{cmdline}`
|
102
|
+
code = $?.exitstatus
|
103
|
+
|
104
|
+
logger.fatal("Failed to get secret: #{name} from key vault: #{vault}!") if (code != 0 or stdout.strip.empty?)
|
105
|
+
|
106
|
+
return(stdout.strip)
|
107
|
+
end
|
108
|
+
|
109
|
+
###############################################################################
|
110
|
+
|
111
|
+
def specific()
|
112
|
+
logger.fatal("Azure CLI must bpassworde installed and accessible to use the Azure authenticator.") unless cli
|
113
|
+
|
114
|
+
logger.fatal("Azure authenticator mandatory option 'keyvault' has not been set!") unless @options.key?("keyvault")
|
115
|
+
logger.fatal("Azure authenticator keyvault must be a string!") unless @options["keyvault"].kind_of?(String)
|
116
|
+
logger.fatal("Azure authenticator keyvault must not be blank!") if @options["keyvault"].strip.empty?
|
117
|
+
|
118
|
+
keyvault = @options["keyvault"]
|
119
|
+
if @options.key?("ca-certificate") then
|
120
|
+
logger.fatal("Azure authenticator keyvault certificate for Kubernetes CA must be a string!") unless @options["ca-certificate"].kind_of?(String)
|
121
|
+
logger.fatal("Azure authenticator keyvault certificate for Kubernetes CA must not be blank!") if @options["ca-certificate"].strip.empty?
|
122
|
+
|
123
|
+
ca = @options["ca-certificate"]
|
124
|
+
else
|
125
|
+
ca = "kubernetes-ca"
|
126
|
+
end
|
127
|
+
|
128
|
+
if @options.key?("endpoint-secret") then
|
129
|
+
logger.fatal("Azure authenticator keyvault secret for endpoint must be a string!") unless @options["endpoint-secret"].kind_of?(String)
|
130
|
+
logger.fatal("Azure authenticator keyvault secret for endpoint must not be blank!") if @options["endpoint-secret"].strip.empty?
|
131
|
+
|
132
|
+
endpoint = @options["endpoint-secret"]
|
133
|
+
else
|
134
|
+
endpoint = "kubernetes-endpoint"
|
135
|
+
end
|
136
|
+
|
137
|
+
if @options.key?("token-secret") then
|
138
|
+
logger.fatal("Azure authenticator keyvault secret for token must be a string!") unless @options["token-secret"].kind_of?(String)
|
139
|
+
logger.fatal("Azure authenticator keyvault secret for token must not be blank!") if @options["token-secret"].strip.empty?
|
140
|
+
|
141
|
+
token = @options["token-secret"]
|
142
|
+
else
|
143
|
+
token = "kubernetes-token"
|
144
|
+
end
|
145
|
+
|
146
|
+
begin
|
147
|
+
keyvault = keyvault % @variables.values
|
148
|
+
ca = ca % @variables.values
|
149
|
+
endpoint = endpoint % @variables.values
|
150
|
+
token = token % @variables.values
|
151
|
+
rescue
|
152
|
+
logger.fatal("Azure authenticator options contain variables that are not included in the configuration file!")
|
153
|
+
end
|
154
|
+
|
155
|
+
@ca = secret(vault: keyvault, name: ca)
|
156
|
+
@endpoint = secret(vault: keyvault, name: endpoint)
|
157
|
+
@token = secret(vault: keyvault, name: token)
|
158
|
+
end
|
159
|
+
|
160
|
+
###############################################################################
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
###############################################################################
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
###############################################################################
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
###############################################################################
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
###############################################################################
|