Skip to content

Commit

Permalink
partial pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Jan 18, 2019
1 parent 55f62ab commit 796021d
Show file tree
Hide file tree
Showing 5 changed files with 463 additions and 448 deletions.
15 changes: 13 additions & 2 deletions lib/kubernetes-deploy/kubernetes_resource/custom_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module KubernetesDeploy
class CustomResource < KubernetesResource
TIMEOUT_MESSAGE_DIFFERENT_GENERATIONS = <<~MSG
This resource's status could not be used to determine rollout success because it was still out of date
(.metadata.generation != .status.observedGeneration) after #{timeout}s.
(.metadata.generation != .status.observedGeneration).
MSG

def initialize(namespace:, context:, definition:, logger:, statsd_tags: [], crd:)
Expand Down Expand Up @@ -45,16 +45,27 @@ def timeout_message
end
end

def status
if !exists? || rollout_conditions.nil?
super
elsif deploy_succeeded?
"Healthy"
elsif deploy_failed?
"Unhealthy"
end
end

def type
kind
end

def validate_definition(kubectl)
super

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

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def kind
@definition.dig("spec", "names", "kind")
end

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

def prunable?
prunable = @definition.dig("metadata", "annotations", "kubernetes-deploy.shopify.io/prunable")
prunable == "true"
Expand All @@ -67,7 +71,7 @@ def validate_definition(_)

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

def validate_rollout_conditions
Expand Down
3 changes: 1 addition & 2 deletions lib/kubernetes-deploy/rollout_conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def validate!
def validate_conditions(conditions, source_key, required: true)
return [] unless conditions.present? || required
errors = []
errors << "Missing required key '#{source_key}'" if conditions.nil?
errors << "#{source_key} should be Array but found #{conditions[source_key].class}" unless conditions.is_a?(Array)
errors << "#{source_key} should be Array but found #{conditions.class}" unless conditions.is_a?(Array)
errors << "#{source_key} must contain at least one entry" if conditions.empty?
return errors if errors.present?

Expand Down
Loading

0 comments on commit 796021d

Please sign in to comment.