Class: Dapp::Kube::Helm::Release
- Inherits:
-
Object
- Object
- Dapp::Kube::Helm::Release
- Includes:
- Helper::YAML
- Defined in:
- lib/dapp/kube/helm/release.rb
Instance Attribute Summary collapse
-
#chart_path ⇒ Object
readonly
Returns the value of attribute chart_path.
-
#dapp ⇒ Object
readonly
Returns the value of attribute dapp.
-
#deploy_timeout ⇒ Object
readonly
Returns the value of attribute deploy_timeout.
-
#docker_tag ⇒ Object
readonly
Returns the value of attribute docker_tag.
-
#kube_context ⇒ Object
readonly
Returns the value of attribute kube_context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
-
#without_registry ⇒ Object
readonly
Returns the value of attribute without_registry.
Instance Method Summary collapse
- #deployments ⇒ Object
- #hooks ⇒ Object
-
#initialize(dapp, name:, repo:, docker_tag:, namespace:, chart_path:, set: [], values: [], deploy_timeout: nil, without_registry: nil, kube_context: nil) ⇒ Release
constructor
A new instance of Release.
- #install_helm_release ⇒ Object
- #jobs ⇒ Object
- #lint! ⇒ Object
- #templates ⇒ Object
- #upgrade_helm_release ⇒ Object
Methods included from Helper::YAML
Constructor Details
#initialize(dapp, name:, repo:, docker_tag:, namespace:, chart_path:, set: [], values: [], deploy_timeout: nil, without_registry: nil, kube_context: nil) ⇒ Release
Returns a new instance of Release.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dapp/kube/helm/release.rb', line 19 def initialize(dapp, name:, repo:, docker_tag:, namespace:, chart_path:, set: [], values: [], deploy_timeout: nil, without_registry: nil, kube_context: nil) @dapp = dapp @name = name @repo = repo @docker_tag = docker_tag @namespace = namespace @chart_path = chart_path @set = set @values = values @deploy_timeout = deploy_timeout @without_registry = (without_registry.nil? ? false : without_registry) @kube_context = kube_context end |
Instance Attribute Details
#chart_path ⇒ Object (readonly)
Returns the value of attribute chart_path.
12 13 14 |
# File 'lib/dapp/kube/helm/release.rb', line 12 def chart_path @chart_path end |
#dapp ⇒ Object (readonly)
Returns the value of attribute dapp.
6 7 8 |
# File 'lib/dapp/kube/helm/release.rb', line 6 def dapp @dapp end |
#deploy_timeout ⇒ Object (readonly)
Returns the value of attribute deploy_timeout.
15 16 17 |
# File 'lib/dapp/kube/helm/release.rb', line 15 def deploy_timeout @deploy_timeout end |
#docker_tag ⇒ Object (readonly)
Returns the value of attribute docker_tag.
10 11 12 |
# File 'lib/dapp/kube/helm/release.rb', line 10 def docker_tag @docker_tag end |
#kube_context ⇒ Object (readonly)
Returns the value of attribute kube_context.
17 18 19 |
# File 'lib/dapp/kube/helm/release.rb', line 17 def kube_context @kube_context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/dapp/kube/helm/release.rb', line 8 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/dapp/kube/helm/release.rb', line 11 def namespace @namespace end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
9 10 11 |
# File 'lib/dapp/kube/helm/release.rb', line 9 def repo @repo end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
13 14 15 |
# File 'lib/dapp/kube/helm/release.rb', line 13 def set @set end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
14 15 16 |
# File 'lib/dapp/kube/helm/release.rb', line 14 def values @values end |
#without_registry ⇒ Object (readonly)
Returns the value of attribute without_registry.
16 17 18 |
# File 'lib/dapp/kube/helm/release.rb', line 16 def without_registry @without_registry end |
Instance Method Details
#deployments ⇒ Object
48 49 50 51 52 |
# File 'lib/dapp/kube/helm/release.rb', line 48 def deployments (resources_specs['Deployment'] || {}).map do |name, spec| [name, Kubernetes::Client::Resource::Deployment.new(spec)] end.to_h end |
#hooks ⇒ Object
42 43 44 45 46 |
# File 'lib/dapp/kube/helm/release.rb', line 42 def hooks jobs.select do |_, spec| spec.annotations.key? "helm.sh/hook" end end |
#install_helm_release ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dapp/kube/helm/release.rb', line 54 def install_helm_release unless dapp.dry_run? dapp.kubernetes.create_namespace!(namespace) unless dapp.kubernetes.namespace?(namespace) end cmd = dapp.shellout([ "helm install #{chart_path}", "--name #{name}", *, *, *, ("--kube-context #{kube_context}" if kube_context), ].join(" ")) return cmd end |
#jobs ⇒ Object
36 37 38 39 40 |
# File 'lib/dapp/kube/helm/release.rb', line 36 def jobs (resources_specs['Job'] || {}).map do |name, spec| [name, Kubernetes::Client::Resource::Job.new(spec)] end.to_h end |
#lint! ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dapp/kube/helm/release.rb', line 106 def lint! dapp.shellout! [ 'helm', 'lint', '--strict', *, *(fake: true), *, ("--kube-context #{kube_context}" if kube_context), chart_path ].compact.join(' ') end |
#templates ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dapp/kube/helm/release.rb', line 83 def templates @templates ||= {}.tap do |t| current_template = nil spec = 0 evaluation_output.lines.each do |l| if (match = l[/# Source: (.*)/, 1]) spec = 0 t[current_template = match] ||= [] end if l[/^---$/] spec += 1 elsif current_template (t[current_template][spec] ||= []) << l end end t.each do |template, specs| t[template] = "---\n#{specs.reject(&:nil?).map(&:join).join("---\n").strip}" end end end |
#upgrade_helm_release ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dapp/kube/helm/release.rb', line 71 def upgrade_helm_release cmd = dapp.shellout([ "helm upgrade #{name} #{chart_path}", *, *, *, ("--kube-context #{kube_context}" if kube_context), ].join(" ")) return cmd end |