Class: Vidar::K8s::PodSet
- Inherits:
-
Object
- Object
- Vidar::K8s::PodSet
- Defined in:
- lib/vidar/k8s/pod_set.rb
Overview
Represents a collection of Kubernetes pods and their containers fetched via ‘kubectl get pods` for a given namespace.
Instance Method Summary collapse
-
#any? ⇒ Boolean
True if any containers exist in the pod set.
-
#containers ⇒ Array<Container>
Filtered container list.
-
#deployed? ⇒ Boolean
Logs current container states and returns whether all are deployed.
-
#initialize(namespace:, filter: nil) ⇒ PodSet
constructor
A new instance of PodSet.
-
#success? ⇒ Boolean
True if all containers report success.
-
#waiting? ⇒ Boolean
True if any containers are in waiting state.
Constructor Details
#initialize(namespace:, filter: nil) ⇒ PodSet
Returns a new instance of PodSet.
8 9 10 11 |
# File 'lib/vidar/k8s/pod_set.rb', line 8 def initialize(namespace:, filter: nil) @namespace = namespace @filter = filter end |
Instance Method Details
#any? ⇒ Boolean
Returns true if any containers exist in the pod set.
14 15 16 |
# File 'lib/vidar/k8s/pod_set.rb', line 14 def any? containers.any? end |
#containers ⇒ Array<Container>
Returns filtered container list.
48 49 50 51 52 53 54 |
# File 'lib/vidar/k8s/pod_set.rb', line 48 def containers if filter all_containers.select { |cs| cs.name.to_s.include?(filter) } else all_containers.reject(&:job?) end end |
#deployed? ⇒ Boolean
Logs current container states and returns whether all are deployed.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vidar/k8s/pod_set.rb', line 25 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? ⇒ Boolean
Returns true if all containers report success.
41 42 43 44 45 |
# File 'lib/vidar/k8s/pod_set.rb', line 41 def success? return false if containers.empty? containers.all?(&:success?) end |
#waiting? ⇒ Boolean
Returns true if any containers are in waiting state.
19 20 21 |
# File 'lib/vidar/k8s/pod_set.rb', line 19 def waiting? containers.any?(&:waiting?) end |