Commit Graph

157 Commits

Author SHA1 Message Date
anessi acf7158565
feat(helm): add --skip-schema-validation flag to helm 'install', 'upgrade' and 'lint'
When --skip-schema-validation is set, any schema contain in the helm chart is ignored. Defaults to 'false'.

Closes #10398

Signed-off-by: anessi <16045045+anessi@users.noreply.github.com>
2024-06-25 16:43:48 +02:00
Robert Sirchia d58d7b3762 Fixing all the linting errors
Cleaned up all the linting errors we are getting.

Signed-off-by: Robert Sirchia <rsirchia@outlook.com>
2024-03-11 17:13:34 -04:00
Matt Farina 8e6a5149d2
validation fix
Signed-off-by: Matt Farina <matt.farina@suse.com>
2024-02-07 10:54:15 -05:00
Antoine Deschênes 869c1d2560 lint: Add --kube-version flag to set capabilities and deprecation rules
Signed-off-by: Antoine Deschênes <antoine@antoinedeschenes.com>
2024-01-08 19:35:41 -05:00
Joe Julian 762a1c7adc
Merge pull request #12688 from mattfarina/bump-go-1.21
Update to Go 1.21 for builds
2024-01-08 13:53:56 -08:00
Matt Farina 83a76cea6a
Merge pull request #9176 from dastrobu/#9169/lint-dependency-shadowing
lint and validate dependency metadata to reference dependencies with …
2024-01-08 15:56:29 -05:00
Matt Farina 847369c184
Update to Go 1.21 for builds
Noteis:
1. This moves golangci scanning to a GitHub action. This will
   enable inline pointers to issues in the PR where linting fails.
2. Go 1.21 is specified in the go.mod because Kubernetes libs
   require it.
3. The lint issues were removed. Some were fixed while others
   were handled by skipping linting or using _ as an argument.
   Many of these can be refactored later for better cleanup.

Signed-off-by: Matt Farina <matt.farina@suse.com>
2024-01-08 15:48:36 -05:00
Matt Farina 5a1475ee36
Merge pull request #11294 from Juneezee/test/t.TempDir
test: replace `ensure.TempDir` with `t.TempDir`
2023-09-14 09:55:51 -04:00
Joe Julian 126333c525
Merge remote-tracking branch 'upstream/main' into #9169/lint-dependency-shadowing 2023-08-24 12:27:33 -07:00
Joe Julian b12139a6ec
Merge pull request #11586 from jmhbnz/main
Remove warning for template directory not found
2023-08-01 16:32:51 -07:00
Eng Zer Jun 2ceebffc77
test: replace `ensure.TempDir` with `t.TempDir`
This commit replaces `ensure.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ensure.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-07-29 16:11:22 +08:00
James Blair 9dab6e9770
Remove warning for template directory not found.
Some charts don't need a templates directory. The warning appears to originate back when helm expected all charts to contain templates. In CI situations where linting is performed with --strict the lint warning causes unneccessary failures for charts that quite legitimately do not contain a templates directory.

As discussed in #8033 there are no longer any scenarios understood where this warning is helpful so this commit removes it.

Signed-off-by: James Blair <mail@jamesblair.net>
2023-07-09 16:30:04 +12:00
Matt Farina 0a5148faff
Fix multiple bugs in values handling
First, some notes about priority and how some code flow works.

For Helm handling values, the expected order of precidence is:
1. User specified values (e.g CLI)
2. Imported values
3. Parent chart values
4. Subchart values

Helm handles dependency values slightly differently. If there are dependencies
in the charts folder that are not marked as dependencies all of the values,
including nil values, are pulled in. If those charts are listed as a
dependency in the Chart.yaml file than they are processed for import handling.
Prior to the changes here, it caused nil values at the top level to NOT remove
values specified.

The changes:

1. The order of priority was chagned from the list above. Parnet chart values
would override specifically imported values. This is due to a change from
just over a year ago that introduced a bug. That was undone by changing the
precidence when maps were merged.

2. To handle merging while retaining the nil values, which was causing
inconsistent behavior, a new set of Merge functions were introduced. These
functions are just like coalesce except that they DO NOT remove nil/null values.
The new functions are used in a backward compatible manner meaning some new
functions were introduced that called them.

Specific issues fixed (that are known):

Closes #9027

Can now delete subkeys from charts when specified in the parent. This behavior
was previously inconsistent. Sometimes they could be deleted and other times
it did not work. Now it is consistent.

Closes #10899

Imported values (from library or other subcharts) are now used following the
order above.

The previous behavior was inconsistent. import-values using just a string
would import them. When named with a child/parent it did not work if the
parent already had a value. If string and named were mixed the imports
worked if the string happened first but just for the string not the named.
If the named parent/child went first then none of them worked for cases
where the parent already had a value. It was inconsistent and the tests
sometimes mirrored the functionality rather than expected behavior.

Tests for this fall into the sub-packages and are in the template tests
to verify it's happening in the output. Including having values passed
at the CLI as the ultimate highest priority to be used.

This relates to a fix that went in for #9940. The expected values there don't
fit the precedence above where the parent value would override the imported
value. That fix/change introduced more bugs.

Closes #10052

This is the case where imported values using the parent/child designation
just didn't work right. That has been fixed and there are tests. The underlying
issue had to do with the precedence order handling.

Note, a lot of tests were added. Hope we got it more right this time.

Signed-off-by: Matt Farina <matt.farina@suse.com>
2023-06-26 11:37:21 -04:00
Daniel Strobusch 6a4035aea2 lint and validate dependency metadata to reference dependencies with a unique key (name or alias)
Report charts with the following bad dependency specifications as bad charts:

    dependencies:
    - name: foo
      alias: baz # ← baz used twice
      version: 1.0.0
    - name: bar
      alias: baz # ← baz used twice
      version: 1.0.0

    dependencies:
    - name: foo
      alias: bar # ← shadows chart below
      version: 1.0.0
    - name: bar
      version: 1.0.0

    dependencies:
    - name: foo
      version: 1.0.0
    - name: foo # ← chart with same name as above (although version or repo will be different, this will not work currently)
      version: 1.2.3

Closes #9169

Signed-off-by: Daniel Strobusch <1847260+dastrobu@users.noreply.github.com>
2023-05-23 09:03:22 +02:00
wujunwei cd2609d08e add some test case
Signed-off-by: wujunwei <wjw3323@live.com>
2023-03-28 15:04:07 +08:00
wujunwei 8e1c3d0d39 fix comment grammar error.
Signed-off-by: wujunwei <wjw3323@live.com>
2023-03-28 15:04:07 +08:00
wujunwei 316d3fb56a bugfix:(#11391) helm lint infinite loop
when malformed template object

Signed-off-by: wujunwei <wjw3323@live.com>
2023-03-28 15:04:07 +08:00
Matt Farina 4e7e939f19
Updating the Go version in go.mod
At this time both Go 1.19 and 1.20 are supported. The version
specified in the go.mod file is the minimum version we expect Helm
to be compiled against. This is the oldest supported version to
support environments where others compile Helm. The Helm project
is using Go 1.20 to build Helm itself.

Updating to Go 1.19 also includes dealing with io/ioutil
deprecation and some additional linting issues around staticcheck.
All the staticcheck issues were in test files so linting was
skipped for those.

Signed-off-by: Matt Farina <matt.farina@suse.com>
2023-03-22 11:52:30 -04:00
Matt Farina 50c22ed7f9
Bump the Go version
Needed to gofmt source to meet changes in style

Signed-off-by: Matt Farina <matt.farina@suse.com>
2023-03-22 11:29:26 -04:00
Eng Zer Jun 2e3e22a003
test: use `T.TempDir` to create temporary test directory
The directory created by `T.TempDir` is automatically removed when the
test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-02-12 13:54:54 +08:00
Matt Farina 7838fb769d
Fix specifying of Kubernetes version from build scripts
This bug came about because of three issues that this change
corrects:
- The CI scripts run on a pull request did not test building
  Helm. This means that a failure to set a variable using LDFLAGS
  had no opportunity to be caught.
- #8608 provided a means to match the k8s version used in linting
  and chartutil with the version of the package we pull in. With
  one problem. It attempts to set a const as if it were a string.
  This is ignored and everyone missed it.
- #10325 moved those constants to vars so it could be set. This
  looked good and passed tests but missed that you can't set an
  int as if it were a string. See first bullet.

This change fixes this by moved the internal representation to
be a string. These are internal variables not exposed in the public
API which makes this change non-breaking to the API.

Closes #10367

Signed-off-by: Matt Farina <matt.farina@suse.com>
2021-11-18 11:48:02 -05:00
Sverre Boschman 81a373ead5 allow ldflags to overwrite k8s version
Signed-off-by: Sverre Boschman <1142569+sboschman@users.noreply.github.com>
2021-11-09 14:18:07 +01:00
Stuart Drennan 1931b0702d fix(helm): process dependencies import-values
When running helm lint, import-values for dependencies are ignored,
also added test for linting chart with import-values

Closes #9658

Signed-off-by: Stuart Drennan <stuart.drennan@gmail.com>
2021-10-24 11:38:02 +01:00
Adam Reese 53263c6fb7
feat(linter): check for nested resource-policy annotations
The 'helm.sh/resource-policy' annotation is only supported on top level
objects.  The annotation is ignored if given on a nested object within a
list.

Ref #9829

Signed-off-by: Adam Reese <adam@reese.io>
2021-07-06 11:18:15 -07:00
Martin Hickey 699ea6dcef
Merge pull request #9066 from scaat/fix-specification
[FIX]Unified go specification
2021-06-02 11:55:53 +01:00
Mark Sagi-Kazar d5b4e1c5b8
chore: update testdata to use the new ingress template
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-04-25 12:23:03 +02:00
Adam Reese 213a7df2dc
Merge pull request #9416 from croomes/resource-name-validation
Add name validation rules for different object kinds
2021-03-26 10:25:49 -07:00
Simon Croome 6c82c83b3a
Wrap validation error instead of recreating
Signed-off-by: Simon Croome <simon.croome@storageos.com>
2021-03-22 15:59:07 +00:00
Simon Croome 54de1c1f25
Move default to avoid nil check
Signed-off-by: Simon Croome <simon.croome@storageos.com>
2021-03-22 15:59:06 +00:00
Simon Croome ba325bdf7e
Add name validation rules for object kinds
Signed-off-by: Simon Croome <simon@croome.org>

Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Simon Croome <simon.croome@storageos.com>
2021-03-22 15:59:06 +00:00
Josh Soref 2bf8fdf45d
chore: Spelling (#9410)
* spelling: annotate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: asserts

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: behavior

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: binary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: contain

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: copied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependency

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: depending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deprecated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: doesn't

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: donot

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: github

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inputting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: iteration

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: jabberwocky

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: kubernetes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: length

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mismatch

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonexistent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outputs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: panicking

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: plugins

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parsing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: porthos

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: regular

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: resource

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: repositories

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: something

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: strict

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: string

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unknown

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2021-03-15 21:11:57 -04:00
Matthew Luckam 592c338242 updated unit tests to conform with helm best practices
Signed-off-by: Matthew Luckam <Matthew.Luckam@peraton.com>
2021-03-03 11:18:34 -05:00
Matthew Luckam f402994461 corrected order of helm lint coalescing of multiple values files
Signed-off-by: Matthew Luckam <Matthew.Luckam@peraton.com>
2021-03-03 11:18:34 -05:00
Joe Julian fdcd22ef58
Reduce linting severity for users of out-of-date kubernetes (#8608)
* Reduce linting severity for users of out-of-date kubernetes

Fixes #8596

Signed-off-by: Joe Julian <me@joejulian.name>

* add more verbose deprecation info

Signed-off-by: Joe Julian <me@joejulian.name>

* use new upstream deprecations

Signed-off-by: Joe Julian <me@joejulian.name>

* do not error for custom resources

Signed-off-by: Joe Julian <me@joejulian.name>

* Define deprecation version in lint rules by LDFLAG

Signed-off-by: Joe Julian <me@joejulian.name>

* make comment clearer

Signed-off-by: Joe Julian <me@joejulian.name>

* Extend the k8s version discovery and constants to chartutil

Signed-off-by: Joe Julian <me@joejulian.name>

* remove awk dependency

Signed-off-by: Joe Julian <me@joejulian.name>

* align k8s version constant names between capabilities.go and deprecations.go

Signed-off-by: Joe Julian <me@joejulian.name>

* show the error if the unexpected happens

Signed-off-by: Joe Julian <me@joejulian.name>

* bump k8sVersionMinor and golden chart templates for k8s 1.20

Signed-off-by: Joe Julian <me@joejulian.name>

* bump for tests to match 1.20.1

Signed-off-by: Joe Julian <me@joejulian.name>
2021-01-05 16:05:33 -07:00
rimas f30badd570 Fix test
Signed-off-by: rimas <rmocius@gmail.com>
2020-12-01 18:52:57 +02:00
rimas ce1a46899f Fixes #9083
Signed-off-by: rimas <rmocius@gmail.com>
2020-12-01 18:50:14 +02:00
Scaat Feng 9020c95fb1 [FIX]comment should start with whitespace
Signed-off-by: Scaat Feng <scaat.feng@gmail.com>
2020-11-26 14:11:27 +08:00
Nandor Kracser dfb5a5e8cc
lint: lint all documents in a multi-doc yaml file
Signed-off-by: Nandor Kracser <bonifaido@gmail.com>
2020-11-06 14:14:19 +01:00
Christophe VILA 8a4c0bc7b1 added test for https://github.com/helm/helm/pull/8913 related to https://github.com/helm/helm/issues/8621
Signed-off-by: Christophe VILA <christophe.vila@thalesgroup.com>
2020-10-27 23:06:01 +01:00
Christophe VILA f736af95eb do not check YAML if nothing was parsed
Signed-off-by: Christophe VILA <christophe.vila@thalesgroup.com>
2020-10-22 00:15:37 +02:00
Matt Butcher fe2d7f7792
this rewrites a whole bunch of old repo URLs to the new repo URL (#8902)
Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
2020-10-19 14:38:32 -06:00
Matt Butcher ed5fba5142
refactor the release name validation to be consistent across Helm
Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
2020-09-17 11:34:31 -06:00
Matt Butcher 04fb35814f
Fixed a variable name collision caused by two PR merges (#8681)
Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
2020-09-01 11:51:40 -06:00
Matt Butcher 70d03e5cef
Fix/8467 linter failing (#8496)
* add output to get debug info on linter failing

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>

* trap cases where the YAML indent is incorrect.

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
2020-09-01 10:45:59 -06:00
Matt Butcher 96d9ab9663
fix name length check on lint (#8543)
Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
2020-09-01 10:44:52 -06:00
Matt Farina 11f658e223
Fixing linting of templates on Windows
When the engine stored templates in the map the keys were generated
based on path and not filepath. filepath was being used in the linter
when retrieving content from the keys. On Windows the keys ended up
being different.

This change is to use path joins to create the lookup key. Since the
name path was used in the code it needed to be changed in order to
import the package.

Tests already exist and were failing on windows. This got in because
CI is not run on Windows.

Closes #6418

Signed-off-by: Matt Farina <matt@mattfarina.com>
2020-08-20 13:08:48 -04:00
Matt Butcher 2750e4d781
Lint dependencies (#7970)
* feat: add dependency tests

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>

* replaced on-disk fixtures with in-memory fixtures

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
2020-07-09 14:31:51 -06:00
Matthew Fisher d61aaf3fd7
Merge pull request #7235 from karuppiah7890/fix-lint
Show errors when linting for Chart.yaml version and appVersion fields of type non-string
2020-07-07 10:01:16 -07:00
Matthew Fisher e7ab975112
Merge pull request #8142 from technosophos/feat/1990-match-labels-lint
feat: Detect missing selector during lint
2020-07-07 08:48:24 -07:00
Karuppiah Natarajan 47c38ec23d
Show errors when linting for Chart.yaml version and appVersion fields of type non-string
Signed-off-by: Karuppiah Natarajan <karuppiah7890@gmail.com>
2020-05-25 13:24:15 +05:30