class Krane::ReplicaSet

Constants

TIMEOUT

Attributes

pods[R]

Public Class Methods

new(namespace:, context:, definition:, logger:, statsd_tags: nil, parent: nil, deploy_started_at: nil) click to toggle source
Calls superclass method Krane::KubernetesResource::new
# File lib/krane/kubernetes_resource/replica_set.rb, line 9
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

Public Instance Methods

available_replicas() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 50
def available_replicas
  return -1 unless exists?
  rollout_data["availableReplicas"].to_i
end
deploy_failed?() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 34
def deploy_failed?
  pods.present? &&
  pods.all?(&:deploy_failed?) &&
  !stale_status?
end
deploy_succeeded?() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 28
def deploy_succeeded?
  return false if stale_status?
  desired_replicas == rollout_data["availableReplicas"].to_i &&
  desired_replicas == rollout_data["readyReplicas"].to_i
end
desired_replicas() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 40
def desired_replicas
  return -1 unless exists?
  @instance_data["spec"]["replicas"].to_i
end
ready_replicas() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 45
def ready_replicas
  return -1 unless exists?
  rollout_data['readyReplicas'].to_i
end
status() click to toggle source
Calls superclass method Krane::KubernetesResource#status
# File lib/krane/kubernetes_resource/replica_set.rb, line 23
def status
  return super unless rollout_data.present?
  rollout_data.map { |state_replicas, num| "#{num} #{state_replicas.chop.pluralize(num)}" }.join(", ")
end
sync(cache) click to toggle source
Calls superclass method Krane::KubernetesResource#sync
# File lib/krane/kubernetes_resource/replica_set.rb, line 18
def sync(cache)
  super
  @pods = fetch_pods_if_needed(cache) || []
end

Private Instance Methods

fetch_pods_if_needed(cache) click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 61
def fetch_pods_if_needed(cache)
  # If the ReplicaSet doesn't exist, its pods won't either
  return unless exists?
  # If the status hasn't been updated yet, we're not going to make a determination anyway
  return if stale_status?
  # If we don't want any pods at all, we don't need to look for them
  return if desired_replicas == 0
  # We only need to fetch pods so that deploy_failed? can check that they aren't ALL bad.
  # If we can already tell some pods are ok from the RS data, don't bother fetching them (which can be expensive)
  # Lower numbers here make us more susceptible to being fooled by replicas without probes briefly appearing ready
  return if ready_replicas > 1

  find_pods(cache)
end
parent_of_pod?(pod_data) click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 83
def parent_of_pod?(pod_data)
  return false unless pod_data.dig("metadata", "ownerReferences")
  pod_data["metadata"]["ownerReferences"].any? { |ref| ref["uid"] == @instance_data["metadata"]["uid"] }
end
rollout_data() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 76
def rollout_data
  return { "replicas" => 0 } unless exists?
  { "replicas" => 0 }.merge(
    @instance_data["status"].slice("replicas", "availableReplicas", "readyReplicas")
  )
end
stale_status?() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 57
def stale_status?
  observed_generation != current_generation
end
unmanaged?() click to toggle source
# File lib/krane/kubernetes_resource/replica_set.rb, line 88
def unmanaged?
  @parent.blank?
end