Update Kubernetes to 14b32888de6403aa38aedc69086c5a3aff7a4ace
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
4
vendor/k8s.io/client-go/rest/config.go
generated
vendored
4
vendor/k8s.io/client-go/rest/config.go
generated
vendored
@@ -71,6 +71,10 @@ type Config struct {
|
||||
// TODO: demonstrate an OAuth2 compatible client.
|
||||
BearerToken string
|
||||
|
||||
// CacheDir is the directory where we'll store HTTP cached responses.
|
||||
// If set to empty string, no caching mechanism will be used.
|
||||
CacheDir string
|
||||
|
||||
// Impersonate is the configuration that RESTClient will use for impersonation.
|
||||
Impersonate ImpersonationConfig
|
||||
|
||||
|
||||
24
vendor/k8s.io/client-go/rest/request.go
generated
vendored
24
vendor/k8s.io/client-go/rest/request.go
generated
vendored
@@ -33,6 +33,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/net/http2"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -744,8 +745,29 @@ func (r *Request) DoRaw() ([]byte, error) {
|
||||
func (r *Request) transformResponse(resp *http.Response, req *http.Request) Result {
|
||||
var body []byte
|
||||
if resp.Body != nil {
|
||||
if data, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
body = data
|
||||
case http2.StreamError:
|
||||
// This is trying to catch the scenario that the server may close the connection when sending the
|
||||
// response body. This can be caused by server timeout due to a slow network connection.
|
||||
// TODO: Add test for this. Steps may be:
|
||||
// 1. client-go (or kubectl) sends a GET request.
|
||||
// 2. Apiserver sends back the headers and then part of the body
|
||||
// 3. Apiserver closes connection.
|
||||
// 4. client-go should catch this and return an error.
|
||||
glog.V(2).Infof("Stream error %#v when reading response body, may be caused by closed connection.", err)
|
||||
streamErr := fmt.Errorf("Stream error %#v when reading response body, may be caused by closed connection. Please retry.", err)
|
||||
return Result{
|
||||
err: streamErr,
|
||||
}
|
||||
default:
|
||||
glog.Errorf("Unexpected error when reading response body: %#v", err)
|
||||
unexpectedErr := fmt.Errorf("Unexpected error %#v when reading response body. Please retry.", err)
|
||||
return Result{
|
||||
err: unexpectedErr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
vendor/k8s.io/client-go/rest/transport.go
generated
vendored
1
vendor/k8s.io/client-go/rest/transport.go
generated
vendored
@@ -89,6 +89,7 @@ func (c *Config) TransportConfig() (*transport.Config, error) {
|
||||
},
|
||||
Username: c.Username,
|
||||
Password: c.Password,
|
||||
CacheDir: c.CacheDir,
|
||||
BearerToken: c.BearerToken,
|
||||
Impersonate: transport.ImpersonationConfig{
|
||||
UserName: c.Impersonate.UserName,
|
||||
|
||||
4
vendor/k8s.io/client-go/transport/config.go
generated
vendored
4
vendor/k8s.io/client-go/transport/config.go
generated
vendored
@@ -34,6 +34,10 @@ type Config struct {
|
||||
// Bearer token for authentication
|
||||
BearerToken string
|
||||
|
||||
// CacheDir is the directory where we'll store HTTP cached responses.
|
||||
// If set to empty string, no caching mechanism will be used.
|
||||
CacheDir string
|
||||
|
||||
// Impersonate is the config that this Config will impersonate using
|
||||
Impersonate ImpersonationConfig
|
||||
|
||||
|
||||
31
vendor/k8s.io/client-go/transport/round_trippers.go
generated
vendored
31
vendor/k8s.io/client-go/transport/round_trippers.go
generated
vendored
@@ -19,10 +19,14 @@ package transport
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/gregjones/httpcache"
|
||||
"github.com/gregjones/httpcache/diskcache"
|
||||
"github.com/peterbourgon/diskv"
|
||||
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
)
|
||||
@@ -56,6 +60,9 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip
|
||||
len(config.Impersonate.Extra) > 0 {
|
||||
rt = NewImpersonatingRoundTripper(config.Impersonate, rt)
|
||||
}
|
||||
if len(config.CacheDir) > 0 {
|
||||
rt = NewCacheRoundTripper(config.CacheDir, rt)
|
||||
}
|
||||
return rt, nil
|
||||
}
|
||||
|
||||
@@ -79,6 +86,30 @@ type requestCanceler interface {
|
||||
CancelRequest(*http.Request)
|
||||
}
|
||||
|
||||
type cacheRoundTripper struct {
|
||||
rt *httpcache.Transport
|
||||
}
|
||||
|
||||
// NewCacheRoundTripper creates a roundtripper that reads the ETag on
|
||||
// response headers and send the If-None-Match header on subsequent
|
||||
// corresponding requests.
|
||||
func NewCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper {
|
||||
d := diskv.New(diskv.Options{
|
||||
BasePath: cacheDir,
|
||||
TempDir: filepath.Join(cacheDir, ".diskv-temp"),
|
||||
})
|
||||
t := httpcache.NewTransport(diskcache.NewWithDiskv(d))
|
||||
t.Transport = rt
|
||||
|
||||
return &cacheRoundTripper{rt: t}
|
||||
}
|
||||
|
||||
func (rt *cacheRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
return rt.rt.RoundTrip(req)
|
||||
}
|
||||
|
||||
func (rt *cacheRoundTripper) WrappedRoundTripper() http.RoundTripper { return rt.rt.Transport }
|
||||
|
||||
type authProxyRoundTripper struct {
|
||||
username string
|
||||
groups []string
|
||||
|
||||
Reference in New Issue
Block a user