mirror of
https://github.com/openbao/openbao.git
synced 2026-02-07 00:45:54 +01:00
Move to github.com/cenkalti/backoff/v5 (#2301)
Some checks failed
CI / Setup (push) Has been cancelled
CI / Verify doc-ui only PRs (push) Has been cancelled
CI / Run Go tests (push) Has been cancelled
CI / Run Go tests tagged with testonly (push) Has been cancelled
CI / Run Go tests with data race detection (push) Has been cancelled
CI / Test UI (push) Has been cancelled
CI / tests-completed (push) Has been cancelled
Run linters / Vulnerable dependencies (push) Has been cancelled
Run linters / Code checks (push) Has been cancelled
Run linters / Semgrep (push) Has been cancelled
Run linters / Go mod checks (push) Has been cancelled
Run linters / EL8 Go build checks (push) Has been cancelled
Run linters / Protobuf checks (push) Has been cancelled
CodeQL Advanced / Analyze (go) (push) Has been cancelled
Go Dependency Submission / go-dependency-submission (push) Has been cancelled
Mirror Repo / mirror (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Some checks failed
CI / Setup (push) Has been cancelled
CI / Verify doc-ui only PRs (push) Has been cancelled
CI / Run Go tests (push) Has been cancelled
CI / Run Go tests tagged with testonly (push) Has been cancelled
CI / Run Go tests with data race detection (push) Has been cancelled
CI / Test UI (push) Has been cancelled
CI / tests-completed (push) Has been cancelled
Run linters / Vulnerable dependencies (push) Has been cancelled
Run linters / Code checks (push) Has been cancelled
Run linters / Semgrep (push) Has been cancelled
Run linters / Go mod checks (push) Has been cancelled
Run linters / EL8 Go build checks (push) Has been cancelled
Run linters / Protobuf checks (push) Has been cancelled
CodeQL Advanced / Analyze (go) (push) Has been cancelled
Go Dependency Submission / go-dependency-submission (push) Has been cancelled
Mirror Repo / mirror (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
* Move to github.com/cenkalti/backoff/v5 Signed-off-by: Jonas Köhnen <jonas.koehnen@sap.com> * Make nilnil happy Signed-off-by: Jonas Köhnen <jonas.koehnen@sap.com> --------- Signed-off-by: Jonas Köhnen <jonas.koehnen@sap.com>
This commit is contained in:
@@ -9,7 +9,7 @@ replace github.com/openbao/openbao/api/v2 => ../../
|
||||
require github.com/openbao/openbao/api/v2 v2.1.0
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
||||
@@ -9,7 +9,7 @@ replace github.com/openbao/openbao/api/v2 => ../../
|
||||
require github.com/openbao/openbao/api/v2 v2.1.0
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
||||
@@ -9,7 +9,7 @@ replace github.com/openbao/openbao/api/v2 => ../../
|
||||
require github.com/openbao/openbao/api/v2 v2.1.0
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
||||
@@ -9,7 +9,7 @@ replace github.com/openbao/openbao/api/v2 => ../../
|
||||
require github.com/openbao/openbao/api/v2 v2.1.0
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
||||
@@ -10,7 +10,7 @@ go 1.24.0
|
||||
toolchain go1.24.3
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v4 v4.3.0
|
||||
github.com/cenkalti/backoff/v5 v5.0.3
|
||||
github.com/go-jose/go-jose/v4 v4.1.3
|
||||
github.com/go-test/deep v1.1.1
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/cenkalti/backoff/v5"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -308,14 +308,11 @@ func (r *LifetimeWatcher) doRenewWithOptions(tokenMode bool, nonRenewable bool,
|
||||
remainingLeaseDuration = time.Until(initialTime.Add(time.Duration(initLeaseDuration) * time.Second))
|
||||
if errorBackoff == nil {
|
||||
errorBackoff = &backoff.ExponentialBackOff{
|
||||
MaxElapsedTime: remainingLeaseDuration,
|
||||
RandomizationFactor: backoff.DefaultRandomizationFactor,
|
||||
InitialInterval: initialRetryInterval,
|
||||
MaxInterval: 5 * time.Minute,
|
||||
Multiplier: 2,
|
||||
Clock: backoff.SystemClock,
|
||||
}
|
||||
errorBackoff.Reset()
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -349,7 +346,7 @@ func (r *LifetimeWatcher) doRenewWithOptions(tokenMode bool, nonRenewable bool,
|
||||
|
||||
if errorBackoff == nil {
|
||||
sleepDuration = r.calculateSleepDuration(remainingLeaseDuration, priorDuration)
|
||||
} else if errorBackoff.NextBackOff() == backoff.Stop {
|
||||
} else if errorBackoff.NextBackOff() == backoff.Stop || remainingLeaseDuration < 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/cenkalti/backoff/v5"
|
||||
"github.com/openbao/openbao/api/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -207,36 +207,36 @@ func checkObjects(t *testing.T, roleConfig map[string]interface{}, isClusterBind
|
||||
}
|
||||
|
||||
// Check the k8s objects that should have been created (all but the ServiceAccount)
|
||||
operation := func() error {
|
||||
operation := func() (none struct{}, err error) {
|
||||
if existingRole == "" {
|
||||
exists, err := checkRoleExists(k8sClient, listOptions, roleType)
|
||||
require.NoError(t, err)
|
||||
if exists != shouldExist {
|
||||
return fmt.Errorf("%s exists (%v) but should be (%v)", roleType, exists, shouldExist)
|
||||
return none, fmt.Errorf("%s exists (%v) but should be (%v)", roleType, exists, shouldExist)
|
||||
}
|
||||
}
|
||||
|
||||
exists, err := checkRoleBindingExists(k8sClient, listOptions, isClusterBinding)
|
||||
require.NoError(t, err)
|
||||
if exists != shouldExist {
|
||||
return fmt.Errorf("binding (cluster %v) exists (%v) but should be (%v)", isClusterBinding, exists, shouldExist)
|
||||
return none, fmt.Errorf("binding (cluster %v) exists (%v) but should be (%v)", isClusterBinding, exists, shouldExist)
|
||||
}
|
||||
|
||||
exists, err = checkServiceAccountExists(k8sClient, listOptions)
|
||||
require.NoError(t, err)
|
||||
// No permission to create services accounts, so they should never get created
|
||||
if exists {
|
||||
return fmt.Errorf("service account exists (%v) but should be (false)", exists)
|
||||
return none, fmt.Errorf("service account exists (%v) but should be (false)", exists)
|
||||
}
|
||||
|
||||
return nil
|
||||
return none, nil
|
||||
}
|
||||
|
||||
bo := backoff.NewExponentialBackOff()
|
||||
bo.MaxElapsedTime = maxWaitTime
|
||||
// Don't actually back off, just keep retrying quickly to speed up the test.
|
||||
bo.Multiplier = 1
|
||||
|
||||
err = backoff.Retry(operation, bo)
|
||||
_, err = backoff.Retry(t.Context(), operation, backoff.WithBackOff(bo), backoff.WithMaxElapsedTime(maxWaitTime))
|
||||
assert.NoError(t, err, "timed out waiting for objects to exist=%v", shouldExist)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/cenkalti/backoff/v5"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
ctconfig "github.com/openbao/openbao-template/config"
|
||||
"github.com/openbao/openbao-template/manager"
|
||||
@@ -138,16 +138,16 @@ func (ts *Server) Run(ctx context.Context, incoming chan string, templates []*ct
|
||||
return fmt.Errorf("min backoff is larger than max backoff")
|
||||
}
|
||||
|
||||
var errBackoff backoff.BackOff = backoff.NewExponentialBackOff(
|
||||
backoff.WithInitialInterval(ts.minBackoff),
|
||||
backoff.WithMaxInterval(ts.maxBackoff),
|
||||
backoff.WithMultiplier(backoffMultiplier),
|
||||
backoff.WithRandomizationFactor(backoffRandomizationFactor),
|
||||
)
|
||||
var errBackoff backoff.BackOff = &backoff.ExponentialBackOff{
|
||||
InitialInterval: ts.minBackoff,
|
||||
MaxInterval: ts.maxBackoff,
|
||||
Multiplier: backoffMultiplier,
|
||||
RandomizationFactor: backoffRandomizationFactor,
|
||||
}
|
||||
|
||||
// If ExitOnRetryFailure is set, disallow retry
|
||||
if ts.config.AgentConfig.TemplateConfig != nil && ts.config.AgentConfig.TemplateConfig.ExitOnRetryFailure {
|
||||
errBackoff = backoff.WithMaxRetries(errBackoff, 0)
|
||||
errBackoff = &backoff.StopBackOff{}
|
||||
}
|
||||
|
||||
// timer to time backoffs
|
||||
|
||||
3
go.mod
3
go.mod
@@ -28,7 +28,7 @@ require (
|
||||
github.com/ProtonMail/go-crypto v1.3.0
|
||||
github.com/armon/go-radix v1.0.0
|
||||
github.com/caddyserver/certmagic v0.25.1
|
||||
github.com/cenkalti/backoff/v4 v4.3.0
|
||||
github.com/cenkalti/backoff/v5 v5.0.3
|
||||
github.com/containerd/platforms v0.2.1
|
||||
github.com/coreos/go-systemd/v22 v22.6.0
|
||||
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74
|
||||
@@ -221,6 +221,7 @@ require (
|
||||
github.com/boltdb/bolt v1.3.1 // indirect
|
||||
github.com/boombuler/barcode v1.0.1 // indirect
|
||||
github.com/caddyserver/zerossl v0.1.4 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible // indirect
|
||||
github.com/circonus-labs/circonusllhist v0.1.3 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -168,6 +168,8 @@ github.com/caddyserver/zerossl v0.1.4 h1:CVJOE3MZeFisCERZjkxIcsqIH4fnFdlYWnPYeFt
|
||||
github.com/caddyserver/zerossl v0.1.4/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/cenkalti/backoff/v5"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
metrics "github.com/hashicorp/go-metrics/compat"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
@@ -169,7 +169,7 @@ func NewPostgreSQLBackend(conf map[string]string, logger log.Logger) (physical.B
|
||||
}
|
||||
|
||||
// Create PostgreSQL handle for the database.
|
||||
db, err := doRetryConnect(logger, connURL, uint64(maxRetriesInt))
|
||||
db, err := doRetryConnect(logger, connURL, uint(maxRetriesInt))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to postgres: %w", err)
|
||||
}
|
||||
@@ -284,33 +284,26 @@ func connectionURL(conf map[string]string) string {
|
||||
return connURL
|
||||
}
|
||||
|
||||
func doRetryConnect(logger log.Logger, connURL string, retries uint64) (*sql.DB, error) {
|
||||
func doRetryConnect(logger log.Logger, connURL string, retries uint) (*sql.DB, error) {
|
||||
db, err := sql.Open("pgx", connURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var b backoff.BackOff = backoff.NewExponentialBackOff(
|
||||
backoff.WithMaxInterval(5*time.Second),
|
||||
backoff.WithInitialInterval(15*time.Millisecond),
|
||||
)
|
||||
if retries > 0 {
|
||||
b = backoff.WithMaxRetries(b, retries)
|
||||
b := backoff.NewExponentialBackOff()
|
||||
b.MaxInterval = 5 * time.Second
|
||||
b.InitialInterval = 15 * time.Millisecond
|
||||
|
||||
op := func() (none struct{}, err error) {
|
||||
if err := db.Ping(); err != nil {
|
||||
logger.Debug("database not ready", "err", err)
|
||||
return none, err
|
||||
}
|
||||
return none, nil
|
||||
}
|
||||
|
||||
b.Reset()
|
||||
|
||||
if err := backoff.Retry(func() error {
|
||||
err := db.Ping()
|
||||
if err != nil {
|
||||
logger.Debug("database not ready", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}, b); err != nil {
|
||||
db.Close()
|
||||
return nil, fmt.Errorf("unable to verify connection: %w", err)
|
||||
if _, err := backoff.Retry(context.Background(), op, backoff.WithBackOff(b), backoff.WithMaxTries(retries)); err != nil {
|
||||
return nil, errors.Join(fmt.Errorf("unable to verify connection: %w", err), db.Close())
|
||||
}
|
||||
|
||||
return db, nil
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
backoff "github.com/cenkalti/backoff/v4"
|
||||
backoff "github.com/cenkalti/backoff/v5"
|
||||
"github.com/gocql/gocql"
|
||||
"github.com/openbao/openbao/helper/testhelpers/cassandra"
|
||||
dbplugin "github.com/openbao/openbao/sdk/v2/database/dbplugin/v5"
|
||||
@@ -247,17 +247,19 @@ func TestDeleteUser(t *testing.T) {
|
||||
|
||||
func assertCreds(t testing.TB, address string, port int, username, password string, sslOpts *gocql.SslOptions, timeout time.Duration) {
|
||||
t.Helper()
|
||||
op := func() error {
|
||||
return connect(t, address, port, username, password, sslOpts)
|
||||
}
|
||||
|
||||
op := backoff.Operation[any](func() (any, error) {
|
||||
return nil, connect(t, address, port, username, password, sslOpts)
|
||||
})
|
||||
|
||||
bo := backoff.NewExponentialBackOff()
|
||||
bo.MaxElapsedTime = timeout
|
||||
bo.InitialInterval = 500 * time.Millisecond
|
||||
bo.MaxInterval = bo.InitialInterval
|
||||
bo.RandomizationFactor = 0.0
|
||||
|
||||
err := backoff.Retry(op, bo)
|
||||
if err != nil {
|
||||
if _, err := backoff.Retry(t.Context(), op,
|
||||
backoff.WithBackOff(bo),
|
||||
backoff.WithMaxElapsedTime(timeout),
|
||||
); err != nil {
|
||||
t.Fatalf("failed to connect after %s: %s", timeout, err)
|
||||
}
|
||||
}
|
||||
@@ -284,22 +286,20 @@ func connect(t testing.TB, address string, port int, username, password string,
|
||||
func assertNoCreds(t testing.TB, address string, port int, username, password string, sslOpts *gocql.SslOptions, timeout time.Duration) {
|
||||
t.Helper()
|
||||
|
||||
op := func() error {
|
||||
op := func() (none struct{}, err error) {
|
||||
// "Invert" the error so the backoff logic sees a failure to connect as a success
|
||||
err := connect(t, address, port, username, password, sslOpts)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
_ = connect(t, address, port, username, password, sslOpts)
|
||||
return none, nil
|
||||
}
|
||||
|
||||
bo := backoff.NewExponentialBackOff()
|
||||
bo.MaxElapsedTime = timeout
|
||||
bo.InitialInterval = 500 * time.Millisecond
|
||||
bo.MaxInterval = bo.InitialInterval
|
||||
bo.RandomizationFactor = 0.0
|
||||
|
||||
err := backoff.Retry(op, bo)
|
||||
if err != nil {
|
||||
if _, err := backoff.Retry(t.Context(), op,
|
||||
backoff.WithBackOff(bo),
|
||||
backoff.WithMaxElapsedTime(timeout),
|
||||
); err != nil {
|
||||
t.Fatalf("successfully connected after %s when it shouldn't", timeout)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ replace github.com/openbao/openbao/api/v2 => ../api
|
||||
|
||||
require (
|
||||
github.com/armon/go-radix v1.0.0
|
||||
github.com/cenkalti/backoff/v4 v4.3.0
|
||||
github.com/cenkalti/backoff/v5 v5.0.3
|
||||
github.com/containerd/errdefs v1.0.0
|
||||
github.com/docker/docker v28.5.2+incompatible
|
||||
github.com/docker/go-connections v0.6.0
|
||||
|
||||
@@ -30,6 +30,8 @@ github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/
|
||||
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/cenkalti/backoff/v5"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/build"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@@ -295,33 +295,32 @@ func (d *Runner) StartNewService(ctx context.Context, addSuffix, forceLocalAddr
|
||||
}
|
||||
}
|
||||
|
||||
bo := backoff.NewExponentialBackOff()
|
||||
bo.MaxInterval = time.Second * 5
|
||||
bo.MaxElapsedTime = 2 * time.Minute
|
||||
|
||||
pieces := strings.Split(result.Addrs[0], ":")
|
||||
portInt, err := strconv.Atoi(pieces[1])
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
var config ServiceConfig
|
||||
err = backoff.Retry(func() error {
|
||||
bo := backoff.NewExponentialBackOff()
|
||||
bo.MaxInterval = time.Second * 5
|
||||
|
||||
op := func() (ServiceConfig, error) {
|
||||
container, err := d.DockerAPI.ContainerInspect(ctx, result.Container.ID)
|
||||
if err != nil || !container.State.Running {
|
||||
return backoff.Permanent(fmt.Errorf("failed inspect or container %q not running: %w", result.Container.ID, err))
|
||||
return nil, backoff.Permanent(fmt.Errorf("failed inspect or container %q not running: %w", result.Container.ID, err))
|
||||
}
|
||||
|
||||
c, err := connect(ctx, pieces[0], portInt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if c == nil {
|
||||
return errors.New("service adapter returned nil error and config")
|
||||
return nil, errors.New("service adapter returned nil error and config")
|
||||
}
|
||||
config = c
|
||||
return nil
|
||||
}, bo)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
config, err := backoff.Retry(ctx, op, backoff.WithBackOff(bo), backoff.WithMaxElapsedTime(2*time.Minute))
|
||||
if err != nil {
|
||||
if !d.RunOptions.DoNotAutoRemove {
|
||||
cleanup()
|
||||
|
||||
Reference in New Issue
Block a user