Skip to content

Commit

Permalink
Annotation to decalre monitorability (fallback to default behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Nov 13, 2018
1 parent 5eb4c2c commit bc6bf72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/kubernetes-deploy/kubernetes_resource/custom_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ def timeout
end

def deploy_succeeded?
return false unless deploy_started?
unless @success_assumption_warning_shown
@logger.warn("Don't know how to monitor resources of type #{kind}. Assuming #{id} deployed successfully.")
@success_assumption_warning_shown = true
if monitor_rollout?
return false unless ready_status = @instance_data&.dig("status", "Conditions")&.find { |cond| cond["type"] == "Ready" }
ready_status["status"] == "True"
else
super
end
true
end

def deploy_failed?
false
if monitor_rollout?
return false unless failed_status = @instance_data&.dig("status", "Conditions")&.find { |cond| cond["type"] == "Failed" }
failed_status["status"] == "True"
else
super
end
end

def id
Expand All @@ -45,5 +50,9 @@ def type
def kind
@definition["kind"]
end

def monitor_rollout?
@crd.monitor_rollouts?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module KubernetesDeploy
class CustomResourceDefinition < KubernetesResource
TIMEOUT = 2.minutes
CHILD_CR_TIMEOUT_ANNOTATION = "kubernetes-deploy.shopify.io/cr-timeout-override"
MONITOR_ROLLOUT_ANNOTATION = "kubernetes-deploy.shopify.io/monitor-rollout"
GLOBAL = true

def deploy_succeeded?
Expand Down Expand Up @@ -46,6 +47,10 @@ def timeout_for_children
@definition.dig("metadata", "annotations", CHILD_CR_TIMEOUT_ANNOTATION)&.to_i
end

def monitor_rollouts?
@definition.dig("metadata", "annotations", MONITOR_ROLLOUT_ANNOTATION) == "true"
end

private

def names_accepted_condition
Expand Down

0 comments on commit bc6bf72

Please sign in to comment.