Skip to content

Commit

Permalink
chore(vault): custom retry check function (#4475)
Browse files Browse the repository at this point in the history
* vault retry check function

---------

Co-authored-by: I557621 <[email protected]>
  • Loading branch information
Jk1484 and I557621 authored Sep 26, 2023
1 parent 4c9dd41 commit 2ab1e2a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/vault/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package vault

import (
"context"
"encoding/json"
"fmt"
"net/http"
"path"
"strconv"
"strings"
Expand Down Expand Up @@ -41,6 +43,25 @@ func NewClient(config *Config, token string) (Client, error) {
return Client{}, err
}

client.SetMinRetryWait(time.Second * 3)
client.SetMaxRetryWait(time.Second * 5)
client.SetCheckRetry(func(ctx context.Context, resp *http.Response, err error) (bool, error) {
if resp != nil {
log.Entry().Infoln("Vault retry: ", resp.Status, resp.StatusCode, err)
} else {
log.Entry().Infoln("Vault retry: ", err)
}

retry, err := api.DefaultRetryPolicy(ctx, resp, err)
if err != nil || retry {
return true, nil
}
if resp != nil && resp.StatusCode >= 400 {
return true, nil
}
return false, nil
})

if config.Namespace != "" {
client.SetNamespace(config.Namespace)
}
Expand Down

0 comments on commit 2ab1e2a

Please sign in to comment.