Sha256: b71f64ea02b9ee93ba153e5a13ec8fa046110b42a76ed2235aeea0bc926968b2

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

#!/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?("-") }
@namespace = namespace_from_args(ARGV)

@helm_pid = Process.spawn "helm upgrade #{ARGV.join(" ")}"

pods_before_upgrade = read_pods
puts "[INFO] Pods before upgrade #{pods_before_upgrade}" if pods_before_upgrade.size.positive?

event_pid = Process.spawn(add_ns("kubectl get events --watch-only=true"))
service_pid = Process.spawn(add_ns("kubectl get services --watch-only=true"))

wait_for_pod_to_log

@pods = []
@pod_pids = {}

begin
  Process.waitpid(@helm_pid, Process::WNOHANG)
rescue Errno::ECHILD
  `kill #{event_pid}`
  `kill #{service_pid}`
  raise HelmUpgradeLogs::Error, "Failed to find logs before helm finished"
end

while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
  pods = read_pods - pods_before_upgrade
  if pods != @pods
    @pods = pods
    puts "[INFO] Pods: #{pods.join(",")}"
    # Could change this each to Parallel.each
    @pods.each do |pod|
      next unless @pod_pids[pod].nil?

      wait_for_specific_pod_to_log pod
      log_pid = Process.spawn(add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true"))
      @pod_pids[pod] = log_pid
    end
  end
  sleep 1
end
helm_status = $CHILD_STATUS.exitstatus
`kill #{event_pid}`
`kill #{service_pid}`
@pod_pids.each do |_pod, pid|
  `kill #{pid}`
end
exit helm_status

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
helm_upgrade_logs-0.2.6 exe/helm_upgrade_logs