Merge pull request #8754 from technosophos/fix/repo-add-force-update

replace --no-update with --force-update and invert default. BREAKING.
pull/8759/head
Matthew Fisher 4 years ago committed by GitHub
commit 71ee2c23c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,7 +42,7 @@ type repoAddOptions struct {
url string url string
username string username string
password string password string
noUpdate bool forceUpdate bool
certFile string certFile string
keyFile string keyFile string
@ -51,6 +51,9 @@ type repoAddOptions struct {
repoFile string repoFile string
repoCache string repoCache string
// Deprecated, but cannot be removed until Helm 4
deprecatedNoUpdate bool
} }
func newRepoAddCmd(out io.Writer) *cobra.Command { func newRepoAddCmd(out io.Writer) *cobra.Command {
@ -74,7 +77,8 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.StringVar(&o.username, "username", "", "chart repository username") f.StringVar(&o.username, "username", "", "chart repository username")
f.StringVar(&o.password, "password", "", "chart repository password") f.StringVar(&o.password, "password", "", "chart repository password")
f.BoolVar(&o.noUpdate, "no-update", false, "raise error if repo is already registered") f.BoolVar(&o.forceUpdate, "force-update", false, "replace (overwrite) the repo if it already exists")
f.BoolVar(&o.deprecatedNoUpdate, "no-update", false, "Ignored. Formerly, it would disabled forced updates. It is deprecated by force-update.")
f.StringVar(&o.certFile, "cert-file", "", "identify HTTPS client using this SSL certificate file") f.StringVar(&o.certFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&o.keyFile, "key-file", "", "identify HTTPS client using this SSL key file") f.StringVar(&o.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle") f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
@ -112,7 +116,8 @@ func (o *repoAddOptions) run(out io.Writer) error {
return err return err
} }
if o.noUpdate && f.Has(o.name) { // If the repo exists and --force-update was not specified, error out.
if !o.forceUpdate && f.Has(o.name) {
return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name)
} }

@ -67,7 +67,8 @@ func TestRepoAdd(t *testing.T) {
o := &repoAddOptions{ o := &repoAddOptions{
name: testRepoName, name: testRepoName,
url: ts.URL(), url: ts.URL(),
noUpdate: true, forceUpdate: false,
deprecatedNoUpdate: true,
repoFile: repoFile, repoFile: repoFile,
} }
os.Setenv(xdg.CacheHomeEnvVar, rootDir) os.Setenv(xdg.CacheHomeEnvVar, rootDir)
@ -94,7 +95,7 @@ func TestRepoAdd(t *testing.T) {
t.Errorf("Error cache charts file was not created for repository %s", testRepoName) t.Errorf("Error cache charts file was not created for repository %s", testRepoName)
} }
o.noUpdate = false o.forceUpdate = true
if err := o.run(ioutil.Discard); err != nil { if err := o.run(ioutil.Discard); err != nil {
t.Errorf("Repository was not updated: %s", err) t.Errorf("Repository was not updated: %s", err)
@ -132,7 +133,8 @@ func repoAddConcurrent(t *testing.T, testName, repoFile string) {
o := &repoAddOptions{ o := &repoAddOptions{
name: name, name: name,
url: ts.URL(), url: ts.URL(),
noUpdate: true, deprecatedNoUpdate: true,
forceUpdate: false,
repoFile: repoFile, repoFile: repoFile,
} }
if err := o.run(ioutil.Discard); err != nil { if err := o.run(ioutil.Discard); err != nil {

Loading…
Cancel
Save