Class: Kubert::Deployment

Inherits:
Object
  • Object
show all
Defined in:
lib/kubert/deployment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, project_name = Kubert.configuration[:project_name]) ⇒ Deployment

Returns a new instance of Deployment.



12
13
14
15
16
# 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

Instance Attribute Details

#operation_statusesObject (readonly)

Returns the value of attribute operation_statuses.



11
12
13
# File 'lib/kubert/deployment.rb', line 11

def operation_statuses
  @operation_statuses
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/kubert/deployment.rb', line 11

def options
  @options
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



11
12
13
# File 'lib/kubert/deployment.rb', line 11

def project_name
  @project_name
end

Class Method Details

.perform(options) ⇒ Object



3
4
5
# File 'lib/kubert/deployment.rb', line 3

def self.perform(options)
  new(options).perform
end

.rollback(options) ⇒ Object



7
8
9
# File 'lib/kubert/deployment.rb', line 7

def self.rollback(options)
  new(options).rollback
end

Instance Method Details

#compilationObject



50
51
52
# 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_deployObject



38
39
40
41
42
43
44
45
46
47
48
# 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

#performObject



27
28
29
30
31
32
33
34
35
36
# 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

#rollbackObject



18
19
20
21
22
23
24
25
# 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