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

Add ignore-already-exists flag to ignore chartmuseum's "already exists" error #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
49 changes: 28 additions & 21 deletions cmd/helmpush/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@ import (

type (
pushCmd struct {
chartName string
chartVersion string
repoName string
username string
password string
accessToken string
authHeader string
contextPath string
forceUpload bool
useHTTP bool
checkHelmVersion bool
caFile string
certFile string
keyFile string
insecureSkipVerify bool
keyring string
dependencyUpdate bool
out io.Writer
chartName string
chartVersion string
repoName string
username string
password string
accessToken string
authHeader string
contextPath string
forceUpload bool
ignoreAlreadyExistsError bool
useHTTP bool
checkHelmVersion bool
caFile string
certFile string
keyFile string
insecureSkipVerify bool
keyring string
dependencyUpdate bool
out io.Writer
}

config struct {
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