Sha256: 63cf35359565463013bf193b3e3397e43e94687a39e64659d787ac3fe6b2a90c
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require 'open3' module K8sKit class Context attr_reader :namespace def initialize(namespace: nil) @namespace = namespace end def kubectl ns = namespace ? "-n #{namespace}" : '' "kubectl #{ns}" end def run(cmd, silent: true) cmd = "#{kubectl} #{cmd}" puts "Running #{cmd}" out = [] Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr| while line = stdout_err.gets puts line unless silent out << line end exit_status = wait_thr.value unless exit_status.success? abort "Failed: #{cmd}" end end out.join("\n").chomp end def pod(name) Pod.new(self, name) end def job(name) Job.new(self, name) end def wait_for_all_pods_ready(timeout: 300) t0 = Time.now print 'Waiting for all pods to be ready...' loop do statuses = run('get pods -o jsonpath="{.items.*.status.containerStatuses[*].ready}"') if statuses.empty? puts '' raise StandardError, 'No pod could be found in the namespace' end return unless statuses.include?('false') if t0 + timeout < Time.now puts '' raise StandardError, 'Timeout while waiting for pods to become ready' end print '.' sleep 2 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
k9s_kit-0.0.7.pre.pre6 | lib/k8s_kit/context.rb |
k9s_kit-0.0.7.pre.pre5 | lib/k8s_kit/context.rb |