class Krane::Service

Constants

TIMEOUT

Public Instance Methods

deploy_failed?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 41
def deploy_failed?
  false
end
deploy_succeeded?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 33
def deploy_succeeded?
  return false unless exists?
  return published? if requires_publishing?
  return exists? unless requires_endpoints?
  # We can't use endpoints if we want the service to be able to fail fast when the pods are down
  exposes_zero_replica_workload? || selects_some_pods?
end
status() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 19
def status
  if !exists?
    "Not found"
  elsif requires_publishing? && !published?
    "LoadBalancer IP address is not provisioned yet"
  elsif !requires_endpoints?
    "Doesn't require any endpoints"
  elsif selects_some_pods?
    "Selects at least 1 pod"
  else
    "Selects 0 pods"
  end
end
sync(cache) click to toggle source
Calls superclass method Krane::KubernetesResource#sync
# File lib/krane/kubernetes_resource/service.rb, line 8
def sync(cache)
  super
  if exists? && selector.present?
    @related_pods = cache.get_all(Pod.kind, selector)
    @related_workloads = fetch_related_workloads(cache)
  else
    @related_pods = []
    @related_workloads = []
  end
end
timeout_message() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 45
def timeout_message
  "This service does not seem to select any pods and this is likely invalid. "\
  "Please confirm the spec.selector is correct and the targeted workload is healthy."
end

Private Instance Methods

exposes_zero_replica_workload?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 60
def exposes_zero_replica_workload?
  return false unless related_replica_count
  related_replica_count == 0
end
external_name_svc?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 92
def external_name_svc?
  @definition["spec"]["type"] == "ExternalName"
end
published?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 100
def published?
  @instance_data.dig('status', 'loadBalancer', 'ingress').present?
end
requires_endpoints?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 65
def requires_endpoints?
  # services of type External don't have endpoints
  return false if external_name_svc?

  # problem counting replicas - by default, assume endpoints are required
  return true if related_replica_count.blank?

  related_replica_count > 0
end
requires_publishing?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 96
def requires_publishing?
  @definition["spec"]["type"] == "LoadBalancer"
end
selector() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 80
def selector
  @definition["spec"].fetch("selector", {})
end
selects_some_pods?() click to toggle source
# File lib/krane/kubernetes_resource/service.rb, line 75
def selects_some_pods?
  return false unless selector.present?
  @related_pods.present?
end