added a skip-empty flag to upgrade command

Signed-off-by: igorushi <igor.altman@gmail.com>
pull/11945/head
igorushi 3 years ago
parent 8a9c702b4c
commit 0ecfd56fe2

@ -123,7 +123,7 @@ func (s statusPrinter) WriteYAML(out io.Writer) error {
}
func (s statusPrinter) WriteTable(out io.Writer) error {
if s.release == nil {
if s.release == nil || s.release.Skipped {
return nil
}
fmt.Fprintf(out, "NAME: %s\n", s.release.Name)

@ -0,0 +1 @@
Release "funny-bunny" has been skipped. Happy Helming!

@ -210,7 +210,11 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
}
if outfmt == output.Table {
fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0])
if rel.Skipped {
fmt.Fprintf(out, "Release %q has been skipped. Happy Helming!\n", args[0])
} else {
fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0])
}
}
return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false, false})
@ -240,6 +244,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f.StringVar(&client.Description, "description", "", "add a custom description")
f.BoolVar(&client.DependencyUpdate, "dependency-update", false, "update dependencies if they are missing before installing the chart")
f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates")
f.BoolVar(&client.SkipEmptyUpgrade, "skip-empty", false, "skip upgrade if there are no changes")
addChartPathOptionsFlags(f, &client.ChartPathOptions)
addValueOptionsFlags(f, valueOpts)
bindOutputFlag(cmd, &outfmt)

@ -168,6 +168,12 @@ func TestUpgradeCmd(t *testing.T) {
golden: "output/upgrade.txt",
rels: []*release.Release{relWithStatusMock("funny-bunny", 2, ch, release.StatusFailed)},
},
{
name: "upgrade skip empty release",
cmd: fmt.Sprintf("upgrade --skip-empty funny-bunny '%s' ", chartPath),
golden: "output/upgrade-with-skip.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "funny-bunny", Version: 2, Chart: ch, Status: release.StatusDeployed})},
},
{
name: "upgrade a pending install release",
cmd: fmt.Sprintf("upgrade funny-bunny '%s'", chartPath),

@ -106,6 +106,8 @@ type Upgrade struct {
Lock sync.Mutex
// Enable DNS lookups when rendering templates
EnableDNS bool
// Skip upgrade if there are no changes
SkipEmptyUpgrade bool
}
type resultMessage struct {
@ -161,7 +163,9 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, chart *chart.
return res, err
}
if !u.DryRun {
if upgradedRelease.Skipped {
u.cfg.Log("upgrade release for %s was skipped", name)
} else if !u.DryRun {
u.cfg.Log("updating status for upgraded release for %s", name)
if err := u.cfg.Releases.Update(upgradedRelease); err != nil {
return res, err
@ -317,6 +321,13 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
return nil
})
if u.SkipEmptyUpgrade {
if len(toBeCreated) == 0 && len(toBeUpdated) == 0 {
upgradedRelease.Skipped = true
return upgradedRelease, nil
}
}
if u.DryRun {
u.cfg.Log("dry run for %s", upgradedRelease.Name)
if len(u.Description) > 0 {

@ -40,6 +40,8 @@ type Release struct {
// Labels of the release.
// Disabled encoding into Json cause labels are stored in storage driver metadata field.
Labels map[string]string `json:"-"`
// Skipped indicates if release was skipped.
Skipped bool
}
// SetStatus is a helper for setting the status on a release.

Loading…
Cancel
Save