Skip to content
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

Merged
merged 3 commits into from
Oct 24, 2018
Merged

Conversation

dturn
Copy link
Contributor

@dturn dturn commented Oct 23, 2018

test_jobs_can_fail is flakey due to not checking the status condition of jobs. So let's check it.

fixes: #350

@@ -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
Copy link
Contributor

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?

Copy link
Contributor

@KnVerey KnVerey left a 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|
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the parentheses?

Copy link
Contributor Author

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 = {
Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Contributor Author

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.

@dturn
Copy link
Contributor Author

dturn commented Oct 24, 2018

Screen shot of the error message:
screen shot 2018-10-24 at 11 02 58 am

@dturn dturn merged commit b9827c1 into master Oct 24, 2018
@dturn dturn deleted the job-failure-condition branch October 24, 2018 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_jobs_can_fail is flakey and may point to a real problem
3 participants