Add repo update strict flag

pull/4348/head
l.aminov 7 years ago
parent fe9064c8f7
commit fd808dbef3

@ -40,9 +40,10 @@ future releases.
var errNoRepositories = errors.New("no repositories found. You must add one before updating")
type repoUpdateCmd struct {
update func([]*repo.ChartRepository, io.Writer, helmpath.Home) error
update func([]*repo.ChartRepository, io.Writer, helmpath.Home, bool) error
home helmpath.Home
out io.Writer
strict bool
}
func newRepoUpdateCmd(out io.Writer) *cobra.Command {
@ -60,6 +61,10 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
return u.run()
},
}
f := cmd.Flags()
f.BoolVar(&u.strict, "strict", false, "fail on update warnings")
return cmd
}
@ -80,10 +85,10 @@ func (u *repoUpdateCmd) run() error {
}
repos = append(repos, r)
}
return u.update(repos, u.out, u.home)
return u.update(repos, u.out, u.home, u.strict)
}
func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Home) error {
func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Home, strict bool) error {
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var (
errorCounter int
@ -107,9 +112,11 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Ho
}(re)
}
wg.Wait()
if errorCounter != 0 {
if errorCounter != 0 && strict {
return errors.New("Update Failed. Check log for details")
}
fmt.Fprintln(out, "Update Complete. ⎈ Happy Helming!⎈ ")
return nil
}

@ -46,7 +46,7 @@ func TestUpdateCmd(t *testing.T) {
out := bytes.NewBuffer(nil)
// Instead of using the HTTP updater, we provide our own for this test.
// The TestUpdateCharts test verifies the HTTP behavior independently.
updater := func(repos []*repo.ChartRepository, out io.Writer, hh helmpath.Home) error {
updater := func(repos []*repo.ChartRepository, out io.Writer, hh helmpath.Home, strict bool) error {
for _, re := range repos {
fmt.Fprintln(out, re.Config.Name)
}
@ -95,7 +95,7 @@ func TestUpdateCharts(t *testing.T) {
}
b := bytes.NewBuffer(nil)
updateCharts([]*repo.ChartRepository{r}, b, hh)
updateCharts([]*repo.ChartRepository{r}, b, hh, false)
got := b.String()
if strings.Contains(got, "Unable to get an update") {

@ -445,10 +445,7 @@ func (m *Manager) UpdateRepositories() error {
func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
out := m.Out
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var (
errorCounter int
wg sync.WaitGroup
)
var wg sync.WaitGroup
for _, c := range repos {
r, err := repo.NewChartRepository(c, m.Getters)
if err != nil {
@ -457,7 +454,6 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
wg.Add(1)
go func(r *repo.ChartRepository) {
if err := r.DownloadIndexFile(m.HelmHome.Cache()); err != nil {
errorCounter++
fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", r.Config.Name, r.Config.URL, err)
} else {
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", r.Config.Name)
@ -466,9 +462,6 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
}(r)
}
wg.Wait()
if errorCounter != 0 {
return errors.New("Update Failed. Check log for details")
}
fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈")
return nil
}

Loading…
Cancel
Save