@@ -437,6 +437,20 @@ type Remediation interface {
437
437
RetriesExhausted (hr * HelmRelease ) bool
438
438
}
439
439
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
+
440
454
// Install holds the configuration for Helm install actions performed for this
441
455
// HelmRelease.
442
456
type Install struct {
@@ -448,6 +462,11 @@ type Install struct {
448
462
// +optional
449
463
Timeout * metav1.Duration `json:"timeout,omitempty"`
450
464
465
+ // Strategy defines the install strategy to use for this HelmRelease.
466
+ // Defaults to 'RemediateOnFailure'.
467
+ // +optional
468
+ Strategy * InstallStrategy `json:"strategy,omitempty"`
469
+
451
470
// Remediation holds the remediation configuration for when the Helm install
452
471
// action for the HelmRelease fails. The default is to not perform any action.
453
472
// +optional
@@ -541,6 +560,41 @@ func (in Install) GetRemediation() Remediation {
541
560
return * in .Remediation
542
561
}
543
562
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
+
544
598
// InstallRemediation holds the configuration for Helm install remediation.
545
599
type InstallRemediation struct {
546
600
// Retries is the number of retries that should be attempted on failures before
@@ -631,6 +685,11 @@ type Upgrade struct {
631
685
// +optional
632
686
Timeout * metav1.Duration `json:"timeout,omitempty"`
633
687
688
+ // Strategy defines the upgrade strategy to use for this HelmRelease.
689
+ // Defaults to 'RemediateOnFailure'.
690
+ // +optional
691
+ Strategy * UpgradeStrategy `json:"strategy,omitempty"`
692
+
634
693
// Remediation holds the remediation configuration for when the Helm upgrade
635
694
// action for the HelmRelease fails. The default is to not perform any action.
636
695
// +optional
@@ -719,6 +778,41 @@ func (in Upgrade) GetRemediation() Remediation {
719
778
return * in .Remediation
720
779
}
721
780
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
+
722
816
// UpgradeRemediation holds the configuration for Helm upgrade remediation.
723
817
type UpgradeRemediation struct {
724
818
// Retries is the number of retries that should be attempted on failures before
@@ -791,6 +885,19 @@ func (in UpgradeRemediation) RetriesExhausted(hr *HelmRelease) bool {
791
885
return in .Retries >= 0 && in .GetFailureCount (hr ) > int64 (in .Retries )
792
886
}
793
887
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
+
794
901
// RemediationStrategy returns the strategy to use to remediate a failed install
795
902
// or upgrade.
796
903
type RemediationStrategy string
@@ -1012,7 +1119,8 @@ type HelmReleaseStatus struct {
1012
1119
History Snapshots `json:"history,omitempty"`
1013
1120
1014
1121
// 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.
1016
1124
// +kubebuilder:validation:Enum=install;upgrade
1017
1125
// +optional
1018
1126
LastAttemptedReleaseAction ReleaseAction `json:"lastAttemptedReleaseAction,omitempty"`
@@ -1195,6 +1303,19 @@ func (in HelmRelease) GetActiveRemediation() Remediation {
1195
1303
}
1196
1304
}
1197
1305
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
+
1198
1319
// GetRequeueAfter returns the duration after which the HelmRelease
1199
1320
// must be reconciled again.
1200
1321
func (in HelmRelease ) GetRequeueAfter () time.Duration {
0 commit comments