Class: Krane::ReplicaSet

Inherits:
PodSetBase show all
Defined in:
lib/krane/kubernetes_resource/replica_set.rb

Constant Summary collapse

TIMEOUT =
5.minutes
SYNC_DEPENDENCIES =
%w(Pod)

Constants inherited from KubernetesResource

KubernetesResource::ALLOWED_DEPLOY_METHOD_OVERRIDES, KubernetesResource::DEBUG_RESOURCE_NOT_FOUND_MESSAGE, KubernetesResource::DEPLOY_METHOD_OVERRIDE_ANNOTATION, KubernetesResource::DISABLED_EVENT_INFO_MESSAGE, KubernetesResource::DISABLED_LOG_INFO_MESSAGE, KubernetesResource::DISABLE_FETCHING_EVENT_INFO, KubernetesResource::DISABLE_FETCHING_LOG_INFO, KubernetesResource::GLOBAL, KubernetesResource::LAST_APPLIED_ANNOTATION, KubernetesResource::LOG_LINE_COUNT, KubernetesResource::SENSITIVE_TEMPLATE_CONTENT, KubernetesResource::SERVER_DRY_RUNNABLE, KubernetesResource::SERVER_DRY_RUN_DISABLED_ERROR, KubernetesResource::STANDARD_TIMEOUT_MESSAGE, KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION, KubernetesResource::UNUSUAL_FAILURE_MESSAGE

Instance Attribute Summary collapse

Attributes inherited from KubernetesResource

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

Instance Method Summary collapse

Methods inherited from PodSetBase

#failure_message, #fetch_debug_logs, #fetch_events, #print_debug_logs?, #timeout_message

Methods inherited from KubernetesResource

#<=>, #after_sync, build, class_for_kind, #current_generation, #debug_message, #deploy_method, #deploy_method_override, #deploy_started?, #deploy_timed_out?, #disappeared?, #exists?, #failure_message, #fetch_events, #file_path, #global?, #group, #id, kind, #kubectl_resource_type, #observed_generation, #pretty_status, #pretty_timeout_type, #report_status_to_statsd, #selected?, #sensitive_template_content?, #server_dry_run_validated?, #server_dry_runnable_resource?, #sync_debug_info, #terminating?, #timeout, timeout, #timeout_message, #timeout_override, #to_kubeclient_resource, #use_generated_name, #uses_generate_name?, #validate_definition, #validation_error_msg, #validation_failed?, #version

Constructor Details

#initialize(namespace:, context:, definition:, logger:, statsd_tags: nil, parent: nil, deploy_started_at: nil) ⇒ ReplicaSet

Returns a new instance of ReplicaSet.


10
11
12
13
14
15
16
17
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 10

def initialize(namespace:, context:, definition:, logger:, statsd_tags: nil,
  parent: nil, deploy_started_at: nil)
  @parent = parent
  @deploy_started_at = deploy_started_at
  @pods = []
  super(namespace: namespace, context: context, definition: definition,
        logger: logger, statsd_tags: statsd_tags)
end

Instance Attribute Details

#podsObject (readonly)

Returns the value of attribute pods.


8
9
10
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 8

def pods
  @pods
end

Instance Method Details

#available_replicasObject


51
52
53
54
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 51

def available_replicas
  return -1 unless exists?
  rollout_data["availableReplicas"].to_i
end

#deploy_failed?Boolean

Returns:

  • (Boolean)

35
36
37
38
39
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 35

def deploy_failed?
  pods.present? &&
  pods.all?(&:deploy_failed?) &&
  !stale_status?
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)

29
30
31
32
33
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 29

def deploy_succeeded?
  return false if stale_status?
  desired_replicas == rollout_data["availableReplicas"].to_i &&
  desired_replicas == rollout_data["readyReplicas"].to_i
end

#desired_replicasObject


41
42
43
44
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 41

def desired_replicas
  return -1 unless exists?
  @instance_data["spec"]["replicas"].to_i
end

#ready_replicasObject


46
47
48
49
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 46

def ready_replicas
  return -1 unless exists?
  rollout_data['readyReplicas'].to_i
end

#statusObject


24
25
26
27
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 24

def status
  return super unless rollout_data.present?
  rollout_data.map { |state_replicas, num| "#{num} #{state_replicas.chop.pluralize(num)}" }.join(", ")
end

#sync(cache) ⇒ Object


19
20
21
22
# File 'lib/krane/kubernetes_resource/replica_set.rb', line 19

def sync(cache)
  super
  @pods = exists? ? find_pods(cache) : []
end