Class: Orchparty::Services::Context

Inherits:
Object
  • Object
show all
Includes:
Minfra::Cli::Logging
Defined in:
lib/orchparty/kubernetes_application.rb

Direct Known Subclasses

Apply, Chart, Helm, Label, SecretGeneric, Wait

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Minfra::Cli::Logging

#debug, #deprecated, #error, #exit_error, #info, #warn

Constructor Details

#initialize(cluster_name:, namespace:, file_path:, app_config:, app:, service:, out_io: $stdout) ⇒ Context

Returns a new instance of Context.



20
21
22
23
24
25
26
27
28
29
# File 'lib/orchparty/kubernetes_application.rb', line 20

def initialize(cluster_name:, namespace:, file_path:, app_config:, app:, service:, out_io: $stdout)
  self.cluster_name = cluster_name
  self.namespace = namespace
  self.dir_path = file_path
  self.app_config = app_config
  @app = app
  @out_io = out_io
  self.service = service # ugly naming, should be 'context'?
  self.options = options
end

Instance Attribute Details

#app_configObject

Returns the value of attribute app_config.



18
19
20
# File 'lib/orchparty/kubernetes_application.rb', line 18

def app_config
  @app_config
end

#cluster_nameObject

Returns the value of attribute cluster_name.



18
19
20
# File 'lib/orchparty/kubernetes_application.rb', line 18

def cluster_name
  @cluster_name
end

#dir_pathObject

Returns the value of attribute dir_path.



18
19
20
# File 'lib/orchparty/kubernetes_application.rb', line 18

def dir_path
  @dir_path
end

#namespaceObject

Returns the value of attribute namespace.



18
19
20
# File 'lib/orchparty/kubernetes_application.rb', line 18

def namespace
  @namespace
end

#optionsObject

Returns the value of attribute options.



18
19
20
# File 'lib/orchparty/kubernetes_application.rb', line 18

def options
  @options
end

#serviceObject

Returns the value of attribute service.



18
19
20
# File 'lib/orchparty/kubernetes_application.rb', line 18

def service
  @service
end

Instance Method Details

#installObject



69
70
71
72
# File 'lib/orchparty/kubernetes_application.rb', line 69

def install
  @out_io.puts install_cmd.run.stdout
  cleanup if respond_to?(:cleanup)
end


49
50
51
52
53
54
55
56
# File 'lib/orchparty/kubernetes_application.rb', line 49

def print_install
  @out_io.puts '---'
  @out_io.puts install_cmd(value_path).cmd
  @out_io.puts upgrade_cmd(value_path).cmd
  @out_io.puts '---'
  @out_io.puts File.read(template(value_path, service, flag: '')) if value_path
  cleanup if respond_to?(:cleanup)
end

On 05.02.2021 we have decided that it would be best to print both commands. This way it would be possible to debug both upgrade and install and also people would not see git diffs all the time.



60
61
62
# File 'lib/orchparty/kubernetes_application.rb', line 60

def print_upgrade
  print_install
end

#template(file_path, helm, flag: '-f ', fix_file_path: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/orchparty/kubernetes_application.rb', line 31

def template(file_path, helm, flag: '-f ', fix_file_path: nil)
  return '' unless file_path

  debug "Rendering: #{file_path}"
  file_path = File.join(dir_path, file_path) unless file_path.start_with?('/')
  if file_path.end_with?('.erb')
    helm.application = OpenStruct.new(cluster_name: cluster_name, namespace: namespace)
    template = Erubis::Eruby.new(File.read(file_path))
    template.filename = file_path
    yaml = template.result(helm.get_binding)
    file = Tempfile.new('kube-deploy.yaml')
    file.write(yaml)
    file.close
    file_path = file.path
  end
  "#{flag}#{fix_file_path || file_path}"
end

#upgradeObject



64
65
66
67
# File 'lib/orchparty/kubernetes_application.rb', line 64

def upgrade
  @out_io.puts upgrade_cmd.run.stdout
  cleanup if respond_to?(:cleanup)
end