Sha256: c0da6e3b10e88935026b54c48b8aafd6c9c044b4789f481e31a3865d99166d7f

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'open3'
require_relative "helm_upgrade_logs/version"

# Approach not ideal as it will for all containers to be ready and want to stream logs before that
def wait_for_container_ready
  wait_pid = Process.spawn 'kubectl wait --for=condition=ContainersReady pod --selector "app.kubernetes.io/managed-by=Helm" --timeout=30s'
  Process.wait wait_pid
end

# Wait for pods with logs to be present
# Not ideal due to https://github.com/kubernetes/kubernetes/issues/28746
def wait_for_pod_to_log
  90.times {
    sleep 1
    stdout, stderr, _ = Open3.capture3 "kubectl logs -lapp.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=#{$release_name}"
    if stderr.empty? && !stdout.strip.empty?
      puts 'Pods with logs found'
      break
    else
      puts "Waiting for pod logs: #{stderr}"
    end
  }
end

def wait_for_specific_pod_to_log(pod_name)
  30.times {
    sleep 1
    stdout, stderr, _ = Open3.capture3 "kubectl logs #{pod_name}"
    if stderr.empty? && !stdout.strip.empty?
      puts "Pod #{pod_name} with logs found"
      break
    else
      puts "Waiting for pod #{pod_name} logs: #{stderr}"
    end
  }
end

def get_pods
  stdout, stderr, _ = Open3.capture3 "kubectl get pods -lapp.kubernetes.io/instance=#{$release_name} -o name"
  if stderr.empty?
    stdout.lines.collect { |pod| pod.strip }
  else
    []
  end
end

module HelmUpgradeLogs
  class Error < StandardError; end
  # Your code goes here...
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
helm_upgrade_logs-0.2.2 lib/helm_upgrade_logs.rb