Class: Krane::CustomResourceDefinition

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

Constant Summary collapse

TIMEOUT =
2.minutes
ROLLOUT_CONDITIONS_ANNOTATION_SUFFIX =
"instance-rollout-conditions"
ROLLOUT_CONDITIONS_ANNOTATION =
"krane.shopify.io/#{ROLLOUT_CONDITIONS_ANNOTATION_SUFFIX}"
TIMEOUT_FOR_INSTANCE_ANNOTATION =
"krane.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::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, #sync_debug_info, #terminating?, timeout, #timeout, #timeout_override, #to_kubeclient_resource, #use_generated_name, #uses_generate_name?, #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)


14
15
16
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 14

def deploy_failed?
  names_accepted_status == "False"
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 10

def deploy_succeeded?
  names_accepted_status == "True"
end

#group_version_kindObject



39
40
41
42
43
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 39

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

#kindObject



45
46
47
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 45

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

#predeployed?Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 54

def predeployed?
  predeployed = krane_annotation_value("predeployed")
  predeployed.nil? || predeployed == "true"
end

#prunable?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 49

def prunable?
  prunable = krane_annotation_value("prunable")
  prunable == "true"
end

#rollout_conditionsObject



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

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

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

#statusObject



29
30
31
32
33
34
35
36
37
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 29

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

#timeout_for_instanceObject



22
23
24
25
26
27
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 22

def timeout_for_instance
  timeout = krane_annotation_value("instance-timeout")
  DurationParser.new(timeout).parse!.to_i
rescue DurationParser::ParsingError
  nil
end

#timeout_messageObject



18
19
20
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 18

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
76
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 69

def validate_definition(*)
  super

  validate_rollout_conditions
rescue RolloutConditionsError => e
  @validation_errors << "Annotation #{krane_annotation_key(ROLLOUT_CONDITIONS_ANNOTATION_SUFFIX)} "\
    "on #{name} is invalid: #{e}"
end

#validate_rollout_conditionsObject



78
79
80
81
82
83
84
85
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 78

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

  @rollout_conditions_validated = true
end