Class: Orchparty::Services::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/orchparty/kubernetes_application.rb

Direct Known Subclasses

Apply, Chart, Helm, Label, SecretGeneric, Wait

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster_name:, namespace:, file_path:, app_config:) ⇒ Context

Returns a new instance of Context.



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

def initialize(cluster_name: , namespace:, file_path: , app_config:)
  self.cluster_name = cluster_name
  self.namespace = namespace
  self.dir_path = file_path
  self.app_config = app_config
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.



15
16
17
# File 'lib/orchparty/kubernetes_application.rb', line 15

def cluster_name
  @cluster_name
end

#dir_pathObject

Returns the value of attribute dir_path.



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

def dir_path
  @dir_path
end

#namespaceObject

Returns the value of attribute namespace.



16
17
18
# File 'lib/orchparty/kubernetes_application.rb', line 16

def namespace
  @namespace
end

Instance Method Details

#install(helm) ⇒ Object



62
63
64
# File 'lib/orchparty/kubernetes_application.rb', line 62

def install(helm)
  puts system(install_cmd(helm))
end


42
43
44
45
46
47
# File 'lib/orchparty/kubernetes_application.rb', line 42

def print_install(helm)
  puts "---"
  puts install_cmd(helm, value_path(helm))
  puts "---"
  puts File.read(template(value_path(helm), helm, flag: "")) if value_path(helm)
end


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

def print_upgrade(helm)
  puts "---"
  puts install_cmd(helm, value_path(helm))
  puts "---"
  puts File.read(template(value_path(helm), helm, flag: "")) if value_path(helm)
end

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/orchparty/kubernetes_application.rb', line 27

def template(file_path, helm, flag: "-f ", fix_file_path: nil)
  return "" unless file_path
  file_path = File.join(self.dir_path, file_path)
  if(file_path.end_with?(".erb"))
    helm.application = OpenStruct.new(cluster_name: cluster_name, namespace: namespace)
    template = Erubis::Eruby.new(File.read(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

#upgrade(helm) ⇒ Object



57
58
59
# File 'lib/orchparty/kubernetes_application.rb', line 57

def upgrade(helm)
  puts system(upgrade_cmd(helm))
end