mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Merge pull request #22192 from bprashanth/timeout_client
Auto commit by PR queue bot
This commit is contained in:
commit
0f335df106
@ -38,6 +38,7 @@ type sourceURL struct {
|
|||||||
updates chan<- interface{}
|
updates chan<- interface{}
|
||||||
data []byte
|
data []byte
|
||||||
failureLogs int
|
failureLogs int
|
||||||
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSourceURL(url string, header http.Header, nodeName string, period time.Duration, updates chan<- interface{}) {
|
func NewSourceURL(url string, header http.Header, nodeName string, period time.Duration, updates chan<- interface{}) {
|
||||||
@ -47,6 +48,9 @@ func NewSourceURL(url string, header http.Header, nodeName string, period time.D
|
|||||||
nodeName: nodeName,
|
nodeName: nodeName,
|
||||||
updates: updates,
|
updates: updates,
|
||||||
data: nil,
|
data: nil,
|
||||||
|
// Timing out requests leads to retries. This client is only used to
|
||||||
|
// read the the manifest URL passed to kubelet.
|
||||||
|
client: &http.Client{Timeout: 10 * time.Second},
|
||||||
}
|
}
|
||||||
glog.V(1).Infof("Watching URL %s", url)
|
glog.V(1).Infof("Watching URL %s", url)
|
||||||
go wait.Until(config.run, period, wait.NeverStop)
|
go wait.Until(config.run, period, wait.NeverStop)
|
||||||
@ -59,7 +63,9 @@ func (s *sourceURL) run() {
|
|||||||
if s.failureLogs < 3 {
|
if s.failureLogs < 3 {
|
||||||
glog.Warningf("Failed to read pods from URL: %v", err)
|
glog.Warningf("Failed to read pods from URL: %v", err)
|
||||||
} else if s.failureLogs == 3 {
|
} else if s.failureLogs == 3 {
|
||||||
glog.Warningf("Failed to read pods from URL. Won't log this message anymore: %v", err)
|
glog.Warningf("Failed to read pods from URL. Dropping verbosity of this message to V(4): %v", err)
|
||||||
|
} else {
|
||||||
|
glog.V(4).Infof("Failed to read pods from URL: %v", err)
|
||||||
}
|
}
|
||||||
s.failureLogs++
|
s.failureLogs++
|
||||||
} else {
|
} else {
|
||||||
@ -80,8 +86,7 @@ func (s *sourceURL) extractFromURL() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
req.Header = s.header
|
req.Header = s.header
|
||||||
client := &http.Client{}
|
resp, err := s.client.Do(req)
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func TestURLErrorNotExistNoUpdate(t *testing.T) {
|
|||||||
|
|
||||||
func TestExtractFromHttpBadness(t *testing.T) {
|
func TestExtractFromHttpBadness(t *testing.T) {
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
c := sourceURL{"http://localhost:49575/_not_found_", http.Header{}, "other", ch, nil, 0}
|
c := sourceURL{"http://localhost:49575/_not_found_", http.Header{}, "other", ch, nil, 0, http.DefaultClient}
|
||||||
if err := c.extractFromURL(); err == nil {
|
if err := c.extractFromURL(); err == nil {
|
||||||
t.Errorf("Expected error")
|
t.Errorf("Expected error")
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ func TestExtractInvalidPods(t *testing.T) {
|
|||||||
// TODO: Uncomment when fix #19254
|
// TODO: Uncomment when fix #19254
|
||||||
// defer testServer.Close()
|
// defer testServer.Close()
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
c := sourceURL{testServer.URL, http.Header{}, "localhost", ch, nil, 0}
|
c := sourceURL{testServer.URL, http.Header{}, "localhost", ch, nil, 0, http.DefaultClient}
|
||||||
if err := c.extractFromURL(); err == nil {
|
if err := c.extractFromURL(); err == nil {
|
||||||
t.Errorf("%s: Expected error", testCase.desc)
|
t.Errorf("%s: Expected error", testCase.desc)
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
// TODO: Uncomment when fix #19254
|
// TODO: Uncomment when fix #19254
|
||||||
// defer testServer.Close()
|
// defer testServer.Close()
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
c := sourceURL{testServer.URL, http.Header{}, hostname, ch, nil, 0}
|
c := sourceURL{testServer.URL, http.Header{}, hostname, ch, nil, 0, http.DefaultClient}
|
||||||
if err := c.extractFromURL(); err != nil {
|
if err := c.extractFromURL(); err != nil {
|
||||||
t.Errorf("%s: Unexpected error: %v", testCase.desc, err)
|
t.Errorf("%s: Unexpected error: %v", testCase.desc, err)
|
||||||
continue
|
continue
|
||||||
@ -341,7 +341,7 @@ func TestURLWithHeader(t *testing.T) {
|
|||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
header := make(http.Header)
|
header := make(http.Header)
|
||||||
header.Set("Metadata-Flavor", "Google")
|
header.Set("Metadata-Flavor", "Google")
|
||||||
c := sourceURL{testServer.URL, header, "localhost", ch, nil, 0}
|
c := sourceURL{testServer.URL, header, "localhost", ch, nil, 0, http.DefaultClient}
|
||||||
if err := c.extractFromURL(); err != nil {
|
if err := c.extractFromURL(); err != nil {
|
||||||
t.Fatalf("Unexpected error extracting from URL: %v", err)
|
t.Fatalf("Unexpected error extracting from URL: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user