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 =
"instance-rollout-conditions"
TIMEOUT_FOR_INSTANCE_ANNOTATION =
"instance-timeout"
GLOBAL =
true

Constants inherited from KubernetesResource

KubernetesResource::ALLOWED_DEPLOY_METHOD_OVERRIDES, KubernetesResource::DEBUG_RESOURCE_NOT_FOUND_MESSAGE, KubernetesResource::DEPLOY_METHOD_OVERRIDE_ANNOTATION, 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::SYNC_DEPENDENCIES, KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION, 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_method_override, #deploy_started?, #deploy_timed_out?, #disappeared?, #exists?, #failure_message, #fetch_events, #file_path, #global?, #id, #initialize, kind, #kubectl_resource_type, #observed_generation, #pretty_status, #pretty_timeout_type, #report_status_to_statsd, #selected?, #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?, #version

Constructor Details

This class inherits a constructor from Krane::KubernetesResource

Instance Method Details

#deploy_failed?Boolean

Returns:

  • (Boolean)

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

def deploy_failed?
  names_accepted_status == "False"
end

#deploy_succeeded?Boolean

Returns:

  • (Boolean)

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

def deploy_succeeded?
  names_accepted_status == "True"
end

#groupObject


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

def group
  @definition.dig("spec", "group")
end

#group_version_kindObject


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

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

#kindObject


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

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

#predeployed?Boolean

Returns:

  • (Boolean)

57
58
59
60
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 57

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

#prunable?Boolean

Returns:

  • (Boolean)

52
53
54
55
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 52

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

#rollout_conditionsObject


62
63
64
65
66
67
68
69
70
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 62

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

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

#statusObject


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

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

#timeout_for_instanceObject


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

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

#timeout_messageObject


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

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

#validate_definitionObject


72
73
74
75
76
77
78
79
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 72

def validate_definition(*, **)
  super

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

#validate_rollout_conditionsObject


81
82
83
84
85
86
87
88
# File 'lib/krane/kubernetes_resource/custom_resource_definition.rb', line 81

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

  @rollout_conditions_validated = true
end