Class: Kubes::Kubectl
- Inherits:
-
Object
show all
- Extended by:
- Util::Sh, Memoist
- Includes:
- Hooks::Concern, Util::Sh
- Defined in:
- lib/kubes/kubectl.rb,
lib/kubes/kubectl/batch.rb,
lib/kubes/kubectl/ordering.rb,
lib/kubes/kubectl/kustomize.rb,
lib/kubes/kubectl/dispatcher.rb
Defined Under Namespace
Modules: Args, Fetch, Ordering
Classes: Batch, Dispatcher, Kustomize
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util::Sh
sh, sh_capture
Methods included from Logging
#logger
#run_hooks
Constructor Details
#initialize(name, options = {}) ⇒ Kubectl
Returns a new instance of Kubectl.
7
8
9
|
# File 'lib/kubes/kubectl.rb', line 7
def initialize(name, options={})
@name, @options = name, options
end
|
Class Method Details
.capture(args, options = {}) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/kubes/kubectl.rb', line 73
def capture(args, options={})
resp = sh_capture("kubectl #{args}", options)
if args.include?('-o json')
JSON.load(resp) else
resp
end
end
|
.execute(args, options = {}) ⇒ Object
69
70
71
|
# File 'lib/kubes/kubectl.rb', line 69
def execute(args, options={})
sh("kubectl #{args}", options)
end
|
.run(name, options = {}) ⇒ Object
65
66
67
|
# File 'lib/kubes/kubectl.rb', line 65
def run(name, options={})
new(name, options).run
end
|
Instance Method Details
#args ⇒ Object
45
46
47
48
|
# File 'lib/kubes/kubectl.rb', line 45
def args
custom.args + default.args
end
|
#custom ⇒ Object
50
51
52
53
54
|
# File 'lib/kubes/kubectl.rb', line 50
def custom
custom = Kubes::Args::Custom.new(@name, "#{Kubes.root}/.kubes/config/kubectl/args.rb")
custom.build
custom
end
|
#exit_on_fail ⇒ Object
40
41
42
43
|
# File 'lib/kubes/kubectl.rb', line 40
def exit_on_fail
return false if ENV['KUBES_EXIT_ON_FAIL'] == '0'
Kubes.config.kubectl.exit_on_fail[@name]
end
|
#run ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/kubes/kubectl.rb', line 11
def run
validate!
options = @options.dup
options[:exit_on_fail] = exit_on_fail unless exit_on_fail.nil?
params = args.flatten.join(' ')
args = "#{@name} #{params}"
run_hooks("kubectl.rb", name: @name, file: @options[:file]) do
if options[:capture]
self.class.capture(args, options) else
self.class.execute(args, options)
end
end
end
|
#validate! ⇒ Object
Useful for kustomize mode
30
31
32
33
34
35
36
37
38
|
# File 'lib/kubes/kubectl.rb', line 30
def validate!
return true unless Kubes.kustomize?
unless @options[:role]
logger.error "Missing argument: A folder must be provided when using kustomization.yaml files".color(:red)
logger.info "Please provide a folder"
exit 1
end
end
|