-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check jobs for failure status condition #355
Conversation
@@ -13,6 +13,9 @@ def deploy_succeeded? | |||
def deploy_failed? | |||
return false unless deploy_started? | |||
return false unless @instance_data.dig("spec", "backoffLimit").present? | |||
(@instance_data.dig("status", "conditions") || []).each do |condition| | |||
return true if condition["type"] == 'Failed' && condition['status'] == "True" | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you extract this into a method?
This condition also has richer information about the reason for the failure in its reason/message fields. Let's adjust failure_message
to include that information if we have it.
Can you also add tests? Maybe unit tests that show deploy_failed?
is true with either of the statuses I discovered are possible on the issue?
55d2961
to
294aefc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests! Remaining comments are just stylistic; I don't need to review again.
private | ||
|
||
def failed_status_condition | ||
(@instance_data.dig("status", "conditions") || []).detect do |condition| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this would be easier to read if it used a guard clause instead of the || []
trick. I personally prefer find
over detect
, but I see we already use both in this repo.
@@ -30,8 +31,20 @@ def status | |||
end | |||
end | |||
|
|||
def failure_message | |||
if (condition = failed_status_condition.presence) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the parentheses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a habit from a style checker, but basically saying I'm intentionally using =
and didn't mean to use ==
end | ||
|
||
def test_job_fails_without_failed_status_condition | ||
status = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the data this contains isn't a status in this test
job = KubernetesDeploy::Job.new(namespace: 'test', context: 'nope', definition: template, | ||
logger: @logger) | ||
job.deploy_started_at = Time.now.utc | ||
mediator = KubernetesDeploy::SyncMediator.new(namespace: 'test', context: 'minikube', logger: logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think this could change anything, but you're using two different fake context names here and two lines above this (and accessing the logger differently)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually copied from the pod test, I'll fix both.
cbbdb4c
to
bbd97a3
Compare
bbd97a3
to
aa5b49c
Compare
test_jobs_can_fail is flakey due to not checking the status condition of jobs. So let's check it.
fixes: #350