This refactor cleans up downloadAll's validation, download, and save
logic:
1. A temporary directory is created, and removed after all references to
the struct have been dropped via `defer`
2. Any local dependencies in the `charts` directory are kept intact and validated
3. Charts that have been updated are moved to the `charts` directory
This refactor has a number of improvements, including:
- tmpCharts is removed after execution
- no remote charts are downloaded to destPath: they are all pulled into
tmpPath, validated, then moved to destPath
- lots of code cleanup/improvements, like the `if` block checking
whether the `charts` directory was actually not a directory. In some
cases it could be checking a `nil` object, causing a runtime panic.
- the cyclomatic complexity of the code was simplified
- extra (and in some cases, dangerous) calls to `os.RemoveAll` have been
refactored, cleaning the code and preventing certain failure cases.
A test has been provided to demonstrate the tmpCharts removal issue has
been fixed.
Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
Cobra's bash completion V2 has the following benefits:
- aligned with the completion logic for the other shells
- provides completion descriptions as for the other shells
- uses a 300-line shell script (versus 4K lines for V1)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Cobra provides powershell auto-completion out of the box. This commit
teaches helm how to use it.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
**What*
Without this commit, you can't pipe the password into `helm repo add`:
```
$ echo password | helm repo add repo-name https://repo-url --username username
Password:
Error: inappropriate ioctl for device
```
This commit introduces `--password-stdin`:
```
$ echo password | helm repo add repo-name https://repo-url --username username --password-stdin
"repo-name" has been added to your repositories
```
**Why**
There are two reasons I see for adding this:
* I personally would expect that it's possible to pipe the password into
`helm repo add` but that's currently not the case. If I understand it
correctly, you currently either need to pass the password via a cli
parameter (`--password`) or use a expect/send mechanism.
* Subcommands like `helm registry login` already support
`--password-stdin`. The cli interfaces should be consistent regarding
which options they support.
**Notes**
I basically just copy-pasted code from `cmd/helm/registry_login.go`.
Signed-off-by: André Schröder <andre.schroedr@gmail.com>
Testing that a bad completion directive was being replaced by the
default one was actually testing Cobra's behaviour. This is unnecessary
especially since that behaviour changed in the 1.2.0 release. Helm
tests should focus on testing Helm's behaviour.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This is a port to helm v3 of #5182.
A little more flexible than the v2 version, it allows to specify a list
of repositories that should be updated.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
The URL passed to the getter for WithURL needs to be a full URL
rather than a chart reference used at the CLI. For example,
bitnami/wordpress can point to the wordpress chart in the bitnami
repo where the bitnami repo is at https://charts.bitnami.com.
WithURL needs the full URL to the repo and not bitnami/wordpress.
This is important because getters use the full URL information.
In this case the http getter uses the host name for SNI handling.
Before this change WithURL was being set to the chart reference
instead of the URL. This was a silent bug.
This change sets WithURL using a URL after for the repo is
available when a reference is used instead of a full url.
Signed-off-by: Matt Farina <matt.farina@suse.com>
managedFields were a changed that landed in 1.18. This is an array
under metadata with managedFields. The kubernetes client pkgs that
Helm uses automatically add them.
This change added a manager for the managedFields. The flow for
deciding on the name to use is:
1. An explicit name if one is chosen
2. The base name of the first os.Arg (the binary name) if no name
explicitly set.
3. unknown if no name set and name cannot be detected
The name is at the package level as there is no other place to easily
set it for Helm v3. Since the name is for the binary or app it should
be ok to set app wide.
Signed-off-by: Matt Farina <matt.farina@suse.com>
It just makes the code better, I suppose the following is rational:
- use standard libaray common constants instead of hardcode though it's
really common
- close the response body even if the http status code is not 200 OK.
The doc says *It is the caller's responsibility to close Body*.
- move the `bytes.Buffer` return value declaration where it gets used.
Signed-off-by: longkai <im.longkai@gmail.com>