class Hippo::Package
Public Class Methods
new(options, stage)
click to toggle source
# File lib/hippo/package.rb, line 8 def initialize(options, stage) @options = options @stage = stage end
Private Class Methods
setup_from_cli_context(context)
click to toggle source
# File lib/hippo/package.rb, line 119 def setup_from_cli_context(context) cli = Hippo::CLI.setup(context) package_name = context.options[:package] if package_name.nil? || package_name.empty? raise Error, 'A package name must be provided in -p or --package' end package = cli.stage.packages[package_name] if package.nil? raise Error, "No package named '#{package_name}' has been defined" end [package, cli] end
Public Instance Methods
chart_version()
click to toggle source
Return the version of the chart to be used
@return [String]
# File lib/hippo/package.rb, line 32 def chart_version @options['chart_version'] end
final_values()
click to toggle source
Compile a set of final values which should be used when upgrading and installing this package.
@return [Hash]
# File lib/hippo/package.rb, line 47 def final_values overrides = @stage.overridden_package_values[name] values.deep_merge(overrides) end
helm(*commands)
click to toggle source
# File lib/hippo/package.rb, line 88 def helm(*commands) command = ['helm'] command += ['--kube-context', @stage.context] if @stage.context command += ['-n', @stage.namespace] command += commands command end
install()
click to toggle source
Install this package
@return [void]
# File lib/hippo/package.rb, line 55 def install run_install_command('install') end
installed?()
click to toggle source
Is this release currently installed for the stage?
@return [Boolean]
# File lib/hippo/package.rb, line 76 def installed? secrets = @stage.get('secrets').map(&:name) secrets.any? { |s| s.match(/\Ash\.helm\.release\.v\d+\.#{Regexp.escape(name)}\./) } end
name()
click to toggle source
Return the name of the package (i.e. the release name) and how this package will be referred.
@return [String]
# File lib/hippo/package.rb, line 17 def name @options['name'] end
notes()
click to toggle source
Return the notes for this package
@return [String]
# File lib/hippo/package.rb, line 84 def notes run(helm('get', 'notes', name)) end
package()
click to toggle source
Return the name of the package to be installed. Including the registry.
@return [String]
# File lib/hippo/package.rb, line 25 def package @options['package'] end
uninstall()
click to toggle source
Uninstall this packgae
@return [void]
# File lib/hippo/package.rb, line 69 def uninstall run(helm('uninstall', name)) end
upgrade()
click to toggle source
Upgrade this package
@return [void]
# File lib/hippo/package.rb, line 62 def upgrade run_install_command('upgrade', '--history-max', @options['max-revisions'] ? @options['max-revisions'].to_i.to_s : '5') end
values()
click to toggle source
return values defined in the package's manifest file
@return [Hash]
# File lib/hippo/package.rb, line 39 def values @options['values'] end
Private Instance Methods
install_command(verb, *additional)
click to toggle source
# File lib/hippo/package.rb, line 98 def install_command(verb, *additional) if chart_version additional = ['--version', chart_version] + additional end helm(verb, name, package, '-f', '-', *additional) end
run(command, stdin: nil)
click to toggle source
# File lib/hippo/package.rb, line 110 def run(command, stdin: nil) puts command stdout, stderr, status = Open3.capture3(*command, stdin_data: stdin) raise Error, "[helm] #{stderr}" unless status.success? stdout end
run_install_command(verb, *additional)
click to toggle source
# File lib/hippo/package.rb, line 105 def run_install_command(verb, *additional) run(install_command(verb, *additional), stdin: final_values.to_yaml(line_width: -1)) true end