Class: KubernetesDeploy::CustomResourceDefinition

Inherits:
KubernetesResource show all
Defined in:
lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb

Constant Summary collapse

TIMEOUT =
2.minutes
ROLLOUT_CONDITIONS_ANNOTATION =
"kubernetes-deploy.shopify.io/instance-rollout-conditions"
TIMEOUT_FOR_INSTANCE_ANNOTATION =
"kubernetes-deploy.shopify.io/instance-timeout"
GLOBAL =
true

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::KUBECTL_OUTPUT_IS_SENSITIVE, KubernetesResource::LAST_APPLIED_ANNOTATION, KubernetesResource::LOG_LINE_COUNT, KubernetesResource::STANDARD_TIMEOUT_MESSAGE, KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION, KubernetesResource::UNUSUAL_FAILURE_MESSAGE

Instance Attribute Summary

Attributes inherited from KubernetesResource

#context, #deploy_started_at, #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?, #id, #initialize, kind, #kubectl_output_is_sensitive?, #kubectl_resource_type, #observed_generation, #pretty_status, #pretty_timeout_type, #report_status_to_statsd, #sync, #sync_debug_info, #terminating?, timeout, #timeout, #timeout_override, #to_kubeclient_resource, #validation_error_msg, #validation_failed?

Constructor Details

This class inherits a constructor from KubernetesDeploy::KubernetesResource

Instance Method Details

#deploy_failed?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 15

def deploy_failed?
  names_accepted_status == "False"
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 11

def deploy_succeeded?
  names_accepted_status == "True"
end

#group_version_kindObject



40
41
42
43
44
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 40

def group_version_kind
  group = @definition.dig("spec", "group")
  version = @definition.dig("spec", "version")
  "#{group}/#{version}/#{kind}"
end

#kindObject



46
47
48
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 46

def kind
  @definition.dig("spec", "names", "kind")
end

#nameObject



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

def name
  @definition.dig("metadata", "name")
end

#prunable?Boolean

Returns:

  • (Boolean)


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

def prunable?
  prunable = @definition.dig("metadata", "annotations", "kubernetes-deploy.shopify.io/prunable")
  prunable == "true"
end

#rollout_conditionsObject



59
60
61
62
63
64
65
66
67
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 59

def rollout_conditions
  return @rollout_conditions if defined?(@rollout_conditions)

  @rollout_conditions = if rollout_conditions_annotation
    RolloutConditions.from_annotation(rollout_conditions_annotation)
  end
rescue RolloutConditionsError
  @rollout_conditions = nil
end

#statusObject



30
31
32
33
34
35
36
37
38
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 30

def status
  if !exists?
    super
  elsif deploy_succeeded?
    "Names accepted"
  else
    "#{names_accepted_condition['reason']} (#{names_accepted_condition['message']})"
  end
end

#timeout_for_instanceObject



23
24
25
26
27
28
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 23

def timeout_for_instance
  timeout = @definition.dig("metadata", "annotations", TIMEOUT_FOR_INSTANCE_ANNOTATION)
  DurationParser.new(timeout).parse!.to_i
rescue DurationParser::ParsingError
  nil
end

#timeout_messageObject



19
20
21
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 19

def timeout_message
  "The names this CRD is attempting to register were neither accepted nor rejected in time"
end

#validate_definitionObject



69
70
71
72
73
74
75
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 69

def validate_definition(*)
  super

  validate_rollout_conditions
rescue RolloutConditionsError => e
  @validation_errors << "Annotation #{ROLLOUT_CONDITIONS_ANNOTATION} on #{name} is invalid: #{e}"
end

#validate_rollout_conditionsObject



77
78
79
80
81
82
83
84
# File 'lib/kubernetes-deploy/kubernetes_resource/custom_resource_definition.rb', line 77

def validate_rollout_conditions
  if rollout_conditions_annotation && @rollout_conditions_validated.nil?
    conditions = RolloutConditions.from_annotation(rollout_conditions_annotation)
    conditions.validate!
  end

  @rollout_conditions_validated = true
end