Class: Vidar::DeployStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/vidar/deploy_status.rb

Overview

Polls Kubernetes pod status until deployment completes or times out.

Constant Summary collapse

INITIAL_SLEEP =
2
SLEEP =
10
MAX_TRIES =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace:, filter: nil, max_tries: MAX_TRIES) ⇒ DeployStatus

Returns a new instance of DeployStatus.

Parameters:

  • namespace (String)

    Kubernetes namespace, or “all”

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

    optional substring filter on container names

  • max_tries (Integer) (defaults to: MAX_TRIES)

    maximum poll iterations before giving up



13
14
15
16
17
# File 'lib/vidar/deploy_status.rb', line 13

def initialize(namespace:, filter: nil, max_tries: MAX_TRIES)
  @namespace = namespace
  @filter = filter
  @max_tries = max_tries
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



8
9
10
# File 'lib/vidar/deploy_status.rb', line 8

def filter
  @filter
end

#max_triesObject (readonly)

Returns the value of attribute max_tries.



8
9
10
# File 'lib/vidar/deploy_status.rb', line 8

def max_tries
  @max_tries
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/vidar/deploy_status.rb', line 8

def namespace
  @namespace
end

Instance Method Details

#success?Boolean

Returns true if the last observed pod set reported success.

Returns:

  • (Boolean)

    true if the last observed pod set reported success



46
47
48
49
50
# File 'lib/vidar/deploy_status.rb', line 46

def success?
  return false unless @last_pod_set

  @last_pod_set.success?
end

#wait_until_completedvoid

This method returns an undefined value.

Waits until all pods are deployed and none are still initializing.



34
35
36
37
38
39
40
41
42
43
# File 'lib/vidar/deploy_status.rb', line 34

def wait_until_completed
  sleep(INITIAL_SLEEP)

  max_tries.times do
    ps = current_pod_set
    break if ps.deployed?

    sleep(SLEEP)
  end
end

#wait_until_upvoid

This method returns an undefined value.

Waits until at least one pod exists in the namespace.



21
22
23
24
25
26
27
28
29
30
# File 'lib/vidar/deploy_status.rb', line 21

def wait_until_up
  sleep(INITIAL_SLEEP)

  max_tries.times do
    ps = current_pod_set
    break if ps.any?

    sleep(SLEEP)
  end
end