mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #57259 from ericchiang/client-go-no-cache-import
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. client-go: remove import of github.com/gregjones/httpcache Moves NewCacheRoundTripper from `k8s.io/client-go/transport` to its own package. This prevents Kubernetes clients from requiring its dependencies. This change removes the following transitive imports from `k8s.io/client-go/kubernetes` ``` github.com/google/btree github.com/gregjones/httpcache github.com/gregjones/httpcache/diskcache github.com/peterbourgon/diskv ``` ```release-note NONE ```
This commit is contained in:
commit
4a77bd53e8
@ -40,6 +40,7 @@ go_library(
|
|||||||
"//pkg/kubectl/plugins:go_default_library",
|
"//pkg/kubectl/plugins:go_default_library",
|
||||||
"//pkg/kubectl/resource:go_default_library",
|
"//pkg/kubectl/resource:go_default_library",
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
|
"//pkg/kubectl/util/transport:go_default_library",
|
||||||
"//pkg/kubectl/validation:go_default_library",
|
"//pkg/kubectl/validation:go_default_library",
|
||||||
"//pkg/printers:go_default_library",
|
"//pkg/printers:go_default_library",
|
||||||
"//pkg/printers/internalversion:go_default_library",
|
"//pkg/printers/internalversion:go_default_library",
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -59,6 +60,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/util/transport"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||||
)
|
)
|
||||||
@ -109,7 +111,15 @@ func (f *discoveryFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.CacheDir = f.cacheDir
|
if f.cacheDir != "" {
|
||||||
|
wt := cfg.WrapTransport
|
||||||
|
cfg.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
|
||||||
|
if wt != nil {
|
||||||
|
rt = wt(rt)
|
||||||
|
}
|
||||||
|
return transport.NewCacheRoundTripper(f.cacheDir, rt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
|
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -101,6 +101,7 @@ filegroup(
|
|||||||
"//pkg/kubectl/util/logs:all-srcs",
|
"//pkg/kubectl/util/logs:all-srcs",
|
||||||
"//pkg/kubectl/util/slice:all-srcs",
|
"//pkg/kubectl/util/slice:all-srcs",
|
||||||
"//pkg/kubectl/util/term:all-srcs",
|
"//pkg/kubectl/util/term:all-srcs",
|
||||||
|
"//pkg/kubectl/util/transport:all-srcs",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
visibility = ["//build/visible_to:pkg_kubectl_util_CONSUMERS"],
|
visibility = ["//build/visible_to:pkg_kubectl_util_CONSUMERS"],
|
||||||
|
34
pkg/kubectl/util/transport/BUILD
Normal file
34
pkg/kubectl/util/transport/BUILD
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["round_tripper.go"],
|
||||||
|
importpath = "k8s.io/kubernetes/pkg/kubectl/util/transport",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//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",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["round_tripper_test.go"],
|
||||||
|
embed = [":go_default_library"],
|
||||||
|
importpath = "k8s.io/kubernetes/pkg/kubectl/util/transport",
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "package-srcs",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "all-srcs",
|
||||||
|
srcs = [":package-srcs"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
51
pkg/kubectl/util/transport/round_tripper.go
Normal file
51
pkg/kubectl/util/transport/round_tripper.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package transport provides a round tripper capable of caching HTTP responses.
|
||||||
|
package transport
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/gregjones/httpcache"
|
||||||
|
"github.com/gregjones/httpcache/diskcache"
|
||||||
|
"github.com/peterbourgon/diskv"
|
||||||
|
)
|
||||||
|
|
||||||
|
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 }
|
95
pkg/kubectl/util/transport/round_tripper_test.go
Normal file
95
pkg/kubectl/util/transport/round_tripper_test.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package transport
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// copied from k8s.io/client-go/transport/round_trippers_test.go
|
||||||
|
type testRoundTripper struct {
|
||||||
|
Request *http.Request
|
||||||
|
Response *http.Response
|
||||||
|
Err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rt *testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
rt.Request = req
|
||||||
|
return rt.Response, rt.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
@ -190,10 +190,6 @@
|
|||||||
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
||||||
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/google/btree",
|
|
||||||
"Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
||||||
@ -210,14 +206,6 @@
|
|||||||
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
||||||
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/hashicorp/golang-lru",
|
"ImportPath": "github.com/hashicorp/golang-lru",
|
||||||
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
||||||
@ -270,10 +258,6 @@
|
|||||||
"ImportPath": "github.com/pborman/uuid",
|
"ImportPath": "github.com/pborman/uuid",
|
||||||
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
||||||
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
||||||
|
12
staging/src/k8s.io/apiserver/Godeps/Godeps.json
generated
12
staging/src/k8s.io/apiserver/Godeps/Godeps.json
generated
@ -518,14 +518,6 @@
|
|||||||
"ImportPath": "github.com/gophercloud/gophercloud/pagination",
|
"ImportPath": "github.com/gophercloud/gophercloud/pagination",
|
||||||
"Rev": "8e59687aa4b27ab22a0bf3295f1e165ff7bd5f97"
|
"Rev": "8e59687aa4b27ab22a0bf3295f1e165ff7bd5f97"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/grpc-ecosystem/go-grpc-prometheus",
|
"ImportPath": "github.com/grpc-ecosystem/go-grpc-prometheus",
|
||||||
"Rev": "2500245aa6110c562d17020fb31a2c133d737799"
|
"Rev": "2500245aa6110c562d17020fb31a2c133d737799"
|
||||||
@ -594,10 +586,6 @@
|
|||||||
"ImportPath": "github.com/pborman/uuid",
|
"ImportPath": "github.com/pborman/uuid",
|
||||||
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
||||||
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
||||||
|
16
staging/src/k8s.io/client-go/Godeps/Godeps.json
generated
16
staging/src/k8s.io/client-go/Godeps/Godeps.json
generated
@ -150,10 +150,6 @@
|
|||||||
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
||||||
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/google/btree",
|
|
||||||
"Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
||||||
@ -198,14 +194,6 @@
|
|||||||
"ImportPath": "github.com/gophercloud/gophercloud/pagination",
|
"ImportPath": "github.com/gophercloud/gophercloud/pagination",
|
||||||
"Rev": "8e59687aa4b27ab22a0bf3295f1e165ff7bd5f97"
|
"Rev": "8e59687aa4b27ab22a0bf3295f1e165ff7bd5f97"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/hashicorp/golang-lru",
|
"ImportPath": "github.com/hashicorp/golang-lru",
|
||||||
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
||||||
@ -246,10 +234,6 @@
|
|||||||
"ImportPath": "github.com/mailru/easyjson/jwriter",
|
"ImportPath": "github.com/mailru/easyjson/jwriter",
|
||||||
"Rev": "2f5df55504ebc322e4d52d34df6a1f5b503bf26d"
|
"Rev": "2f5df55504ebc322e4d52d34df6a1f5b503bf26d"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
||||||
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
||||||
|
@ -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,
|
||||||
|
@ -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
|
||||||
|
@ -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,
|
||||||
|
@ -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",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -170,10 +170,6 @@
|
|||||||
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
||||||
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/google/btree",
|
|
||||||
"Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
||||||
@ -190,14 +186,6 @@
|
|||||||
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
||||||
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/hashicorp/golang-lru",
|
"ImportPath": "github.com/hashicorp/golang-lru",
|
||||||
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
||||||
@ -250,10 +238,6 @@
|
|||||||
"ImportPath": "github.com/pborman/uuid",
|
"ImportPath": "github.com/pborman/uuid",
|
||||||
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
"ImportPath": "github.com/pmezard/go-difflib/difflib",
|
||||||
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
|
||||||
|
16
staging/src/k8s.io/metrics/Godeps/Godeps.json
generated
16
staging/src/k8s.io/metrics/Godeps/Godeps.json
generated
@ -74,10 +74,6 @@
|
|||||||
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
||||||
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/google/btree",
|
|
||||||
"Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
||||||
@ -94,14 +90,6 @@
|
|||||||
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
||||||
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/json-iterator/go",
|
"ImportPath": "github.com/json-iterator/go",
|
||||||
"Rev": "13f86432b882000a51c6e610c620974462691a97"
|
"Rev": "13f86432b882000a51c6e610c620974462691a97"
|
||||||
@ -122,10 +110,6 @@
|
|||||||
"ImportPath": "github.com/mailru/easyjson/jwriter",
|
"ImportPath": "github.com/mailru/easyjson/jwriter",
|
||||||
"Rev": "2f5df55504ebc322e4d52d34df6a1f5b503bf26d"
|
"Rev": "2f5df55504ebc322e4d52d34df6a1f5b503bf26d"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/spf13/pflag",
|
"ImportPath": "github.com/spf13/pflag",
|
||||||
"Rev": "9ff6c6923cfffbcd502984b8e0c80539a94968b7"
|
"Rev": "9ff6c6923cfffbcd502984b8e0c80539a94968b7"
|
||||||
|
@ -162,10 +162,6 @@
|
|||||||
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
||||||
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/google/btree",
|
|
||||||
"Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
||||||
@ -182,14 +178,6 @@
|
|||||||
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
||||||
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/hashicorp/golang-lru",
|
"ImportPath": "github.com/hashicorp/golang-lru",
|
||||||
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
||||||
@ -242,10 +230,6 @@
|
|||||||
"ImportPath": "github.com/pborman/uuid",
|
"ImportPath": "github.com/pborman/uuid",
|
||||||
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/prometheus/client_golang/prometheus",
|
"ImportPath": "github.com/prometheus/client_golang/prometheus",
|
||||||
"Rev": "e7e903064f5e9eb5da98208bae10b475d4db0f8c"
|
"Rev": "e7e903064f5e9eb5da98208bae10b475d4db0f8c"
|
||||||
|
@ -82,10 +82,6 @@
|
|||||||
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
|
||||||
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/google/btree",
|
|
||||||
"Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
|
||||||
@ -102,14 +98,6 @@
|
|||||||
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
"ImportPath": "github.com/googleapis/gnostic/extensions",
|
||||||
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/gregjones/httpcache/diskcache",
|
|
||||||
"Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/hashicorp/golang-lru",
|
"ImportPath": "github.com/hashicorp/golang-lru",
|
||||||
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
|
||||||
@ -146,10 +134,6 @@
|
|||||||
"ImportPath": "github.com/mailru/easyjson/jwriter",
|
"ImportPath": "github.com/mailru/easyjson/jwriter",
|
||||||
"Rev": "2f5df55504ebc322e4d52d34df6a1f5b503bf26d"
|
"Rev": "2f5df55504ebc322e4d52d34df6a1f5b503bf26d"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/peterbourgon/diskv",
|
|
||||||
"Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/spf13/pflag",
|
"ImportPath": "github.com/spf13/pflag",
|
||||||
"Rev": "9ff6c6923cfffbcd502984b8e0c80539a94968b7"
|
"Rev": "9ff6c6923cfffbcd502984b8e0c80539a94968b7"
|
||||||
|
Loading…
Reference in New Issue
Block a user