@@ -73,6 +73,7 @@ type Reconciler struct {
73
73
skipDependentWatches bool
74
74
maxConcurrentReconciles int
75
75
reconcilePeriod time.Duration
76
+ maxHistory int
76
77
77
78
annotSetupOnce sync.Once
78
79
annotations map [string ]struct {}
@@ -280,6 +281,18 @@ func WithReconcilePeriod(rp time.Duration) Option {
280
281
}
281
282
}
282
283
284
+ // WithMaxReleaseHistory specifies the maximum size of the Helm release history maintained
285
+ // on upgrades/rollbacks. Zero (default) means unlimited.
286
+ func WithMaxReleaseHistory (maxHistory int ) Option {
287
+ return func (r * Reconciler ) error {
288
+ if maxHistory < 0 {
289
+ return errors .New ("maximum Helm release history size must not be negative" )
290
+ }
291
+ r .maxHistory = maxHistory
292
+ return nil
293
+ }
294
+ }
295
+
283
296
// WithInstallAnnotations is an Option that configures Install annotations
284
297
// to enable custom action.Install fields to be set based on the value of
285
298
// annotations found in the custom resource watched by this reconciler.
@@ -592,6 +605,12 @@ func (r *Reconciler) getReleaseState(client helmclient.ActionInterface, obj meta
592
605
}
593
606
594
607
var opts []helmclient.UpgradeOption
608
+ if r .maxHistory > 0 {
609
+ opts = append (opts , func (u * action.Upgrade ) error {
610
+ u .MaxHistory = r .maxHistory
611
+ return nil
612
+ })
613
+ }
595
614
for name , annot := range r .upgradeAnnotations {
596
615
if v , ok := obj .GetAnnotations ()[name ]; ok {
597
616
opts = append (opts , annot .UpgradeOption (v ))
@@ -636,6 +655,12 @@ func (r *Reconciler) doInstall(actionClient helmclient.ActionInterface, u *updat
636
655
637
656
func (r * Reconciler ) doUpgrade (actionClient helmclient.ActionInterface , u * updater.Updater , obj * unstructured.Unstructured , vals map [string ]interface {}, log logr.Logger ) (* release.Release , error ) {
638
657
var opts []helmclient.UpgradeOption
658
+ if r .maxHistory > 0 {
659
+ opts = append (opts , func (u * action.Upgrade ) error {
660
+ u .MaxHistory = r .maxHistory
661
+ return nil
662
+ })
663
+ }
639
664
for name , annot := range r .upgradeAnnotations {
640
665
if v , ok := obj .GetAnnotations ()[name ]; ok {
641
666
opts = append (opts , annot .UpgradeOption (v ))
0 commit comments