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
5e8e8dcf
Unverified
Commit
5e8e8dcf
authored
Oct 23, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 23, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70101 from imjching/68026-fix-golint-failures-discovery
Fix linting issues in staging/src/k8s.io/client-go/discovery/*
parents
f827a982
7a317e62
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
15 deletions
+45
-15
.golint_failures
hack/.golint_failures
+0
-1
memcache.go
staging/src/k8s.io/client-go/discovery/cached/memcache.go
+1
-0
cached_discovery.go
staging/src/k8s.io/client-go/discovery/cached_discovery.go
+13
-0
discovery_client.go
staging/src/k8s.io/client-go/discovery/discovery_client.go
+12
-12
discovery.go
staging/src/k8s.io/client-go/discovery/fake/discovery.go
+13
-0
helper.go
staging/src/k8s.io/client-go/discovery/helper.go
+6
-2
No files found.
hack/.golint_failures
View file @
5e8e8dcf
...
...
@@ -623,7 +623,6 @@ staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers
staging/src/k8s.io/cli-runtime/pkg/genericclioptions/resource
staging/src/k8s.io/client-go/deprecated-dynamic
staging/src/k8s.io/client-go/discovery
staging/src/k8s.io/client-go/discovery/cached
staging/src/k8s.io/client-go/discovery/fake
staging/src/k8s.io/client-go/dynamic
staging/src/k8s.io/client-go/dynamic/fake
...
...
staging/src/k8s.io/client-go/discovery/cached/memcache.go
View file @
5e8e8dcf
...
...
@@ -44,6 +44,7 @@ type memCacheClient struct {
cacheValid
bool
}
// Error Constants
var
(
ErrCacheEmpty
=
errors
.
New
(
"the cache has not been filled yet"
)
ErrCacheNotFound
=
errors
.
New
(
"not found"
)
...
...
staging/src/k8s.io/client-go/discovery/cached_discovery.go
View file @
5e8e8dcf
...
...
@@ -94,6 +94,8 @@ func (d *CachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList, er
return
ServerResources
(
d
)
}
// ServerGroups returns the supported groups, with information like supported versions and the
// preferred version.
func
(
d
*
CachedDiscoveryClient
)
ServerGroups
()
(
*
metav1
.
APIGroupList
,
error
)
{
filename
:=
filepath
.
Join
(
d
.
cacheDirectory
,
"servergroups.json"
)
cachedBytes
,
err
:=
d
.
getCachedFile
(
filename
)
...
...
@@ -202,26 +204,36 @@ func (d *CachedDiscoveryClient) writeCachedFile(filename string, obj runtime.Obj
return
err
}
// RESTClient returns a RESTClient that is used to communicate with API server
// by this client implementation.
func
(
d
*
CachedDiscoveryClient
)
RESTClient
()
restclient
.
Interface
{
return
d
.
delegate
.
RESTClient
()
}
// ServerPreferredResources returns the supported resources with the version preferred by the
// server.
func
(
d
*
CachedDiscoveryClient
)
ServerPreferredResources
()
([]
*
metav1
.
APIResourceList
,
error
)
{
return
ServerPreferredResources
(
d
)
}
// ServerPreferredNamespacedResources returns the supported namespaced resources with the
// version preferred by the server.
func
(
d
*
CachedDiscoveryClient
)
ServerPreferredNamespacedResources
()
([]
*
metav1
.
APIResourceList
,
error
)
{
return
ServerPreferredNamespacedResources
(
d
)
}
// ServerVersion retrieves and parses the server's version (git version).
func
(
d
*
CachedDiscoveryClient
)
ServerVersion
()
(
*
version
.
Info
,
error
)
{
return
d
.
delegate
.
ServerVersion
()
}
// OpenAPISchema retrieves and parses the swagger API schema the server supports.
func
(
d
*
CachedDiscoveryClient
)
OpenAPISchema
()
(
*
openapi_v2
.
Document
,
error
)
{
return
d
.
delegate
.
OpenAPISchema
()
}
// Fresh is supposed to tell the caller whether or not to retry if the cache
// fails to find something (false = retry, true = no need to retry).
func
(
d
*
CachedDiscoveryClient
)
Fresh
()
bool
{
d
.
mutex
.
Lock
()
defer
d
.
mutex
.
Unlock
()
...
...
@@ -229,6 +241,7 @@ func (d *CachedDiscoveryClient) Fresh() bool {
return
d
.
fresh
}
// Invalidate enforces that no cached data is used in the future that is older than the current time.
func
(
d
*
CachedDiscoveryClient
)
Invalidate
()
{
d
.
mutex
.
Lock
()
defer
d
.
mutex
.
Unlock
()
...
...
staging/src/k8s.io/client-go/discovery/discovery_client.go
View file @
5e8e8dcf
...
...
@@ -263,8 +263,8 @@ func ServerPreferredResources(d DiscoveryInterface) ([]*metav1.APIResourceList,
result
:=
[]
*
metav1
.
APIResourceList
{}
grVersions
:=
map
[
schema
.
GroupResource
]
string
{}
// selected version of a GroupResource
grA
pi
Resources
:=
map
[
schema
.
GroupResource
]
*
metav1
.
APIResource
{}
// selected APIResource for a GroupResource
gvA
pi
ResourceLists
:=
map
[
schema
.
GroupVersion
]
*
metav1
.
APIResourceList
{}
// blueprint for a APIResourceList for later grouping
grA
PI
Resources
:=
map
[
schema
.
GroupResource
]
*
metav1
.
APIResource
{}
// selected APIResource for a GroupResource
gvA
PI
ResourceLists
:=
map
[
schema
.
GroupVersion
]
*
metav1
.
APIResourceList
{}
// blueprint for a APIResourceList for later grouping
for
_
,
apiGroup
:=
range
serverGroupList
.
Groups
{
for
_
,
version
:=
range
apiGroup
.
Versions
{
...
...
@@ -276,11 +276,11 @@ func ServerPreferredResources(d DiscoveryInterface) ([]*metav1.APIResourceList,
}
// create empty list which is filled later in another loop
emptyA
pi
ResourceList
:=
metav1
.
APIResourceList
{
emptyA
PI
ResourceList
:=
metav1
.
APIResourceList
{
GroupVersion
:
version
.
GroupVersion
,
}
gvA
piResourceLists
[
groupVersion
]
=
&
emptyApi
ResourceList
result
=
append
(
result
,
&
emptyA
pi
ResourceList
)
gvA
PIResourceLists
[
groupVersion
]
=
&
emptyAPI
ResourceList
result
=
append
(
result
,
&
emptyA
PI
ResourceList
)
for
i
:=
range
apiResourceList
.
APIResources
{
apiResource
:=
&
apiResourceList
.
APIResources
[
i
]
...
...
@@ -288,21 +288,21 @@ func ServerPreferredResources(d DiscoveryInterface) ([]*metav1.APIResourceList,
continue
}
gv
:=
schema
.
GroupResource
{
Group
:
apiGroup
.
Name
,
Resource
:
apiResource
.
Name
}
if
_
,
ok
:=
grA
pi
Resources
[
gv
];
ok
&&
version
.
Version
!=
apiGroup
.
PreferredVersion
.
Version
{
if
_
,
ok
:=
grA
PI
Resources
[
gv
];
ok
&&
version
.
Version
!=
apiGroup
.
PreferredVersion
.
Version
{
// only override with preferred version
continue
}
grVersions
[
gv
]
=
version
.
Version
grA
pi
Resources
[
gv
]
=
apiResource
grA
PI
Resources
[
gv
]
=
apiResource
}
}
}
// group selected APIResources according to GroupVersion into APIResourceLists
for
groupResource
,
apiResource
:=
range
grA
pi
Resources
{
for
groupResource
,
apiResource
:=
range
grA
PI
Resources
{
version
:=
grVersions
[
groupResource
]
groupVersion
:=
schema
.
GroupVersion
{
Group
:
groupResource
.
Group
,
Version
:
version
}
apiResourceList
:=
gvA
pi
ResourceLists
[
groupVersion
]
apiResourceList
:=
gvA
PI
ResourceLists
[
groupVersion
]
apiResourceList
.
APIResources
=
append
(
apiResourceList
.
APIResources
,
*
apiResource
)
}
...
...
@@ -464,9 +464,9 @@ func NewDiscoveryClient(c restclient.Interface) *DiscoveryClient {
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func
(
c
*
DiscoveryClient
)
RESTClient
()
restclient
.
Interface
{
if
c
==
nil
{
func
(
d
*
DiscoveryClient
)
RESTClient
()
restclient
.
Interface
{
if
d
==
nil
{
return
nil
}
return
c
.
restClient
return
d
.
restClient
}
staging/src/k8s.io/client-go/discovery/fake/discovery.go
View file @
5e8e8dcf
...
...
@@ -36,6 +36,8 @@ type FakeDiscovery struct {
FakedServerVersion
*
version
.
Info
}
// ServerResourcesForGroupVersion returns the supported resources for a group
// and version.
func
(
c
*
FakeDiscovery
)
ServerResourcesForGroupVersion
(
groupVersion
string
)
(
*
metav1
.
APIResourceList
,
error
)
{
action
:=
testing
.
ActionImpl
{
Verb
:
"get"
,
...
...
@@ -50,6 +52,7 @@ func (c *FakeDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*me
return
nil
,
fmt
.
Errorf
(
"GroupVersion %q not found"
,
groupVersion
)
}
// ServerResources returns the supported resources for all groups and versions.
func
(
c
*
FakeDiscovery
)
ServerResources
()
([]
*
metav1
.
APIResourceList
,
error
)
{
action
:=
testing
.
ActionImpl
{
Verb
:
"get"
,
...
...
@@ -59,14 +62,20 @@ func (c *FakeDiscovery) ServerResources() ([]*metav1.APIResourceList, error) {
return
c
.
Resources
,
nil
}
// ServerPreferredResources returns the supported resources with the version
// preferred by the server.
func
(
c
*
FakeDiscovery
)
ServerPreferredResources
()
([]
*
metav1
.
APIResourceList
,
error
)
{
return
nil
,
nil
}
// ServerPreferredNamespacedResources returns the supported namespaced resources
// with the version preferred by the server.
func
(
c
*
FakeDiscovery
)
ServerPreferredNamespacedResources
()
([]
*
metav1
.
APIResourceList
,
error
)
{
return
nil
,
nil
}
// ServerGroups returns the supported groups, with information like supported
// versions and the preferred version.
func
(
c
*
FakeDiscovery
)
ServerGroups
()
(
*
metav1
.
APIGroupList
,
error
)
{
action
:=
testing
.
ActionImpl
{
Verb
:
"get"
,
...
...
@@ -108,6 +117,7 @@ func (c *FakeDiscovery) ServerGroups() (*metav1.APIGroupList, error) {
}
// ServerVersion retrieves and parses the server's version.
func
(
c
*
FakeDiscovery
)
ServerVersion
()
(
*
version
.
Info
,
error
)
{
action
:=
testing
.
ActionImpl
{}
action
.
Verb
=
"get"
...
...
@@ -122,10 +132,13 @@ func (c *FakeDiscovery) ServerVersion() (*version.Info, error) {
return
&
versionInfo
,
nil
}
// OpenAPISchema retrieves and parses the swagger API schema the server supports.
func
(
c
*
FakeDiscovery
)
OpenAPISchema
()
(
*
openapi_v2
.
Document
,
error
)
{
return
&
openapi_v2
.
Document
{},
nil
}
// RESTClient returns a RESTClient that is used to communicate with API server
// by this client implementation.
func
(
c
*
FakeDiscovery
)
RESTClient
()
restclient
.
Interface
{
return
nil
}
staging/src/k8s.io/client-go/discovery/helper.go
View file @
5e8e8dcf
...
...
@@ -31,11 +31,11 @@ import (
func
MatchesServerVersion
(
clientVersion
apimachineryversion
.
Info
,
client
DiscoveryInterface
)
error
{
sVer
,
err
:=
client
.
ServerVersion
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"couldn't read version from server: %v
\n
"
,
err
)
return
fmt
.
Errorf
(
"couldn't read version from server: %v"
,
err
)
}
// GitVersion includes GitCommit and GitTreeState, but best to be safe?
if
clientVersion
.
GitVersion
!=
sVer
.
GitVersion
||
clientVersion
.
GitCommit
!=
sVer
.
GitCommit
||
clientVersion
.
GitTreeState
!=
sVer
.
GitTreeState
{
return
fmt
.
Errorf
(
"server version (%#v) differs from client version (%#v)
!
\n
"
,
sVer
,
clientVersion
)
return
fmt
.
Errorf
(
"server version (%#v) differs from client version (%#v)"
,
sVer
,
clientVersion
)
}
return
nil
...
...
@@ -101,12 +101,15 @@ func FilteredBy(pred ResourcePredicate, rls []*metav1.APIResourceList) []*metav1
return
result
}
// ResourcePredicate has a method to check if a resource matches a given condition.
type
ResourcePredicate
interface
{
Match
(
groupVersion
string
,
r
*
metav1
.
APIResource
)
bool
}
// ResourcePredicateFunc returns true if it matches a resource based on a custom condition.
type
ResourcePredicateFunc
func
(
groupVersion
string
,
r
*
metav1
.
APIResource
)
bool
// Match is a wrapper around ResourcePredicateFunc.
func
(
fn
ResourcePredicateFunc
)
Match
(
groupVersion
string
,
r
*
metav1
.
APIResource
)
bool
{
return
fn
(
groupVersion
,
r
)
}
...
...
@@ -116,6 +119,7 @@ type SupportsAllVerbs struct {
Verbs
[]
string
}
// Match checks if a resource contains all the given verbs.
func
(
p
SupportsAllVerbs
)
Match
(
groupVersion
string
,
r
*
metav1
.
APIResource
)
bool
{
return
sets
.
NewString
([]
string
(
r
.
Verbs
)
...
)
.
HasAll
(
p
.
Verbs
...
)
}
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