Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Adding linting to Chart and values yaml files #2429

Merged
merged 1 commit into from
Oct 9, 2017

Conversation

mattfarina
Copy link
Contributor

This does not lint yaml templates as they are templates rather
than valid yaml files. They cannot be linted with a normal linter

yamllint is used for linting. This is an existing Python project
https://github.com/adrienverge/yamllint

The rules are not the default rules and are stored in their
entirity so they can be controlled over time

The existance of a Chart.yaml file and values.yaml file is checked
and an error is thrown if one is missing. Helm lint will not
detect a chart if Chart.yaml is missing and if a values.yaml file
is missing it is noted as info.

The run function is introduced to enable running all the linters,
capturing non-zero exit codes, and exiting with a non-zdero code
if any of them fail. This is used instead of exiting when the
first failure happens to provide more feedback to chart developers.

/cc @prydonius @viglesiasce @unguiculus

You can see an example of a failure at https://circleci.com/gh/mattfarina/charts/41

There are docs on configuring yamllint including the rules. I tried to tailor our rules to the existing charts. Though, many of the charts fail the rules and are inconsistent.

You can take a look at all the lint failures we have in the existing stable and incubator charts in this gist based on the rules in the config file here.

Once we agree on a set of rules I can create separate PRs to clean up the existing charts.

References #2373

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 6, 2017
Copy link
Member

@unguiculus unguiculus left a comment

Choose a reason for hiding this comment

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

Just a few nits. Looks fine otherwise. Maybe we can use helm template in the future to generate Yaml files that we can feed into the linter.


# If a Chart.yaml file is present lint it. Otherwise report an error
# because one should exist
if [ -e ${directory}/Chart.yaml ]
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer if you stick to the existing style and put then on the same line.

if [ -e ${directory}/Chart.yaml ]; then


# If a values.yaml file is present lint it. Otherwise report an error
# because one should exist
if [ -e ${directory}/values.yaml ]
Copy link
Member

Choose a reason for hiding this comment

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

See above.

# because one should exist
if [ -e ${directory}/Chart.yaml ]
then
run yamllint -c test/circle/lintconf.yml ${directory}/Chart.yaml
Copy link
Member

Choose a reason for hiding this comment

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

The rest of the file seems to be indented with two spaces. Can we agree on one style?

$@
local ret=$?
if [ $ret -ne 0 ]; then
exitCode=1
Copy link
Member

Choose a reason for hiding this comment

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

Inconsistent indentation.

This does not lint yaml templates as they are templates rather
than valid yaml files. They cannot be linted with a normal linter

yamllint is used for linting. This is an existing Python project
https://github.com/adrienverge/yamllint

The rules are not the default rules and are stored in their
entirity so they can be controlled over time

The existance of a Chart.yaml file and values.yaml file is checked
and an error is thrown if one is missing. Helm lint will not
detect a chart if Chart.yaml is missing and if a values.yaml file
is missing it is noted as info.

The run function is introduced to enable running all the linters,
capturing non-zero exit codes, and exiting with a non-zdero code
if any of them fail. This is used instead of exiting when the
first failure happens to provide more feedback to chart developers.
@mattfarina
Copy link
Contributor Author

@unguiculus Sorry about that. Thanks for catching those. I'm too used to my editor fixing issues like these automatically. I see I don't have that setup for shell scripts.

I've updated with a fix for the formatting.

@unguiculus
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 9, 2017
@unguiculus unguiculus merged commit 2f12841 into helm:master Oct 9, 2017
@mattfarina mattfarina deleted the yamllint branch October 9, 2017 20:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants