Skip to content

Commit

Permalink
Add ignore-already-exists flag to skip chartmuseum 409 error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevilain committed Dec 1, 2020
1 parent a0a1e31 commit c2e8926
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ Pushing mychart-0.3.2.tgz to chartmuseum...
Done.
```

If the `--force`/`-f` option is not set and the chart already exists you will get an error:
```
$ helm push mychart/ chartmuseum
Pushing mychart-0.1.0.tgz to chartmuseum...
Error: 409: mychart-0.1.0.tgz already exists
```
For some environnements, like in CI/CD pipelines, this error should not stop the whole pipeline and can be skipped using the `--ignore-already-exists` option.

### Pushing directly to URL
If the second argument provided resembles a URL, you are not required to add the repo prior to push:
```
Expand Down
13 changes: 10 additions & 3 deletions cmd/helmpush/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
authHeader string
contextPath string
forceUpload bool
ignoreAlreadyExistsError bool
useHTTP bool
checkHelmVersion bool
caFile string
Expand Down Expand Up @@ -121,6 +122,7 @@ func newPushCmd(args []string) *cobra.Command {
f.StringVar(&p.keyring, "keyring", defaultKeyring(), "location of a public keyring")
f.BoolVarP(&p.insecureSkipVerify, "insecure", "", false, "Connect to server with an insecure way by skipping certificate verification [$HELM_REPO_INSECURE]")
f.BoolVarP(&p.forceUpload, "force", "f", false, "Force upload even if chart version exists")
f.BoolVarP(&p.ignoreAlreadyExistsError, "ignore-already-exists", "", false, "Skip the already exisits error if chart version exists")
f.BoolVarP(&p.dependencyUpdate, "dependency-update", "d", false, `update dependencies from "requirements.yaml" to dir "charts/" before packaging`)
f.BoolVarP(&p.checkHelmVersion, "check-helm-version", "", false, `outputs either "2" or "3" indicating the current Helm major version`)

Expand Down Expand Up @@ -328,7 +330,7 @@ func (p *pushCmd) push() error {
return err
}

return handlePushResponse(resp)
return p.handlePushResponse(resp)
}

func (p *pushCmd) download(fileURL string) error {
Expand Down Expand Up @@ -384,13 +386,18 @@ func (p *pushCmd) download(fileURL string) error {
return handleDownloadResponse(resp)
}

func handlePushResponse(resp *http.Response) error {
func (p *pushCmd) handlePushResponse(resp *http.Response) error {
if resp.StatusCode != 201 {
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return getChartmuseumError(b, resp.StatusCode)
err = getChartmuseumError(b, resp.StatusCode)
if p.ignoreAlreadyExistsError && resp.StatusCode == 409 {
fmt.Printf("Got the following error: %s \nSkipping.\n", err)
return nil
}
return err
}
fmt.Println("Done.")
return nil
Expand Down

0 comments on commit c2e8926

Please sign in to comment.