@@ -437,6 +437,20 @@ type Remediation interface {
437437 RetriesExhausted (hr * HelmRelease ) bool
438438}
439439
440+ // Strategy defines a consistent interface for InstallStrategy and
441+ // UpgradeStrategy.
442+ // +kubebuilder:object:generate=false
443+ type Strategy interface {
444+ GetRetry () Retry
445+ }
446+
447+ // Retry defines a consistent interface for retry strategies from
448+ // InstallStrategy and UpgradeStrategy.
449+ // +kubebuilder:object:generate=false
450+ type Retry interface {
451+ GetRetryInterval () time.Duration
452+ }
453+
440454// Install holds the configuration for Helm install actions performed for this
441455// HelmRelease.
442456type Install struct {
@@ -448,6 +462,11 @@ type Install struct {
448462 // +optional
449463 Timeout * metav1.Duration `json:"timeout,omitempty"`
450464
465+ // Strategy defines the install strategy to use for this HelmRelease.
466+ // Defaults to 'RemediateOnFailure'.
467+ // +optional
468+ Strategy * InstallStrategy `json:"strategy,omitempty"`
469+
451470 // Remediation holds the remediation configuration for when the Helm install
452471 // action for the HelmRelease fails. The default is to not perform any action.
453472 // +optional
@@ -541,6 +560,41 @@ func (in Install) GetRemediation() Remediation {
541560 return * in .Remediation
542561}
543562
563+ // GetRetry returns the configured retry strategy for the Helm install
564+ // action.
565+ func (in Install ) GetRetry () Retry {
566+ if in .Strategy == nil || in .Strategy .Name != string (ActionStrategyRetryOnFailure ) {
567+ return nil
568+ }
569+ return in .Strategy
570+ }
571+
572+ // InstallStrategy holds the configuration for Helm install strategy.
573+ // +kubebuilder:validation:XValidation:rule="!has(self.retryInterval) || self.name != 'RemediateOnFailure'", message=".retryInterval cannot be set when .name is 'RemediateOnFailure'"
574+ type InstallStrategy struct {
575+ // Name of the install strategy.
576+ // +kubebuilder:validation:Enum=RemediateOnFailure;RetryOnFailure
577+ // +required
578+ Name string `json:"name"`
579+
580+ // RetryInterval is the interval at which to retry a failed install.
581+ // Can be used only when Name is set to RetryOnFailure.
582+ // Defaults to '5m'.
583+ // +kubebuilder:validation:Type=string
584+ // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
585+ // +optional
586+ RetryInterval * metav1.Duration `json:"retryInterval,omitempty"`
587+ }
588+
589+ // GetRetryInterval returns the configured retry interval for the Helm install
590+ // action, or the default.
591+ func (in InstallStrategy ) GetRetryInterval () time.Duration {
592+ if in .RetryInterval == nil {
593+ return 5 * time .Minute
594+ }
595+ return in .RetryInterval .Duration
596+ }
597+
544598// InstallRemediation holds the configuration for Helm install remediation.
545599type InstallRemediation struct {
546600 // Retries is the number of retries that should be attempted on failures before
@@ -631,6 +685,11 @@ type Upgrade struct {
631685 // +optional
632686 Timeout * metav1.Duration `json:"timeout,omitempty"`
633687
688+ // Strategy defines the upgrade strategy to use for this HelmRelease.
689+ // Defaults to 'RemediateOnFailure'.
690+ // +optional
691+ Strategy * UpgradeStrategy `json:"strategy,omitempty"`
692+
634693 // Remediation holds the remediation configuration for when the Helm upgrade
635694 // action for the HelmRelease fails. The default is to not perform any action.
636695 // +optional
@@ -719,6 +778,41 @@ func (in Upgrade) GetRemediation() Remediation {
719778 return * in .Remediation
720779}
721780
781+ // GetRetry returns the configured retry strategy for the Helm upgrade
782+ // action.
783+ func (in Upgrade ) GetRetry () Retry {
784+ if in .Strategy == nil || in .Strategy .Name != string (ActionStrategyRetryOnFailure ) {
785+ return nil
786+ }
787+ return in .Strategy
788+ }
789+
790+ // UpgradeStrategy holds the configuration for Helm upgrade strategy.
791+ // +kubebuilder:validation:XValidation:rule="!has(self.retryInterval) || self.name == 'RetryOnFailure'", message=".retryInterval can only be set when .name is 'RetryOnFailure'"
792+ type UpgradeStrategy struct {
793+ // Name of the upgrade strategy.
794+ // +kubebuilder:validation:Enum=RemediateOnFailure;RetryOnFailure
795+ // +required
796+ Name string `json:"name"`
797+
798+ // RetryInterval is the interval at which to retry a failed upgrade.
799+ // Can be used only when Name is set to RetryOnFailure.
800+ // Defaults to '5m'.
801+ // +kubebuilder:validation:Type=string
802+ // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
803+ // +optional
804+ RetryInterval * metav1.Duration `json:"retryInterval,omitempty"`
805+ }
806+
807+ // GetRetryInterval returns the configured retry interval for the Helm upgrade
808+ // action, or the default.
809+ func (in UpgradeStrategy ) GetRetryInterval () time.Duration {
810+ if in .RetryInterval == nil {
811+ return 5 * time .Minute
812+ }
813+ return in .RetryInterval .Duration
814+ }
815+
722816// UpgradeRemediation holds the configuration for Helm upgrade remediation.
723817type UpgradeRemediation struct {
724818 // Retries is the number of retries that should be attempted on failures before
@@ -791,6 +885,19 @@ func (in UpgradeRemediation) RetriesExhausted(hr *HelmRelease) bool {
791885 return in .Retries >= 0 && in .GetFailureCount (hr ) > int64 (in .Retries )
792886}
793887
888+ // ActionStrategyName is a valid name for an action strategy.
889+ type ActionStrategyName string
890+
891+ const (
892+ // ActionStrategyRemediateOnFailure is the action strategy name for
893+ // remediate on failure.
894+ ActionStrategyRemediateOnFailure ActionStrategyName = "RemediateOnFailure"
895+
896+ // ActionStrategyRetryOnFailure is the action strategy name for retry on
897+ // failure.
898+ ActionStrategyRetryOnFailure ActionStrategyName = "RetryOnFailure"
899+ )
900+
794901// RemediationStrategy returns the strategy to use to remediate a failed install
795902// or upgrade.
796903type RemediationStrategy string
@@ -1012,7 +1119,8 @@ type HelmReleaseStatus struct {
10121119 History Snapshots `json:"history,omitempty"`
10131120
10141121 // LastAttemptedReleaseAction is the last release action performed for this
1015- // HelmRelease. It is used to determine the active remediation strategy.
1122+ // HelmRelease. It is used to determine the active retry or remediation
1123+ // strategy.
10161124 // +kubebuilder:validation:Enum=install;upgrade
10171125 // +optional
10181126 LastAttemptedReleaseAction ReleaseAction `json:"lastAttemptedReleaseAction,omitempty"`
@@ -1195,6 +1303,19 @@ func (in HelmRelease) GetActiveRemediation() Remediation {
11951303 }
11961304}
11971305
1306+ // GetActiveRetry returns the active retry configuration for the
1307+ // HelmRelease.
1308+ func (in HelmRelease ) GetActiveRetry () Retry {
1309+ switch in .Status .LastAttemptedReleaseAction {
1310+ case ReleaseActionInstall :
1311+ return in .GetInstall ().GetRetry ()
1312+ case ReleaseActionUpgrade :
1313+ return in .GetUpgrade ().GetRetry ()
1314+ default :
1315+ return nil
1316+ }
1317+ }
1318+
11981319// GetRequeueAfter returns the duration after which the HelmRelease
11991320// must be reconciled again.
12001321func (in HelmRelease ) GetRequeueAfter () time.Duration {
0 commit comments