Sha256: 058218c8c9d01a791aa9724481739f31b6cbe17b74ec972a0eb3ed6e6347aafb

Contents?: true

Size: 900 Bytes

Versions: 2

Compression:

Stored size: 900 Bytes

Contents

module Vidar
  module K8s
    class Pods
      def initialize(namespace)
        @namespace = namespace
      end

      def all_ready?
        if items.empty?
          Log.error "Could not fetch pod list"
          return false
        end

        container_statuses.each do |container_status|
          Log.info container_status.to_text
        end

        Log.info "-", "-"

        container_statuses.all?(&:ok?)
      end

      private

      attr_reader :pods, :namespace

      def items
        @items ||= begin
          output = `kubectl get pods -n #{Config.get!(:namespace)} -o json`
          json = JSON.parse(output.strip)
          json["items"] || []
        end
      end

      def container_statuses
        @container_statuses ||= items.map { |i| i.dig("status", "containerStatuses") }.flatten.compact.map { |status| ContainerStatus.new(status) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vidar-0.2.0 lib/vidar/k8s/pods.rb
vidar-0.1.6 lib/vidar/k8s/pods.rb