Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ea085e0a
Commit
ea085e0a
authored
Dec 15, 2017
by
Eric Chiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client-go: remove import of github.com/gregjones/httpcache
parent
8a9954d4
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
193 additions
and
107 deletions
+193
-107
BUILD
pkg/kubectl/cmd/util/BUILD
+1
-0
factory_client_access.go
pkg/kubectl/cmd/util/factory_client_access.go
+11
-1
BUILD
pkg/kubectl/util/BUILD
+1
-0
BUILD
pkg/kubectl/util/transport/BUILD
+34
-0
round_tripper.go
pkg/kubectl/util/transport/round_tripper.go
+51
-0
round_tripper_test.go
pkg/kubectl/util/transport/round_tripper_test.go
+95
-0
config.go
staging/src/k8s.io/client-go/rest/config.go
+0
-5
config_test.go
staging/src/k8s.io/client-go/rest/config_test.go
+0
-1
transport.go
staging/src/k8s.io/client-go/rest/transport.go
+0
-1
BUILD
staging/src/k8s.io/client-go/transport/BUILD
+0
-3
config.go
staging/src/k8s.io/client-go/transport/config.go
+0
-4
round_trippers.go
staging/src/k8s.io/client-go/transport/round_trippers.go
+0
-31
round_trippers_test.go
...ing/src/k8s.io/client-go/transport/round_trippers_test.go
+0
-61
No files found.
pkg/kubectl/cmd/util/BUILD
View file @
ea085e0a
...
@@ -40,6 +40,7 @@ go_library(
...
@@ -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",
...
...
pkg/kubectl/cmd/util/factory_client_access.go
View file @
ea085e0a
...
@@ -23,6 +23,7 @@ import (
...
@@ -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 (
...
@@ -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
...
@@ -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
{
...
...
pkg/kubectl/util/BUILD
View file @
ea085e0a
...
@@ -101,6 +101,7 @@ filegroup(
...
@@ -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"],
...
...
pkg/kubectl/util/transport/BUILD
0 → 100644
View file @
ea085e0a
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"],
)
pkg/kubectl/util/transport/round_tripper.go
0 → 100644
View file @
ea085e0a
/*
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
}
pkg/kubectl/util/transport/round_tripper_test.go
0 → 100644
View file @
ea085e0a
/*
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
))
}
}
staging/src/k8s.io/client-go/rest/config.go
View file @
ea085e0a
...
@@ -71,10 +71,6 @@ type Config struct {
...
@@ -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 {
...
@@ -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
,
...
...
staging/src/k8s.io/client-go/rest/config_test.go
View file @
ea085e0a
...
@@ -267,7 +267,6 @@ func TestAnonymousConfig(t *testing.T) {
...
@@ -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
...
...
staging/src/k8s.io/client-go/rest/transport.go
View file @
ea085e0a
...
@@ -89,7 +89,6 @@ func (c *Config) TransportConfig() (*transport.Config, error) {
...
@@ -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
,
...
...
staging/src/k8s.io/client-go/transport/BUILD
View file @
ea085e0a
...
@@ -28,9 +28,6 @@ go_library(
...
@@ -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",
],
],
)
)
...
...
staging/src/k8s.io/client-go/transport/config.go
View file @
ea085e0a
...
@@ -37,10 +37,6 @@ type Config struct {
...
@@ -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
...
...
staging/src/k8s.io/client-go/transport/round_trippers.go
View file @
ea085e0a
...
@@ -19,14 +19,10 @@ package transport
...
@@ -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
...
@@ -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 {
...
@@ -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
...
...
staging/src/k8s.io/client-go/transport/round_trippers_test.go
View file @
ea085e0a
...
@@ -17,11 +17,7 @@ limitations under the License.
...
@@ -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) {
...
@@ -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
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment