From 6e1b45888abdde0f57a450fd62295d177af00822 Mon Sep 17 00:00:00 2001 From: derkoe Date: Wed, 28 Nov 2018 21:43:38 +0100 Subject: [PATCH] feat(cmd/helm): re-add --history-max option to v3 Since there is no tiller anymore this option make most sense with the 'helm upgrade' commando. Origininally this was added in PR #2636 implementing the feature #2081. Signed-off-by: Christian Koeberl --- cmd/helm/upgrade.go | 5 ++++- pkg/hapi/tiller.go | 2 ++ pkg/helm/option.go | 7 +++++++ pkg/tiller/release_update.go | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 73082dc1d..144c536db 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -65,6 +65,7 @@ type upgradeOptions struct { reuseValues bool // --reuse-values timeout int64 // --timeout wait bool // --wait + maxHistory int // --max-history valuesOptions chartPathOptions @@ -109,6 +110,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { f.BoolVar(&o.reuseValues, "reuse-values", false, "when upgrading, reuse the last release's values and merge in any overrides from the command line via --set and -f. If '--reset-values' is specified, this is ignored.") f.BoolVar(&o.wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout") f.BoolVar(&o.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.") + f.IntVar(&o.maxHistory, "history-max", 0, "limit the maximum number of revisions saved per release. Use 0 for no limit.") o.valuesOptions.addFlags(f) o.chartPathOptions.addFlags(f) @@ -168,7 +170,8 @@ func (o *upgradeOptions) run(out io.Writer) error { helm.UpgradeTimeout(o.timeout), helm.ResetValues(o.resetValues), helm.ReuseValues(o.reuseValues), - helm.UpgradeWait(o.wait)) + helm.UpgradeWait(o.wait), + helm.MaxHistory(o.maxHistory)) if err != nil { return errors.Wrap(err, "UPGRADE FAILED") } diff --git a/pkg/hapi/tiller.go b/pkg/hapi/tiller.go index 85ea3e64e..964e16a04 100644 --- a/pkg/hapi/tiller.go +++ b/pkg/hapi/tiller.go @@ -117,6 +117,8 @@ type UpdateReleaseRequest struct { ReuseValues bool `json:"reuse_values,omitempty"` // Force resource update through delete/recreate if needed. Force bool `json:"force,omitempty"` + // Limit the maximum number of revisions saved per release. + MaxHistory int `json:"max_history,omitempty"` } // RollbackReleaseRequest is the request for a release to be rolledback to a diff --git a/pkg/helm/option.go b/pkg/helm/option.go index ecc164031..83eaba92f 100644 --- a/pkg/helm/option.go +++ b/pkg/helm/option.go @@ -346,6 +346,13 @@ func UpgradeForce(force bool) UpdateOption { } } +// Limit the maximum number of revisions saved per release +func MaxHistory(maxHistory int) UpdateOption { + return func(opts *options) { + opts.updateReq.MaxHistory = maxHistory + } +} + // UninstallOption allows setting optional attributes when // performing a UninstallRelease tiller rpc. type UninstallOption func(*options) diff --git a/pkg/tiller/release_update.go b/pkg/tiller/release_update.go index 916ac64e7..622de5da0 100644 --- a/pkg/tiller/release_update.go +++ b/pkg/tiller/release_update.go @@ -45,6 +45,8 @@ func (s *ReleaseServer) UpdateRelease(req *hapi.UpdateReleaseRequest) (*release. return nil, err } + s.Releases.MaxHistory = req.MaxHistory + if !req.DryRun { s.Log("creating updated release for %s", req.Name) if err := s.Releases.Create(updatedRelease); err != nil {