Module: KubernetesHelper
- Defined in:
- lib/kubernetes_helper/core.rb,
lib/kubernetes_helper.rb,
lib/kubernetes_helper/railtie.rb,
lib/kubernetes_helper/version.rb
Overview
require ‘byebug’ rescue nil
Defined Under Namespace
Classes: Core, ErbBinding, Error, Railtie
Constant Summary
collapse
- FOLDER_NAME =
'.kubernetes'
- VERSION =
'1.24.1'
Class Method Summary
collapse
Class Method Details
.copy_templates(mode_or_file) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/kubernetes_helper.rb', line 67
def self.copy_templates(mode_or_file)
FileUtils.mkdir(settings_path) unless Dir.exist?(settings_path)
template_path = templates_path(mode_or_file)
return FileUtils.cp(template_path, settings_path(mode_or_file)) if File.exist?(template_path)
files = %w[README.md secrets.yml settings.rb]
files += %w[deployment.yml cd.sh ingress.yml service.yml] if mode_or_file == 'advanced'
files.each do |name|
path = settings_path(name)
FileUtils.cp(templates_path(name), path) unless File.exist?(path)
end
end
|
.deep_merge(hash1, hash2) ⇒ Object
42
43
44
45
|
# File 'lib/kubernetes_helper.rb', line 42
def self.deep_merge(hash1, hash2)
merger = proc { |_key, v1, v2| v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2 }
hash1.merge(hash2, &merger)
end
|
.job_apps_from_old_settings(settings) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/kubernetes_helper.rb', line 80
def self.job_apps_from_old_settings(settings)
return [] unless settings[:deployment][:job_name]
[
{
name: settings[:deployment][:job_name],
command: settings[:deployment][:job_command],
services: settings[:deployment][:job_services],
resources: settings[:deployment][:job_resources],
sidekiq_alive_gem: settings[:deployment][:job_sidekiq_alive_gem]
}
]
end
|
.load_settings ⇒ Hash
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/kubernetes_helper.rb', line 17
def self.load_settings config_file = File.join(settings_path, 'settings.rb')
load config_file
def_settings = {
cloud: {
name: 'gcloud'
},
deployment: {
log_container: true,
log_folder: '/app/log',
external_secrets: {},
job_apps: settings[:job_apps] || job_apps_from_old_settings(settings)
},
service: {
port_name: 'http-port',
backend_port_name: 'b-port'
},
secrets: {},
continuous_deployment: {},
ingress: {}
}
deep_merge(def_settings, settings || {})
end
|
.run_cmd(cmd, title = nil) ⇒ Object
56
57
58
59
|
# File 'lib/kubernetes_helper.rb', line 56
def self.run_cmd(cmd, title = nil)
res = Kernel.system cmd
Kernel.abort("::::::::CD: failed running command: #{title || cmd} ==> #{caller}") if res != true
end
|
.settings(settings = nil) ⇒ Object
10
11
12
13
|
# File 'lib/kubernetes_helper.rb', line 10
def self.settings(settings = nil)
@settings = settings if settings
@settings
end
|
.settings_path(file_name = nil, use_template: false) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/kubernetes_helper.rb', line 47
def self.settings_path(file_name = nil, use_template: false)
path = File.join(Dir.pwd, FOLDER_NAME)
if file_name
app_path = File.join(path, file_name)
path = use_template && !File.exist?(app_path) ? templates_path(file_name) : app_path
end
path
end
|
.templates_path(file_name = nil) ⇒ Object
61
62
63
64
|
# File 'lib/kubernetes_helper.rb', line 61
def self.templates_path(file_name = nil)
path = File.join(File.expand_path(__dir__), 'templates')
file_name ? File.join(path, file_name) : path
end
|