Class: KubernetesDeploy::DaemonSet

Inherits:
KubernetesResource show all
Defined in:
lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb

Constant Summary collapse

TIMEOUT =
5.minutes

Constants inherited from KubernetesResource

KubernetesResource::DEBUG_RESOURCE_NOT_FOUND_MESSAGE, KubernetesResource::LOG_LINE_COUNT, KubernetesResource::STANDARD_TIMEOUT_MESSAGE, KubernetesResource::UNUSUAL_FAILURE_MESSAGE

Instance Attribute Summary

Attributes inherited from KubernetesResource

#context, #deploy_started, #name, #namespace, #type, #validation_error_msg

Instance Method Summary collapse

Methods inherited from KubernetesResource

build, #debug_message, #deploy_finished?, #deploy_method, #file_path, #id, #initialize, #kubectl, #pretty_status, #report_status_to_statsd, #status, timeout, #timeout, #validate_definition, #validation_failed?

Constructor Details

This class inherits a constructor from KubernetesDeploy::KubernetesResource

Instance Method Details

#deploy_failed?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 33

def deploy_failed?
  @pods.present? && @pods.any?(&:deploy_failed?)
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 27

def deploy_succeeded?
  @rollout_data["desiredNumberScheduled"].to_i == @rollout_data["currentNumberScheduled"].to_i &&
  @rollout_data["desiredNumberScheduled"].to_i == @rollout_data["numberReady"].to_i &&
  @current_generation == @observed_generation
end

#deploy_timed_out?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 45

def deploy_timed_out?
  super || @pods.present? && @pods.any?(&:deploy_timed_out?)
end

#exists?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 49

def exists?
  @found
end

#failure_messageObject



37
38
39
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 37

def failure_message
  @pods.map(&:failure_message).compact.uniq.join("\n")
end

#fetch_eventsObject



53
54
55
56
57
58
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 53

def fetch_events
  own_events = super
  return own_events unless @pods.present?
  most_useful_pod = @pods.find(&:deploy_failed?) || @pods.find(&:deploy_timed_out?) || @pods.first
  own_events.merge(most_useful_pod.fetch_events)
end

#fetch_logsObject



60
61
62
63
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 60

def fetch_logs
  most_useful_pod = @pods.find(&:deploy_failed?) || @pods.find(&:deploy_timed_out?) || @pods.first
  most_useful_pod.fetch_logs
end

#syncObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 6

def sync
  raw_json, _err, st = kubectl.run("get", type, @name, "--output=json")
  @found = st.success?

  if @found
    daemonset_data = JSON.parse(raw_json)
    @current_generation = daemonset_data["metadata"]["generation"]
    @observed_generation = daemonset_data["status"]["observedGeneration"]
    @rollout_data = daemonset_data["status"]
      .slice("currentNumberScheduled", "desiredNumberScheduled", "numberReady")
    @status = @rollout_data.map { |state_replicas, num| "#{num} #{state_replicas}" }.join(", ")
    @pods = find_pods(daemonset_data)
  else # reset
    @rollout_data = { "currentNumberScheduled" => 0 }
    @current_generation = 1 # to make sure the current and observed generations are different
    @observed_generation = 0
    @status = nil
    @pods = []
  end
end

#timeout_messageObject



41
42
43
# File 'lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb', line 41

def timeout_message
  @pods.map(&:timeout_message).compact.uniq.join("\n")
end