rest.Config: support configuring an explict proxy URL

With support of http, https, and socks5 proxy support. We already
support configuring this via environmnet variables, but this approach
becomes inconvenient dealing with multiple clusters on different
networks, that require different proxies to connect to. Most solutions
require wrapping clients (like kubectl) in bash scripts.

Part of: https://github.com/kubernetes/client-go/issues/351

Kubernetes-commit: f3f666d5f1f6f74a8c948a5c64af993696178244
This commit is contained in:
Mike Danese
2019-05-03 13:50:17 -07:00
committed by Kubernetes Publisher
parent 06f6a9f888
commit 0caa50056a
14 changed files with 291 additions and 27 deletions

View File

@@ -23,6 +23,7 @@ import (
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
gruntime "runtime"
@@ -128,6 +129,13 @@ type Config struct {
// Dial specifies the dial function for creating unencrypted TCP connections.
Dial func(ctx context.Context, network, address string) (net.Conn, error)
// Proxy is the the proxy func to be used for all requests made by this
// transport. If Proxy is nil, http.ProxyFromEnvironment is used. If Proxy
// returns a nil *URL, no proxy is used.
//
// socks5 proxying does not currently support spdy streaming endpoints.
Proxy func(*http.Request) (*url.URL, error)
// Version forces a specific version to be used (if registered)
// Do we need this?
// Version string
@@ -560,6 +568,7 @@ func AnonymousClientConfig(config *Config) *Config {
Burst: config.Burst,
Timeout: config.Timeout,
Dial: config.Dial,
Proxy: config.Proxy,
}
}
@@ -601,5 +610,6 @@ func CopyConfig(config *Config) *Config {
RateLimiter: config.RateLimiter,
Timeout: config.Timeout,
Dial: config.Dial,
Proxy: config.Proxy,
}
}