class Kubes::Kubectl
Public Class Methods
capture(args, options={})
click to toggle source
# 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) # data else resp end end
execute(args, options={})
click to toggle source
# File lib/kubes/kubectl.rb, line 69 def execute(args, options={}) sh("kubectl #{args}", options) end
new(name, options={})
click to toggle source
# File lib/kubes/kubectl.rb, line 7 def initialize(name, options={}) @name, @options = name, options end
run(name, options={})
click to toggle source
# File lib/kubes/kubectl.rb, line 65 def run(name, options={}) new(name, options).run end
Public Instance Methods
args()
click to toggle source
# File lib/kubes/kubectl.rb, line 45 def args # base at end in case of redirection. IE: command > /path custom.args + default.args end
custom()
click to toggle source
# 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
default()
click to toggle source
# File lib/kubes/kubectl.rb, line 57 def default klass = Kubes.kustomize? ? Args::Kustomize : Args::Standard klass.new(@name, @options) end
exit_on_fail()
click to toggle source
# 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()
click to toggle source
# 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}" # @name: apply or delete run_hooks("kubectl.rb", name: @name, file: @options[:file]) do if options[:capture] self.class.capture(args, options) # already includes kubectl else self.class.execute(args, options) end end end
validate!()
click to toggle source
Useful for kustomize mode
# 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