class Vidar::K8s::PodSet
Attributes
filter[R]
namespace[R]
Public Class Methods
new(namespace:, filter: nil)
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 4 def initialize(namespace:, filter: nil) @namespace = namespace @filter = filter end
Public Instance Methods
containers()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 30 def containers return all_containers unless filter all_containers.select { |cs| cs.name.to_s.include?(filter) } end
deployed?()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 9 def deployed? if items.empty? Log.error "Could not fetch pod list" return false end Log.line containers.each(&:print) Log.line containers.all?(&:deployed?) end
success?()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 24 def success? return false if containers.empty? containers.all?(&:success?) end
Private Instance Methods
all_containers()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 59 def all_containers @all_containers ||= containers_data.map { |status| Container.new(status) } end
containers_data()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 63 def containers_data items.map do |i| owner_references = i.dig("metadata", "ownerReferences") || [] kind = (owner_references[0] || {})["kind"] namespace = i.dig("metadata", "namespace") statuses = i.dig("status", "containerStatuses") || i.dig("status", "conditions") || [] statuses.each do |s| s["namespace"] = namespace s["kind"] = kind s["pod_name"] = i.dig("metadata", "name") end statuses end.flatten end
items()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 40 def items @items ||= begin json = JSON.parse(kubectl_get.strip) json["items"] || [] end end
kubectl_get()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 47 def kubectl_get if namespace == "all" `kubectl get pods --all-namespaces -o json` else `kubectl get pods -n #{namespace} -o json` end end
ready_and_running_containers()
click to toggle source
# File lib/vidar/k8s/pod_set.rb, line 55 def ready_and_running_containers containers.select(&:ready_and_running?) end