Skip to content

Commit f1e5d1d

Browse files
committed
Allow setting a custom wait.Backoff config for renewal
Signed-off-by: James Munnelly <[email protected]>
1 parent fcf8439 commit f1e5d1d

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

manager/manager.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ type Options struct {
8282
SignRequest SignRequestFunc
8383
WriteKeypair WriteKeypairFunc
8484
ReadyToRequest ReadyToRequestFunc
85+
86+
// BackoffConfig configures the exponential backoff applied to certificate renewal failures.
87+
BackoffConfig *wait.Backoff
8588
}
8689

8790
// NewManager constructs a new manager used to manage volumes containing
@@ -100,6 +103,22 @@ func NewManager(opts Options) (*Manager, error) {
100103
if opts.Clock == nil {
101104
opts.Clock = clock.RealClock{}
102105
}
106+
if opts.BackoffConfig == nil {
107+
opts.BackoffConfig = &wait.Backoff{
108+
// the 'base' amount of time for the backoff
109+
Duration: time.Second * 30,
110+
// We multiply the 'duration' by 2.0 if the attempt fails/errors
111+
Factor: 2.0,
112+
// Add a jitter of +/- 0.5 of the 'duration'
113+
Jitter: 0.5,
114+
// 'Steps' controls what the maximum number of backoff attempts is before we
115+
// reset back to the 'base duration'. Set this to the MaxInt32, as we never want to
116+
// reset this unless we get a successful attempt.
117+
Steps: math.MaxInt32,
118+
// The maximum time between calls will be 5 minutes
119+
Cap: time.Minute * 5,
120+
}
121+
}
103122
if opts.Log == nil {
104123
return nil, errors.New("Log must be set")
105124
}
@@ -167,6 +186,7 @@ func NewManager(opts Options) (*Manager, error) {
167186

168187
maxRequestsPerVolume: opts.MaxRequestsPerVolume,
169188
nodeNameHash: nodeNameHash,
189+
backoffConfig: *opts.BackoffConfig,
170190
}
171191

172192
vols, err := opts.MetadataReader.ListVolumes()
@@ -263,6 +283,9 @@ type Manager struct {
263283

264284
// maximum number of CertificateRequests that should exist at any time for each volume
265285
maxRequestsPerVolume int
286+
287+
// backoffConfig configures the exponential backoff applied to certificate renewal failures.
288+
backoffConfig wait.Backoff
266289
}
267290

268291
// issue will step through the entire issuance flow for a volume.
@@ -589,20 +612,7 @@ func (m *Manager) startRenewalRoutine(volumeID string) (started bool) {
589612
// Instead, retry within the same iteration of the for loop and apply an exponential backoff.
590613
// Because we pass ctx through to the 'wait' package, if the stopCh is closed/context is cancelled,
591614
// we'll immediately stop waiting and 'continue' which will then hit the `case <-stopCh` case in the `select`.
592-
if err := wait.ExponentialBackoffWithContext(ctx, wait.Backoff{
593-
// 8s is the 'base' amount of time for the backoff
594-
Duration: time.Second * 8,
595-
// We multiple the 'duration' by 2.0 if the attempt fails/errors
596-
Factor: 2.0,
597-
// Add a jitter of +/- 1s (0.5 of the 'duration')
598-
Jitter: 0.5,
599-
// 'Steps' controls what the maximum number of backoff attempts is before we
600-
// reset back to the 'base duration'. Set this to the MaxInt32, as we never want to
601-
// reset this unless we get a successful attempt.
602-
Steps: math.MaxInt32,
603-
// The maximum time between calls will be 5 minutes
604-
Cap: time.Minute * 5,
605-
}, func() (bool, error) {
615+
if err := wait.ExponentialBackoffWithContext(ctx, m.backoffConfig, func() (bool, error) {
606616
log.Info("Triggering new issuance")
607617
if err := m.issue(ctx, volumeID); err != nil {
608618
log.Error(err, "Failed to issue certificate, retrying after applying exponential backoff")

test/util/testutil.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto"
2222
"crypto/x509"
2323
"fmt"
24+
"math"
2425
"net"
2526
"testing"
2627
"time"
@@ -120,6 +121,7 @@ func RunTestDriver(t *testing.T, opts DriverOptions) (DriverOptions, csi.NodeCli
120121
SignRequest: opts.SignRequest,
121122
WriteKeypair: opts.WriteKeypair,
122123
ReadyToRequest: opts.ReadyToRequest,
124+
BackoffConfig: &wait.Backoff{Steps: math.MaxInt32}, // don't actually wait (i.e. set all backoff times to 0)
123125
})
124126

125127
d := driver.NewWithListener(lis, *opts.Log, driver.Options{

0 commit comments

Comments
 (0)