Class: Krane::Service

Inherits:
KubernetesResource show all
Defined in:
lib/krane/kubernetes_resource/service.rb

Constant Summary collapse

TIMEOUT =
7.minutes

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::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::TIMEOUT_OVERRIDE_ANNOTATION_DEPRECATED, KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION_SUFFIX, KubernetesResource::UNUSUAL_FAILURE_MESSAGE

Instance Attribute Summary

Attributes inherited from KubernetesResource

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

Instance Method Summary collapse

Methods inherited from KubernetesResource

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

Constructor Details

This class inherits a constructor from Krane::KubernetesResource

Instance Method Details

#deploy_failed?Boolean

Returns:

  • (Boolean)


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

def deploy_failed?
  false
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# 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

#statusObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# 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_messageObject



45
46
47
48
# 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