Skip to content

Commit 652a48d

Browse files
committed
wire up proxier in spdy transport
and delete useless function
1 parent f3f666d commit 652a48d

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

pkg/kubelet/server/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ func TestServeExecInContainerIdleTimeout(t *testing.T) {
10341034

10351035
url := fw.testHTTPServer.URL + "/exec/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?c=ls&c=-a&" + api.ExecStdinParam + "=1"
10361036

1037-
upgradeRoundTripper := spdy.NewSpdyRoundTripper(nil, true, true)
1037+
upgradeRoundTripper := spdy.NewRoundTripper(nil, true, true)
10381038
c := &http.Client{Transport: upgradeRoundTripper}
10391039

10401040
resp, err := c.Do(makeReq(t, "POST", url, "v4.channel.k8s.io"))

staging/src/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,20 @@ var _ utilnet.TLSClientConfigHolder = &SpdyRoundTripper{}
7676
var _ httpstream.UpgradeRoundTripper = &SpdyRoundTripper{}
7777
var _ utilnet.Dialer = &SpdyRoundTripper{}
7878

79-
// NewRoundTripper creates a new SpdyRoundTripper that will use
80-
// the specified tlsConfig.
81-
func NewRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) httpstream.UpgradeRoundTripper {
82-
return NewSpdyRoundTripper(tlsConfig, followRedirects, requireSameHostRedirects)
79+
// NewRoundTripper creates a new SpdyRoundTripper that will use the specified
80+
// tlsConfig.
81+
func NewRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) *SpdyRoundTripper {
82+
return NewRoundTripperWithProxy(tlsConfig, followRedirects, requireSameHostRedirects, utilnet.NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment))
8383
}
8484

85-
// NewSpdyRoundTripper creates a new SpdyRoundTripper that will use
86-
// the specified tlsConfig. This function is mostly meant for unit tests.
87-
func NewSpdyRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) *SpdyRoundTripper {
85+
// NewRoundTripperWithProxy creates a new SpdyRoundTripper that will use the
86+
// specified tlsConfig and proxy func.
87+
func NewRoundTripperWithProxy(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool, proxier func(*http.Request) (*url.URL, error)) *SpdyRoundTripper {
8888
return &SpdyRoundTripper{
8989
tlsConfig: tlsConfig,
9090
followRedirects: followRedirects,
9191
requireSameHostRedirects: requireSameHostRedirects,
92+
proxier: proxier,
9293
}
9394
}
9495

@@ -116,11 +117,7 @@ func (s *SpdyRoundTripper) Dial(req *http.Request) (net.Conn, error) {
116117
// dial dials the host specified by req, using TLS if appropriate, optionally
117118
// using a proxy server if one is configured via environment variables.
118119
func (s *SpdyRoundTripper) dial(req *http.Request) (net.Conn, error) {
119-
proxier := s.proxier
120-
if proxier == nil {
121-
proxier = utilnet.NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment)
122-
}
123-
proxyURL, err := proxier(req)
120+
proxyURL, err := s.proxier(req)
124121
if err != nil {
125122
return nil, err
126123
}

staging/src/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestRoundTripAndNewConnection(t *testing.T) {
282282
t.Fatalf("%s: Error creating request: %s", k, err)
283283
}
284284

285-
spdyTransport := NewSpdyRoundTripper(testCase.clientTLS, redirect, redirect)
285+
spdyTransport := NewRoundTripper(testCase.clientTLS, redirect, redirect)
286286

287287
var proxierCalled bool
288288
var proxyCalledWithHost string
@@ -425,7 +425,7 @@ func TestRoundTripRedirects(t *testing.T) {
425425
t.Fatalf("Error creating request: %s", err)
426426
}
427427

428-
spdyTransport := NewSpdyRoundTripper(nil, true, true)
428+
spdyTransport := NewRoundTripper(nil, true, true)
429429
client := &http.Client{Transport: spdyTransport}
430430

431431
resp, err := client.Do(req)

staging/src/k8s.io/client-go/transport/spdy/spdy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ func RoundTripperFor(config *restclient.Config) (http.RoundTripper, Upgrader, er
3838
if err != nil {
3939
return nil, nil, err
4040
}
41-
upgradeRoundTripper := spdy.NewRoundTripper(tlsConfig, true, false)
41+
proxy := http.ProxyFromEnvironment
42+
if config.Proxy != nil {
43+
proxy = config.Proxy
44+
}
45+
upgradeRoundTripper := spdy.NewRoundTripperWithProxy(tlsConfig, true, false, proxy)
4246
wrapper, err := restclient.HTTPWrappersForConfig(config, upgradeRoundTripper)
4347
if err != nil {
4448
return nil, nil, err

0 commit comments

Comments
 (0)