Skip to content

Return correct exit code when using values files #32

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

Merged
merged 2 commits into from
Oct 1, 2018

Conversation

dcarley
Copy link
Contributor

@dcarley dcarley commented Sep 28, 2018

The return values from the individual calls to lint_chart_with_single_config
are masked by the other operations in the lint_chart_with_all_configs
function.

When helm lint reports an error to STDERR but the chart is incorrectly
given a success tick and the exit code of chart_test.sh is 0 for
success. An example using quay.io/helmpack/chart-testing:v1.1.0:

==> Linting charts/nomad-server
[ERROR] templates/: render error in "nomad-server/templates/nomad-server.yaml": template: nomad-server/templates/nomad-server.yaml:55:28: executing "nomad-server/templates/nomad-server.yaml" at <{{template "fullname...>: template "fullname" not defined

Error: 1 chart(s) linted, 1 chart(s) failed
--------------------------------------------------------------------------------
 ✔︎ charts/nomad-server
--------------------------------------------------------------------------------
 dcarley@cci-mbp  ~/p/g/s/g/c/circle-external-services-chart   master  echo $?
0s

Fix this by copying the pattern used in other functions of tracking
failures in a local boolean variable and using that to determine the
return code at the end of the function. This is the result after:

==> Linting charts/nomad-server
[ERROR] templates/: render error in "nomad-server/templates/nomad-server.yaml": template: nomad-server/templates/nomad-server.yaml:55:28: executing "nomad-server/templates/nomad-server.yaml" at <{{template "fullname...>: template "fullname" not defined

Error: 1 chart(s) linted, 1 chart(s) failed
--------------------------------------------------------------------------------
 ✖︎  charts/nomad-server
--------------------------------------------------------------------------------
 ✘ dcarley@cci-mbp  ~/p/g/s/g/c/circle-external-services-chart   master  echo $?
1

There are probably other bugs like this. Shell scripting does not
provide safe error handling for these cases and it's difficult to write
unit tests for. This is another good reason why the proposal in #29 to
re-implement in another language is a good idea.

The return values from the individual calls to `lint_chart_with_single_config`
are masked by the other operations in the `lint_chart_with_all_configs`
function.

When `helm lint` reports an error to STDERR but the chart is incorrectly
given a success tick and the exit code of `chart_test.sh` is 0 for
success. An example using `quay.io/helmpack/chart-testing:v1.1.0`:

    ==> Linting charts/nomad-server
    [ERROR] templates/: render error in "nomad-server/templates/nomad-server.yaml": template: nomad-server/templates/nomad-server.yaml:55:28: executing "nomad-server/templates/nomad-server.yaml" at <{{template "fullname...>: template "fullname" not defined

    Error: 1 chart(s) linted, 1 chart(s) failed
    --------------------------------------------------------------------------------
     ✔︎ charts/nomad-server
    --------------------------------------------------------------------------------
     dcarley@cci-mbp  ~/p/g/s/g/c/circle-external-services-chart   master  echo $?
    0s

Fix this by copying the pattern used in other functions of tracking
failures in a local boolean variable and using that to determine the
return code at the end of the function. This is the result after:

    ==> Linting charts/nomad-server
    [ERROR] templates/: render error in "nomad-server/templates/nomad-server.yaml": template: nomad-server/templates/nomad-server.yaml:55:28: executing "nomad-server/templates/nomad-server.yaml" at <{{template "fullname...>: template "fullname" not defined

    Error: 1 chart(s) linted, 1 chart(s) failed
    --------------------------------------------------------------------------------
     ✖︎  charts/nomad-server
    --------------------------------------------------------------------------------
     ✘ dcarley@cci-mbp  ~/p/g/s/g/c/circle-external-services-chart   master  echo $?
    1

There are probably other bugs like this. Shell scripting does not
provide safe error handling for these cases and it's difficult to write
unit tests for. This is another good reason why the proposal in helm#29 to
re-implement in another language is a good idea.

Signed-off-by: Dan Carley <dan.carley@gmail.com>
@dcarley dcarley force-pushed the fix_exit_for_values branch from bf065ff to 691f232 Compare September 28, 2018 09:16
@unguiculus
Copy link
Member

Thanks for fixing this. I basically fixed the same thing a while ago in #18 for the install part and didn't see the same problem existed for the linting part. You fixed the problem a little differently than I did. I would like to have this done consistently in both places. Would you mind updating the PR? I don't care whether you choose your way or mine, but it should be solved the same way in both places. Thanks.

@rimusz
Copy link
Contributor

rimusz commented Oct 1, 2018

yes either way is fine, it just needs to be consistent

The `|| error=true` pattern is already used in a few other places. This
makes the change from 64c1e52 consistent with the others.

Signed-off-by: Dan Carley <dan.carley@gmail.com>
@dcarley dcarley force-pushed the fix_exit_for_values branch from 425886d to 5bfc0cf Compare October 1, 2018 15:43
@dcarley
Copy link
Contributor Author

dcarley commented Oct 1, 2018

No problem. I've gone with the || error=true pattern since that was already used in a few other places.

@rimusz
Copy link
Contributor

rimusz commented Oct 1, 2018

/lgtm

@unguiculus unguiculus merged commit 4960e30 into helm:master Oct 1, 2018
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.

3 participants