Class: Vidar::K8s::PodSet

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(namespace:, filter: nil) ⇒ PodSet

Returns a new instance of PodSet.

Parameters:

  • namespace (String)

    Kubernetes namespace, or “all” for all namespaces

  • filter (String, nil) (defaults to: nil)

    optional substring filter on container names



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.

Returns:

  • (Boolean)

    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

#containersArray<Container>

Returns filtered container list.

Returns:

  • (Array<Container>)

    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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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