mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-21 01:50:55 +00:00
Set timeout for accessing credential provider's URL
This changes sets the timeout and also adds the retry mechanism.
This commit is contained in:
@@ -26,8 +26,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/util/wait"
|
||||
)
|
||||
|
||||
// DockerConfigJson represents ~/.docker/config.json file info
|
||||
@@ -48,6 +50,10 @@ type DockerConfigEntry struct {
|
||||
Email string
|
||||
}
|
||||
|
||||
const (
|
||||
readURLTimeout = time.Second * 20
|
||||
)
|
||||
|
||||
var (
|
||||
preferredPathLock sync.Mutex
|
||||
preferredPath = ""
|
||||
@@ -138,6 +144,19 @@ func (he *HttpError) Error() string {
|
||||
}
|
||||
|
||||
func ReadUrl(url string, client *http.Client, header *http.Header) (body []byte, err error) {
|
||||
retryInterval := time.Second
|
||||
wait.PollImmediate(retryInterval, readURLTimeout, func() (bool, error) {
|
||||
body, err = readUrl(url, client, header)
|
||||
if err != nil {
|
||||
glog.V(4).Infof("Error reading %q: %v", url, err)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
return body, err
|
||||
}
|
||||
|
||||
func readUrl(url string, client *http.Client, header *http.Header) (body []byte, err error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user