Class: Rhelm::Subcommand::Base
- Inherits:
-
Object
- Object
- Rhelm::Subcommand::Base
- Defined in:
- lib/rhelm/subcommand/base.rb
Overview
Abstract base class for Helm subcommands.
Direct Known Subclasses
Dependency, Env, History, Install, Lint, List, Pull, Rollback, Status, Test, Uninstall, Upgrade, Verify, Version
Defined Under Namespace
Classes: OptionError
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#kube_apiserver ⇒ Object
readonly
Returns the value of attribute kube_apiserver.
-
#kube_as_group ⇒ Object
readonly
Returns the value of attribute kube_as_group.
-
#kube_as_user ⇒ Object
readonly
Returns the value of attribute kube_as_user.
-
#kube_context ⇒ Object
readonly
Returns the value of attribute kube_context.
-
#kube_token ⇒ Object
readonly
Returns the value of attribute kube_token.
-
#kubeconfig ⇒ Object
readonly
Returns the value of attribute kubeconfig.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#registry_config ⇒ Object
readonly
Returns the value of attribute registry_config.
-
#repository_cache ⇒ Object
readonly
Returns the value of attribute repository_cache.
-
#repository_config ⇒ Object
readonly
Returns the value of attribute repository_config.
Instance Method Summary collapse
- #args ⇒ Object
- #cli_args ⇒ Object
- #full_cli_call ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #report_failure(lines, status, and_raise: true) ⇒ Object
- #run(client: nil, raise_on_error: true, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rhelm/subcommand/base.rb', line 22 def initialize( = {}) @client = .delete(:client) || Client.new @debug = [:debug] @kube_apiserver = [:kube_apiserver] @kube_as_group = [:kube_as_group] @kube_as_user = [:kube_as_user] @kube_context = [:kube_context] @kube_token = [:kube_token] @kubeconfig = [:kubeconfig] @namespace = [:namespace] @registry_config = [:registry_config] @repository_cache = [:repository_cache] @repository_config = [:repository_config] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def client @client end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def debug @debug end |
#kube_apiserver ⇒ Object (readonly)
Returns the value of attribute kube_apiserver.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def kube_apiserver @kube_apiserver end |
#kube_as_group ⇒ Object (readonly)
Returns the value of attribute kube_as_group.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def kube_as_group @kube_as_group end |
#kube_as_user ⇒ Object (readonly)
Returns the value of attribute kube_as_user.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def kube_as_user @kube_as_user end |
#kube_context ⇒ Object (readonly)
Returns the value of attribute kube_context.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def kube_context @kube_context end |
#kube_token ⇒ Object (readonly)
Returns the value of attribute kube_token.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def kube_token @kube_token end |
#kubeconfig ⇒ Object (readonly)
Returns the value of attribute kubeconfig.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def kubeconfig @kubeconfig end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def namespace @namespace end |
#registry_config ⇒ Object (readonly)
Returns the value of attribute registry_config.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def registry_config @registry_config end |
#repository_cache ⇒ Object (readonly)
Returns the value of attribute repository_cache.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def repository_cache @repository_cache end |
#repository_config ⇒ Object (readonly)
Returns the value of attribute repository_config.
9 10 11 |
# File 'lib/rhelm/subcommand/base.rb', line 9 def repository_config @repository_config end |
Instance Method Details
#args ⇒ Object
61 62 63 |
# File 'lib/rhelm/subcommand/base.rb', line 61 def args [subcommand_name, cli_args].flatten end |
#cli_args ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rhelm/subcommand/base.rb', line 46 def cli_args [].tap do |args| args << "--debug" if debug args << ["--kube-apiserver", kube_apiserver] if kube_apiserver args << ["--kube-as-group", kube_as_group ] if kube_as_group args << ["--kube-context", kube_context] if kube_context args << ["--kube-token", kube_token] if kube_token args << ["--kubeconfig", kubeconfig ] if kubeconfig args << ["--namespace", namespace] if namespace args << ["--registry-config", registry_config] if registry_config args << ["--repository-cache", repository_cache] if repository_cache args << ["--repository-config", repository_config] if repository_config end.flatten end |
#full_cli_call ⇒ Object
65 66 67 |
# File 'lib/rhelm/subcommand/base.rb', line 65 def full_cli_call [@client.program, args].flatten.map(&:to_s) end |
#report_failure(lines, status, and_raise: true) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rhelm/subcommand/base.rb', line 69 def report_failure(lines, status, and_raise: true) sanitized_full_cli_call = full_cli_call kube_token_index = sanitized_full_cli_call.find_index("--kube-token") sanitized_full_cli_call[kube_token_index + 1] = "[REDACTED]" if kube_token_index preamble = "#{sanitized_full_cli_call} failed with exit status #{status}. Output follows:" if @client.logger client.logger.error(preamble) client.logger.error(lines) else STDERR.puts premable STDERR.puts lines end raise(Error, "#{sanitized_full_cli_call} failed with exit_status #{status}") if and_raise end |
#run(client: nil, raise_on_error: true, &block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rhelm/subcommand/base.rb', line 37 def run(client: nil, raise_on_error: true, &block) b = block_given? ? block : Proc.new { |_lines, status| status } lines, status = Open3.capture2e(*full_cli_call) report_failure(lines, status.exitstatus) if raise_on_error && status.exitstatus != 0 b.yield lines, status.exitstatus end |