Merge pull request #22192 from bprashanth/timeout_client

Auto commit by PR queue bot
pull/6/head
k8s-merge-robot 2016-03-04 22:59:24 -08:00
commit 0f335df106
2 changed files with 12 additions and 7 deletions

View File

@ -38,6 +38,7 @@ type sourceURL struct {
updates chan<- interface{}
data []byte
failureLogs int
client *http.Client
}
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,
updates: updates,
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)
go wait.Until(config.run, period, wait.NeverStop)
@ -59,7 +63,9 @@ func (s *sourceURL) run() {
if s.failureLogs < 3 {
glog.Warningf("Failed to read pods from URL: %v", err)
} 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++
} else {
@ -80,8 +86,7 @@ func (s *sourceURL) extractFromURL() error {
return err
}
req.Header = s.header
client := &http.Client{}
resp, err := client.Do(req)
resp, err := s.client.Do(req)
if err != nil {
return err
}

View File

@ -44,7 +44,7 @@ func TestURLErrorNotExistNoUpdate(t *testing.T) {
func TestExtractFromHttpBadness(t *testing.T) {
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 {
t.Errorf("Expected error")
}
@ -114,7 +114,7 @@ func TestExtractInvalidPods(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
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 {
t.Errorf("%s: Expected error", testCase.desc)
}
@ -293,7 +293,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
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 {
t.Errorf("%s: Unexpected error: %v", testCase.desc, err)
continue
@ -341,7 +341,7 @@ func TestURLWithHeader(t *testing.T) {
ch := make(chan interface{}, 1)
header := make(http.Header)
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 {
t.Fatalf("Unexpected error extracting from URL: %v", err)
}