Class: Mortar::FireCommand
Constant Summary
Constants inherited
from Command
Command::CHECKSUM_ANNOTATION, Command::LABEL
Instance Method Summary
collapse
Methods included from TTYHelper
#pastel
#build_kubeconfig_from_env, #client, #create_client
#from_file, #from_files, #load_resources, #resources_output, #same_resource?, #stringify_hash
Instance Method Details
#default_config ⇒ Object
26
27
28
29
30
|
# File 'lib/mortar/fire_command.rb', line 26
def default_config
%w{shot.yml shot.yaml}.find { |path|
File.readable?(path)
}
end
|
#dotted_path_to_hash(hash) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/mortar/fire_command.rb', line 140
def dotted_path_to_hash(hash)
h = hash.map do |pkey, pvalue|
pkey.to_s.split(".").reverse.inject(pvalue) do |value, key|
{ key.to_s => value }
end
end
return {} if h.empty?
h.inject(&:deep_merge)
end
|
#execute ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/mortar/fire_command.rb', line 43
def execute
signal_usage_error("#{src} does not exist") unless File.exist?(src)
load_config
resources = process_overlays
resources = (resources, )
if output?
puts resources_output(resources)
exit
end
if resources.empty?
warn 'nothing to do!'
exit
end
K8s::Stack.new(
name, resources,
debug: debug?,
label: LABEL,
checksum_annotation: CHECKSUM_ANNOTATION
).apply(client, prune: prune?)
puts "shot '#{pastel.cyan(name)}' successfully!" if $stdout.tty?
end
|
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/mortar/fire_command.rb', line 95
def
return @extra_labels if @extra_labels
@extra_labels = {}
label_list.each do |label|
key, value = label.split('=')
@extra_labels[key] = value
end
@extra_labels
end
|
115
116
117
118
119
120
121
122
123
|
# File 'lib/mortar/fire_command.rb', line 115
def (resources, labels)
resources.map { |resource|
resource.merge(
metadata: {
labels: labels
}
)
}
end
|
#load_config ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/mortar/fire_command.rb', line 32
def load_config
if config
signal_usage_error("Cannot read config file from #{path}") unless File.readable?(config)
@configuration = Config.load(config)
else
@configuration = Config.new(variables: {}, overlays: [])
end
end
|
108
109
110
|
# File 'lib/mortar/fire_command.rb', line 108
def
@config.labels()
end
|
#process_overlays ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/mortar/fire_command.rb', line 71
def process_overlays
resources = load_resources(src).reject { |r| r.kind.nil? }
@configuration.overlays(overlay_list).each do |overlay|
overlay_resources = from_files(overlay)
overlay_resources.each do |overlay_resource|
match = false
resources = resources.map { |r|
if same_resource?(r, overlay_resource)
match = true
r.merge(overlay_resource.to_hash)
else
r
end
}
resources << overlay_resource unless match
end
end
resources
end
|
#variables_hash ⇒ Object
130
131
132
133
134
135
136
137
138
|
# File 'lib/mortar/fire_command.rb', line 130
def variables_hash
set_hash = {}
var_list.each do |var|
k, v = var.split("=", 2)
set_hash[k] = v
end
dotted_path_to_hash(set_hash)
end
|
#variables_struct ⇒ RecursiveOpenStruct
126
127
128
|
# File 'lib/mortar/fire_command.rb', line 126
def variables_struct
@variables_struct ||= @configuration.variables(variables_hash)
end
|