Class: KubernetesDeploy::StatefulSet

Inherits:
PodSetBase show all
Defined in:
lib/kubernetes-deploy/kubernetes_resource/stateful_set.rb

Constant Summary collapse

TIMEOUT =
10.minutes
ONDELETE =
'OnDelete'

Constants inherited from KubernetesResource

KubernetesResource::DEBUG_RESOURCE_NOT_FOUND_MESSAGE, KubernetesResource::DISABLED_EVENT_INFO_MESSAGE, KubernetesResource::DISABLED_LOG_INFO_MESSAGE, KubernetesResource::DISABLE_FETCHING_EVENT_INFO, KubernetesResource::DISABLE_FETCHING_LOG_INFO, KubernetesResource::LOG_LINE_COUNT, KubernetesResource::STANDARD_TIMEOUT_MESSAGE, KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION, KubernetesResource::UNUSUAL_FAILURE_MESSAGE

Instance Attribute Summary collapse

Attributes inherited from KubernetesResource

#context, #deploy_started_at, #name, #namespace, #type

Instance Method Summary collapse

Methods inherited from PodSetBase

#failure_message, #fetch_events, #fetch_logs, #timeout_message

Methods inherited from KubernetesResource

build, #debug_message, #deploy_method, #deploy_started?, #deploy_timed_out?, #failure_message, #fetch_events, #file_path, #id, #initialize, #kubectl, #pretty_status, #pretty_timeout_type, #report_status_to_statsd, #status, #sync_debug_info, timeout, #timeout, #timeout_message, #timeout_override, #validate_definition, #validation_error_msg, #validation_failed?

Constructor Details

This class inherits a constructor from KubernetesDeploy::KubernetesResource

Instance Attribute Details

#podsObject (readonly)

Returns the value of attribute pods.



7
8
9
# File 'lib/kubernetes-deploy/kubernetes_resource/stateful_set.rb', line 7

def pods
  @pods
end

Instance Method Details

#deploy_failed?Boolean

Returns:

  • (Boolean)


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

def deploy_failed?
  return false if @update_strategy == ONDELETE
  pods.present? && pods.any?(&:deploy_failed?)
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kubernetes-deploy/kubernetes_resource/stateful_set.rb', line 32

def deploy_succeeded?
  if @update_strategy == ONDELETE
    # Gem cannot monitor update since it doesn't occur until delete
    unless @success_assumption_warning_shown
      @logger.warn("WARNING: Your StatefulSet's updateStrategy is set to OnDelete, "\
                   "which means updates will not be applied until its pods are deleted. "\
                   "If you are using k8s 1.7+, consider switching to rollingUpdate.")
      @success_assumption_warning_shown = true
    end
    true
  else
    @status_data['currentRevision'] == @status_data['updateRevision'] &&
    @desired_replicas == @status_data['readyReplicas'].to_i &&
    @desired_replicas == @status_data['currentReplicas'].to_i
  end
end

#exists?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/kubernetes-deploy/kubernetes_resource/stateful_set.rb', line 54

def exists?
  @found
end

#syncObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kubernetes-deploy/kubernetes_resource/stateful_set.rb', line 9

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

  if @found
    stateful_data = JSON.parse(raw_json)
    @desired_replicas = stateful_data["spec"]["replicas"].to_i
    @status_data = stateful_data["status"]
    rollout_data = stateful_data["status"].slice("replicas", "readyReplicas", "currentReplicas")
    @update_strategy = if kubectl.server_version < Gem::Version.new("1.7.0")
      ONDELETE
    else
      stateful_data['spec']['updateStrategy']['type']
    end
    @status = rollout_data.map { |state_replicas, num| "#{num} #{state_replicas.chop.pluralize(num)}" }.join(", ")
    @pods = find_pods(stateful_data)
  else # reset
    @status_data = { 'readyReplicas' => '-1', 'currentReplicas' => '-2' }
    @status = nil
    @pods = []
  end
end