client-go: remove import of github.com/gregjones/httpcache

Kubernetes-commit: ea085e0a32a6b723e5c565e60d8941b5a760bb68
This commit is contained in:
Eric Chiang 2017-12-15 15:02:31 -08:00 committed by Kubernetes Publisher
parent 271600dc67
commit 77f9dfa073
7 changed files with 0 additions and 106 deletions

View File

@ -71,10 +71,6 @@ type Config struct {
// TODO: demonstrate an OAuth2 compatible client. // TODO: demonstrate an OAuth2 compatible client.
BearerToken string 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 is the configuration that RESTClient will use for impersonation.
Impersonate ImpersonationConfig Impersonate ImpersonationConfig
@ -434,7 +430,6 @@ func CopyConfig(config *Config) *Config {
Username: config.Username, Username: config.Username,
Password: config.Password, Password: config.Password,
BearerToken: config.BearerToken, BearerToken: config.BearerToken,
CacheDir: config.CacheDir,
Impersonate: ImpersonationConfig{ Impersonate: ImpersonationConfig{
Groups: config.Impersonate.Groups, Groups: config.Impersonate.Groups,
Extra: config.Impersonate.Extra, Extra: config.Impersonate.Extra,

View File

@ -267,7 +267,6 @@ func TestAnonymousConfig(t *testing.T) {
expected.BearerToken = "" expected.BearerToken = ""
expected.Username = "" expected.Username = ""
expected.Password = "" expected.Password = ""
expected.CacheDir = ""
expected.AuthProvider = nil expected.AuthProvider = nil
expected.AuthConfigPersister = nil expected.AuthConfigPersister = nil
expected.TLSClientConfig.CertData = nil expected.TLSClientConfig.CertData = nil

View File

@ -89,7 +89,6 @@ func (c *Config) TransportConfig() (*transport.Config, error) {
}, },
Username: c.Username, Username: c.Username,
Password: c.Password, Password: c.Password,
CacheDir: c.CacheDir,
BearerToken: c.BearerToken, BearerToken: c.BearerToken,
Impersonate: transport.ImpersonationConfig{ Impersonate: transport.ImpersonationConfig{
UserName: c.Impersonate.UserName, UserName: c.Impersonate.UserName,

View File

@ -28,9 +28,6 @@ go_library(
importpath = "k8s.io/client-go/transport", importpath = "k8s.io/client-go/transport",
deps = [ deps = [
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/gregjones/httpcache:go_default_library",
"//vendor/github.com/gregjones/httpcache/diskcache:go_default_library",
"//vendor/github.com/peterbourgon/diskv:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
], ],
) )

View File

@ -37,10 +37,6 @@ type Config struct {
// Bearer token for authentication // Bearer token for authentication
BearerToken string 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 is the config that this Config will impersonate using
Impersonate ImpersonationConfig Impersonate ImpersonationConfig

View File

@ -19,14 +19,10 @@ package transport
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"path/filepath"
"strings" "strings"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"
"github.com/peterbourgon/diskv"
utilnet "k8s.io/apimachinery/pkg/util/net" utilnet "k8s.io/apimachinery/pkg/util/net"
) )
@ -60,9 +56,6 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip
len(config.Impersonate.Extra) > 0 { len(config.Impersonate.Extra) > 0 {
rt = NewImpersonatingRoundTripper(config.Impersonate, rt) rt = NewImpersonatingRoundTripper(config.Impersonate, rt)
} }
if len(config.CacheDir) > 0 {
rt = NewCacheRoundTripper(config.CacheDir, rt)
}
return rt, nil return rt, nil
} }
@ -86,30 +79,6 @@ type requestCanceler interface {
CancelRequest(*http.Request) 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 { type authProxyRoundTripper struct {
username string username string
groups []string groups []string

View File

@ -17,11 +17,7 @@ limitations under the License.
package transport package transport
import ( import (
"bytes"
"io/ioutil"
"net/http" "net/http"
"net/url"
"os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -220,60 +216,3 @@ func TestAuthProxyRoundTripper(t *testing.T) {
} }
} }
} }
func TestCacheRoundTripper(t *testing.T) {
rt := &testRoundTripper{}
cacheDir, err := ioutil.TempDir("", "cache-rt")
defer os.RemoveAll(cacheDir)
if err != nil {
t.Fatal(err)
}
cache := NewCacheRoundTripper(cacheDir, rt)
// First call, caches the response
req := &http.Request{
Method: http.MethodGet,
URL: &url.URL{Host: "localhost"},
}
rt.Response = &http.Response{
Header: http.Header{"ETag": []string{`"123456"`}},
Body: ioutil.NopCloser(bytes.NewReader([]byte("Content"))),
StatusCode: http.StatusOK,
}
resp, err := cache.RoundTrip(req)
if err != nil {
t.Fatal(err)
}
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if string(content) != "Content" {
t.Errorf(`Expected Body to be "Content", got %q`, string(content))
}
// Second call, returns cached response
req = &http.Request{
Method: http.MethodGet,
URL: &url.URL{Host: "localhost"},
}
rt.Response = &http.Response{
StatusCode: http.StatusNotModified,
Body: ioutil.NopCloser(bytes.NewReader([]byte("Other Content"))),
}
resp, err = cache.RoundTrip(req)
if err != nil {
t.Fatal(err)
}
// Read body and make sure we have the initial content
content, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
t.Fatal(err)
}
if string(content) != "Content" {
t.Errorf("Invalid content read from cache %q", string(content))
}
}