#!/usr/bin/env ruby # frozen_string_literal: true require 'open3' $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib") require 'helm_upgrade_logs' $release_name = ARGV.find { |arg| !arg.start_with?('-') } helm_pid = Process.spawn "helm upgrade #{ARGV.join(' ')}" event_pid = Process.spawn 'kubectl get events --watch-only=true' service_pid = Process.spawn 'kubectl get services --watch-only=true' wait_for_pod_to_log @pods = [] while Process.waitpid(helm_pid, Process::WNOHANG) == nil do pods = get_pods if pods != @pods @pods = pods puts "[INFO] Pods: #{pods.join(',')}" puts `kill #{@log_pid}` if @log_pid @log_pid = Process.spawn "kubectl logs -lapp.kubernetes.io/instance=#{$release_name} -f --all-containers --prefix --ignore-errors=true --max-log-requests=20 --timestamps=true --since=0s" end sleep 2.5 end puts `kill #{@log_pid}` puts `kill #{event_pid}` puts `kill #{service_pid}`