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
57f308ae
Commit
57f308ae
authored
May 11, 2018
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore old cached client behavior
parent
40593557
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
9 deletions
+31
-9
fake.go
pkg/kubectl/cmd/testing/fake.go
+1
-1
config_flags.go
pkg/kubectl/cmd/util/config_flags.go
+12
-2
cached_discovery.go
staging/src/k8s.io/client-go/discovery/cached_discovery.go
+13
-5
Godeps.json
staging/src/k8s.io/metrics/Godeps/Godeps.json
+4
-0
print_test.go
test/integration/apiserver/print_test.go
+1
-1
No files found.
pkg/kubectl/cmd/testing/fake.go
View file @
57f308ae
...
...
@@ -420,7 +420,7 @@ func (f *TestFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, err
fakeClient
:=
f
.
Client
.
(
*
fake
.
RESTClient
)
cacheDir
:=
filepath
.
Join
(
""
,
".kube"
,
"cache"
,
"discovery"
)
cachedClient
,
err
:=
discovery
.
NewCachedDiscoveryClientForConfig
(
f
.
ClientConfigVal
,
cacheDir
,
time
.
Duration
(
10
*
time
.
Minute
))
cachedClient
,
err
:=
discovery
.
NewCachedDiscoveryClientForConfig
(
f
.
ClientConfigVal
,
cacheDir
,
""
,
time
.
Duration
(
10
*
time
.
Minute
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/kubectl/cmd/util/config_flags.go
View file @
57f308ae
...
...
@@ -52,6 +52,8 @@ const (
flagHTTPCacheDir
=
"cache-dir"
)
var
defaultCacheDir
=
filepath
.
Join
(
homedir
.
HomeDir
(),
".kube"
,
"http-cache"
)
// TODO(juanvallejo): move to pkg/kubectl/genericclioptions once
// the dependency on cmdutil is broken here.
// ConfigFlags composes the set of values necessary
...
...
@@ -176,8 +178,15 @@ func (f *ConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, e
// double it just so we don't end up here again for a while. This config is only used for discovery.
config
.
Burst
=
100
cacheDir
:=
computeDiscoverCacheDir
(
filepath
.
Join
(
homedir
.
HomeDir
(),
".kube"
,
"cache"
,
"discovery"
),
config
.
Host
)
return
discovery
.
NewCachedDiscoveryClientForConfig
(
config
,
cacheDir
,
time
.
Duration
(
10
*
time
.
Minute
))
// retrieve a user-provided value for the "cache-dir"
// defaulting to ~/.kube/http-cache if no user-value is given.
httpCacheDir
:=
defaultCacheDir
if
f
.
CacheDir
!=
nil
{
httpCacheDir
=
*
f
.
CacheDir
}
discoveryCacheDir
:=
computeDiscoverCacheDir
(
filepath
.
Join
(
homedir
.
HomeDir
(),
".kube"
,
"cache"
,
"discovery"
),
config
.
Host
)
return
discovery
.
NewCachedDiscoveryClientForConfig
(
config
,
discoveryCacheDir
,
httpCacheDir
,
time
.
Duration
(
10
*
time
.
Minute
))
}
// RESTMapper returns a mapper.
...
...
@@ -271,6 +280,7 @@ func NewConfigFlags() *ConfigFlags {
Timeout
:
stringptr
(
"0"
),
KubeConfig
:
stringptr
(
""
),
CacheDir
:
stringptr
(
defaultCacheDir
),
ClusterName
:
stringptr
(
""
),
AuthInfoName
:
stringptr
(
""
),
Context
:
stringptr
(
""
),
...
...
staging/src/k8s.io/client-go/discovery/cached_discovery.go
View file @
57f308ae
...
...
@@ -239,10 +239,18 @@ func (d *CachedDiscoveryClient) Invalidate() {
}
// NewCachedDiscoveryClientForConfig creates a new DiscoveryClient for the given config, and wraps
// the created client in a CachedDiscoveryClient. The provided configuration is upd
d
ated with a
// the created client in a CachedDiscoveryClient. The provided configuration is updated with a
// custom transport that understands cache responses.
func
NewCachedDiscoveryClientForConfig
(
config
*
restclient
.
Config
,
cacheDirectory
string
,
ttl
time
.
Duration
)
(
*
CachedDiscoveryClient
,
error
)
{
if
len
(
cacheDirectory
)
>
0
{
// We receive two distinct cache directories for now, in order to preserve old behavior
// which makes use of the --cache-dir flag value for storing cache data from the CacheRoundTripper,
// and makes use of the hardcoded destination (~/.kube/cache/discovery/...) for storing
// CachedDiscoveryClient cache data. If httpCacheDir is empty, the restconfig's transport will not
// be updated with a roundtripper that understands cache responses.
// If discoveryCacheDir is empty, cached server resource data will be looked up in the current directory.
// TODO(juanvallejo): the value of "--cache-dir" should be honored. Consolidate discoveryCacheDir with httpCacheDir
// so that server resources and http-cache data are stored in the same location, provided via config flags.
func
NewCachedDiscoveryClientForConfig
(
config
*
restclient
.
Config
,
discoveryCacheDir
,
httpCacheDir
string
,
ttl
time
.
Duration
)
(
*
CachedDiscoveryClient
,
error
)
{
if
len
(
httpCacheDir
)
>
0
{
// update the given restconfig with a custom roundtripper that
// understands how to handle cache responses.
wt
:=
config
.
WrapTransport
...
...
@@ -250,7 +258,7 @@ func NewCachedDiscoveryClientForConfig(config *restclient.Config, cacheDirectory
if
wt
!=
nil
{
rt
=
wt
(
rt
)
}
return
newCacheRoundTripper
(
cacheDirectory
,
rt
)
return
newCacheRoundTripper
(
httpCacheDir
,
rt
)
}
}
...
...
@@ -259,7 +267,7 @@ func NewCachedDiscoveryClientForConfig(config *restclient.Config, cacheDirectory
return
nil
,
err
}
return
newCachedDiscoveryClient
(
discoveryClient
,
cacheDirectory
,
ttl
),
nil
return
newCachedDiscoveryClient
(
discoveryClient
,
discoveryCacheDir
,
ttl
),
nil
}
// NewCachedDiscoveryClient creates a new DiscoveryClient. cacheDirectory is the directory where discovery docs are held. It must be unique per host:port combination to work well.
...
...
staging/src/k8s.io/metrics/Godeps/Godeps.json
View file @
57f308ae
...
...
@@ -83,6 +83,10 @@
"Rev"
:
"05fbef0ca5da472bbf96c9322b84a53edc03c9fd"
},
{
"ImportPath"
:
"github.com/peterbourgon/diskv"
,
"Rev"
:
"5f041e8faa004a95c88a202771f4cc3e991971e6"
},
{
"ImportPath"
:
"golang.org/x/crypto/ssh/terminal"
,
"Rev"
:
"49796115aa4b964c318aad4f3084fdb41e9aa067"
},
...
...
test/integration/apiserver/print_test.go
View file @
57f308ae
...
...
@@ -165,7 +165,7 @@ func TestServerSidePrint(t *testing.T) {
os
.
Remove
(
cacheDir
)
}()
cachedClient
,
err
:=
discovery
.
NewCachedDiscoveryClientForConfig
(
restConfig
,
cacheDir
,
time
.
Duration
(
10
*
time
.
Minute
))
cachedClient
,
err
:=
discovery
.
NewCachedDiscoveryClientForConfig
(
restConfig
,
cacheDir
,
""
,
time
.
Duration
(
10
*
time
.
Minute
))
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
...
...
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