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

HIP-0019 adds .helmlintignore functionality to pkg/lint #13257

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dpritchett
Copy link

@dpritchett dpritchett commented Aug 16, 2024

What this PR does / why we need it:

Adds pkg/lint/ignore as proposed in HIP-0019 (helm/community#353). Closes #13133.

By adding a .helmlintignore file at the root of a chart, helm lint can be made to suppress unwanted errors. Ignored lint results (both support.Message and error types can be ignored) will not show up in the helm command's printable output and will not be allowed to "fail" a lint by returning a nonzero error code.

Sample execution with and without the ignorer

Without the ignorer:

> helm lint ./pkg/action/testdata/charts/messy-chart-with-lintignore
==> Linting ./pkg/action/testdata/charts/messy-chart-with-lintignore
[ERROR] Chart.yaml: apiVersion is required. The value must be either "v1" or "v2"
[INFO] Chart.yaml: icon is recommended
[INFO] values.yaml: file does not exist
[WARNING] /Users/daniel/radius/bb/helm/pkg/action/testdata/charts/messy-chart-with-lintignore: chart directory is missing these dependencies: mariadb

Error: 1 chart(s) linted, 1 chart(s) failed

With the this branch's new pkg/lint/ignore in place:

> go run ./cmd/helm lint ./pkg/action/testdata/charts/messy-chart-with-lintignore --lint-ignore-file=./pkg/action/testdata/charts/messy-chart-with-lintignore/.helmlintignore
==> Linting ./pkg/action/testdata/charts/messy-chart-with-lintignore

1 chart(s) linted, 0 chart(s) failed

Example .helmlintignore file

# file-specific rules
fake-chart-name/templates/shared-secrets/self-signed-cert-job.yml <include "fake-chart-name.ingress.tls.configured" .>
fake-chart-name/charts/fake-chart-name/charts/webservice/templates/service.yaml <include "lastname" .>
certmanager-issuer/templates/rbac-config.yaml <.Values.global.ingress>
fake-chart-name/charts/webservice/templates/tests/tests.yaml
fake-chart-name-exporter/templates/serviceaccount.yaml <.Values.global.serviceAccount.enabled>
fake-chart-name-pages/templates/serviceaccount.yaml <.Values.global.serviceAccount.enabled>
blockstorage/templates/pdb.yaml
registry/templates/serviceaccount.yaml

# fallback rules for cases where current `MatchesErrors` implementations can't easily associate error with a filename
error_lint_ignore=icon is recommended
error_lint_ignore=file does not exist
error_lint_ignore=chart metadata is missing these dependencies**
  1. Where the Ignorer's matchers can easily associate an error string with a specific file path then the more tightly-scoped offending-file-name.yaml error message to ignore here ignore form works as above.
  2. Where the error is not specific to a template yaml file or is otherwise difficult to easily attribute to a file path, then the end user can use the error_lint_ignore=message i don't want to see right now form as a fallback.

Special notes for your reviewer:

  • pkg/lint/ignore's Ignorer is the primary entrypoint, and is threaded through cmd/helm/lint.go and pkg/action/lint.go accordingly
  • the Ignorer presents a MatchesErrors interface as an extensible method of registering ignore rules. While we only include some fairly simple ignore rule syntax (see pkg/lint/ignore/rule_loaders) in this PR it should be straightforward to layer in more complex ignore rule parsing in future PRs if needed.

On more complex ignore rules

More advanced lint result suppression (e.g. adding short codes to every possible linter response so end users could try a --ignore-lint-type=E123 will may require a more thorough refactoring of the entire lint package which we did not want to attempt just yet given the 50+ existing error signatures (rg "return.*errors\.Wrap" pkg/action | wc -l gets 54 lines at the moment)

Companion PR for end user documentation

See helm/helm-www#1617

If applicable:

  • [Y] this PR contains user facing changes (the docs needed label should be applied if so)
  • [Y] this PR contains unit tests
  • [N] this PR has been tested for backwards compatibility

Co-authored-by: Danilo Patrucco danilo.patrucco@gmail.com

See HIP-0019 proposal at helm/community: helm/community#353

Co-authored-by: Danilo Patrucco <danilo.patrucco@gmail.com>

Signed-off-by: Daniel J. Pritchett <dpritchett@radiusmethod.com>
- adds ignorer usage to cmd/helm/lint.go
- adds ignorer usage to pkg/action/lint.go and its lint_test.go

See HIP-0019 proposal at helm/community: helm/community#353

Co-authored-by: Danilo Patrucco <danilo.patrucco@gmail.com>

Signed-off-by: Daniel J. Pritchett <dpritchett@radiusmethod.com>
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 16, 2024
@dpritchett
Copy link
Author

Tagging @mattfarina and @danilo-patrucco as they were the original folks to discuss this in #13133.

Co-authored-by: Danilo Patrucco <danilo.patrucco@gmail.com>

Signed-off-by: Daniel J. Pritchett <dpritchett@radiusmethod.com>
@danilo-patrucco
Copy link

adding @gjenkins8 to the comments for a review

@danilo-patrucco
Copy link

related PRs

@danilo-patrucco
Copy link

adding @sabre1041 to the comments for a review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helm lint exlusion list
2 participants