Skip to content

Commit c2e8926

Browse files
Add ignore-already-exists flag to skip chartmuseum 409 error
1 parent a0a1e31 commit c2e8926

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ Pushing mychart-0.3.2.tgz to chartmuseum...
6767
Done.
6868
```
6969

70+
If the `--force`/`-f` option is not set and the chart already exists you will get an error:
71+
```
72+
$ helm push mychart/ chartmuseum
73+
Pushing mychart-0.1.0.tgz to chartmuseum...
74+
Error: 409: mychart-0.1.0.tgz already exists
75+
```
76+
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.
77+
7078
### Pushing directly to URL
7179
If the second argument provided resembles a URL, you are not required to add the repo prior to push:
7280
```

cmd/helmpush/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type (
4040
authHeader string
4141
contextPath string
4242
forceUpload bool
43+
ignoreAlreadyExistsError bool
4344
useHTTP bool
4445
checkHelmVersion bool
4546
caFile string
@@ -121,6 +122,7 @@ func newPushCmd(args []string) *cobra.Command {
121122
f.StringVar(&p.keyring, "keyring", defaultKeyring(), "location of a public keyring")
122123
f.BoolVarP(&p.insecureSkipVerify, "insecure", "", false, "Connect to server with an insecure way by skipping certificate verification [$HELM_REPO_INSECURE]")
123124
f.BoolVarP(&p.forceUpload, "force", "f", false, "Force upload even if chart version exists")
125+
f.BoolVarP(&p.ignoreAlreadyExistsError, "ignore-already-exists", "", false, "Skip the already exisits error if chart version exists")
124126
f.BoolVarP(&p.dependencyUpdate, "dependency-update", "d", false, `update dependencies from "requirements.yaml" to dir "charts/" before packaging`)
125127
f.BoolVarP(&p.checkHelmVersion, "check-helm-version", "", false, `outputs either "2" or "3" indicating the current Helm major version`)
126128

@@ -328,7 +330,7 @@ func (p *pushCmd) push() error {
328330
return err
329331
}
330332

331-
return handlePushResponse(resp)
333+
return p.handlePushResponse(resp)
332334
}
333335

334336
func (p *pushCmd) download(fileURL string) error {
@@ -384,13 +386,18 @@ func (p *pushCmd) download(fileURL string) error {
384386
return handleDownloadResponse(resp)
385387
}
386388

387-
func handlePushResponse(resp *http.Response) error {
389+
func (p *pushCmd) handlePushResponse(resp *http.Response) error {
388390
if resp.StatusCode != 201 {
389391
b, err := ioutil.ReadAll(resp.Body)
390392
if err != nil {
391393
return err
392394
}
393-
return getChartmuseumError(b, resp.StatusCode)
395+
err = getChartmuseumError(b, resp.StatusCode)
396+
if p.ignoreAlreadyExistsError && resp.StatusCode == 409 {
397+
fmt.Printf("Got the following error: %s \nSkipping.\n", err)
398+
return nil
399+
}
400+
return err
394401
}
395402
fmt.Println("Done.")
396403
return nil

0 commit comments

Comments
 (0)