mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #5325 from brendandburns/api3
Add and extend timeouts.
This commit is contained in:
commit
03b182e8e9
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@ -639,7 +640,7 @@ func TestServeExecInContainerIdleTimeout(t *testing.T) {
|
|||||||
|
|
||||||
url := fw.testHTTPServer.URL + "/exec/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?c=ls&c=-a&" + api.ExecStdinParam + "=1"
|
url := fw.testHTTPServer.URL + "/exec/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?c=ls&c=-a&" + api.ExecStdinParam + "=1"
|
||||||
|
|
||||||
upgradeRoundTripper := spdy.NewRoundTripper(nil)
|
upgradeRoundTripper := spdy.NewSpdyRoundTripper(nil)
|
||||||
c := &http.Client{Transport: upgradeRoundTripper}
|
c := &http.Client{Transport: upgradeRoundTripper}
|
||||||
|
|
||||||
resp, err := c.Get(url)
|
resp, err := c.Get(url)
|
||||||
@ -648,6 +649,10 @@ func TestServeExecInContainerIdleTimeout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
upgradeRoundTripper.Dialer = &net.Dialer{
|
||||||
|
Deadline: time.Now().Add(60 * time.Second),
|
||||||
|
Timeout: 60 * time.Second,
|
||||||
|
}
|
||||||
conn, err := upgradeRoundTripper.NewConnection(resp)
|
conn, err := upgradeRoundTripper.NewConnection(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error creating streaming connection: %s", err)
|
t.Fatalf("Unexpected error creating streaming connection: %s", err)
|
||||||
|
@ -45,11 +45,18 @@ type SpdyRoundTripper struct {
|
|||||||
*/
|
*/
|
||||||
// conn is the underlying network connection to the remote server.
|
// conn is the underlying network connection to the remote server.
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
|
||||||
|
// Dialer is the dialer used to connect. Used if non-nil.
|
||||||
|
Dialer *net.Dialer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSpdyRoundTripper creates a new SpdyRoundTripper that will use
|
// NewSpdyRoundTripper creates a new SpdyRoundTripper that will use
|
||||||
// the specified tlsConfig.
|
// the specified tlsConfig.
|
||||||
func NewRoundTripper(tlsConfig *tls.Config) httpstream.UpgradeRoundTripper {
|
func NewRoundTripper(tlsConfig *tls.Config) httpstream.UpgradeRoundTripper {
|
||||||
|
return NewSpdyRoundTripper(tlsConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSpdyRoundTripper(tlsConfig *tls.Config) *SpdyRoundTripper {
|
||||||
return &SpdyRoundTripper{tlsConfig: tlsConfig}
|
return &SpdyRoundTripper{tlsConfig: tlsConfig}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,11 +65,21 @@ func (s *SpdyRoundTripper) dial(req *http.Request) (net.Conn, error) {
|
|||||||
dialAddr := netutil.CanonicalAddr(req.URL)
|
dialAddr := netutil.CanonicalAddr(req.URL)
|
||||||
|
|
||||||
if req.URL.Scheme == "http" {
|
if req.URL.Scheme == "http" {
|
||||||
return net.Dial("tcp", dialAddr)
|
if s.Dialer == nil {
|
||||||
|
return net.Dial("tcp", dialAddr)
|
||||||
|
} else {
|
||||||
|
return s.Dialer.Dial("tcp", dialAddr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO validate the TLSClientConfig is set up?
|
// TODO validate the TLSClientConfig is set up?
|
||||||
conn, err := tls.Dial("tcp", dialAddr, s.tlsConfig)
|
var conn *tls.Conn
|
||||||
|
var err error
|
||||||
|
if s.Dialer == nil {
|
||||||
|
conn, err = tls.Dial("tcp", dialAddr, s.tlsConfig)
|
||||||
|
} else {
|
||||||
|
conn, err = tls.DialWithDialer(s.Dialer, "tcp", dialAddr, s.tlsConfig)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user