Skip to content

Commit

Permalink
Parameterize startup CRD wait retries
Browse files Browse the repository at this point in the history
Change-Id: I870a3d294b4d30abea3f6ecad951d68cfd5c9ceb
  • Loading branch information
mattcary authored and jsafrane committed Nov 14, 2022
1 parent 1651e0f commit 85739af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ Other than this, the NODE_NAME environment variable must be set where the CSI sn

* `--retry-interval-max`: Maximum retry interval of failed volume snapshot creation or deletion. Default value is 5 minutes.

* `--retry-crd-interval-max`: Maximum retry interval for detecting the snapshot CRDs on controller startup. Default is 5 seconds.

* `--enable-distributed-snapshotting` : Enables each node to handle snapshots for the volumes local to that node. Off by default. It should be set to true only if `--node-deployment` parameter for the csi external snapshotter sidecar is set to true. See https://github.com/kubernetes-csi/external-snapshotter/blob/master/README.md#distributed-snapshotting for details.

* `--prevent-volume-mode-conversion`: Boolean that prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot. Only present as an alpha feature in `v6.0.0` and above.
Expand Down
22 changes: 18 additions & 4 deletions cmd/snapshot-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"flag"
"fmt"
"math"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -71,6 +72,8 @@ var (
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
enableDistributedSnapshotting = flag.Bool("enable-distributed-snapshotting", false, "Enables each node to handle snapshotting for the local volumes created on that node")
preventVolumeModeConversion = flag.Bool("prevent-volume-mode-conversion", false, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")

retryCRDIntervalMax = flag.Duration("retry-crd-interval-max", 5*time.Second, "Maximum retry interval to wait for CRDs to appear. The default is 5 seconds.")
)

var version = "unknown"
Expand Down Expand Up @@ -100,11 +103,22 @@ func ensureCustomResourceDefinitionsExist(client *clientset.Clientset) error {
return true, nil
}

// with a Factor of 1.5 we wait up to 7.5 seconds (the 10th attempt)
// The maximum retry duration = initial duration * retry factor ^ # steps. Rearranging, this gives
// # steps = log(maximum retry / initial duration) / log(retry factor).
const retryFactor = 1.5
const initialDurationMs = 100
maxMs := retryCRDIntervalMax.Milliseconds()
if maxMs < initialDurationMs {
maxMs = initialDurationMs
}
steps := int(math.Ceil(math.Log(float64(maxMs)/initialDurationMs) / math.Log(retryFactor)))
if steps < 1 {
steps = 1
}
backoff := wait.Backoff{
Duration: 100 * time.Millisecond,
Factor: 1.5,
Steps: 10,
Duration: initialDurationMs * time.Millisecond,
Factor: retryFactor,
Steps: steps,
}
if err := wait.ExponentialBackoff(backoff, condition); err != nil {
return err
Expand Down

0 comments on commit 85739af

Please sign in to comment.