class Kubert::Deployment
Attributes
operation_statuses[R]
options[R]
project_name[R]
Public Class Methods
new(options, project_name= Kubert.configuration[:project_name])
click to toggle source
# File lib/kubert/deployment.rb, line 12 def initialize(options, project_name= Kubert.configuration[:project_name]) @project_name = project_name @options = options Kubert.ky_configuration(options) # memoize options for FileAccess usage end
perform(options)
click to toggle source
# File lib/kubert/deployment.rb, line 3 def self.perform(options) new(options).perform end
rollback(options)
click to toggle source
# File lib/kubert/deployment.rb, line 7 def self.rollback(options) new(options).rollback end
Public Instance Methods
compilation()
click to toggle source
# File lib/kubert/deployment.rb, line 50 def compilation @compilation ||= KY::API.compile(options[:configmap_path], options[:secrets_path], options[:output_dir], options_with_defaults) end
handle_env_deploy() { || ... }
click to toggle source
# File lib/kubert/deployment.rb, line 38 def handle_env_deploy config_data = FileAccess.new(:config) config_data.write_local unless config_data.local? secret_data = FileAccess.new(:secret) secret_data.write_local unless secret_data.local? perform_with_status { `kubectl apply -f #{File.expand_path(output_dir)}/#{Kubert.config_file_name} --record` } perform_with_status { `kubectl apply -f #{File.expand_path(output_dir)}/#{Kubert.secret_file_name} --record` } yield secret_data.clean_local unless secret_data.local? config_data.clean_local unless config_data.local? end
perform()
click to toggle source
# File lib/kubert/deployment.rb, line 27 def perform confirm :deploy do handle_env_deploy do compilation.deploy_generation.to_h.each do |deployment_file, _template_hash| perform_with_status { `kubectl apply -f #{File.expand_path(deployment_file)} --record` unless excluded?(deployment_file) } end report_status(:deploy) end end end
rollback()
click to toggle source
# File lib/kubert/deployment.rb, line 18 def rollback confirm :rollback do compilation.deploy_generation.proc_commands.keys.each do |deployment_name| perform_with_status { `kubectl rollout status deployment/#{deployment_name} #{namespace_flag}` } unless excluded?(deployment_name) end report_status(:rollback) end end
Private Instance Methods
confirm(action) { || ... }
click to toggle source
# File lib/kubert/deployment.rb, line 56 def confirm(action) unless options[:skip_confirmation] puts "Press any key to confirm, ctl-c to abort: #{action.to_s.upcase} on #{Kubert.context}" $stdin.gets end yield rescue Interrupt puts "Aborting #{action}" end
excluded?(deployment_info)
click to toggle source
# File lib/kubert/deployment.rb, line 88 def excluded?(deployment_info) Kubert.excluded_deployments.any? {|deploy| deployment_info.match(deploy) } end
ky_configuration()
click to toggle source
# File lib/kubert/deployment.rb, line 79 def ky_configuration @ky_configuration ||= compilation.deploy_generation.configuration.configuration.with_indifferent_access end
namespace_flag()
click to toggle source
# File lib/kubert/deployment.rb, line 83 def namespace_flag return unless compilation.configuration[:environment] "-n #{compilation.configuration[:environment]} " end
options_with_defaults()
click to toggle source
# File lib/kubert/deployment.rb, line 75 def options_with_defaults (options[:environment] ? options : options.merge(environment: Kubert.default_environment)).with_indifferent_access end
output_dir()
click to toggle source
# File lib/kubert/deployment.rb, line 92 def output_dir compilation.deploy_generation.full_output_dir end
perform_with_status() { || ... }
click to toggle source
# File lib/kubert/deployment.rb, line 70 def perform_with_status output = yield abort(output) unless $?.success? end
report_status(action)
click to toggle source
# File lib/kubert/deployment.rb, line 66 def report_status(action) puts "All #{action} steps ran successfully" end