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
0b3eb50b
Commit
0b3eb50b
authored
May 04, 2017
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove invocation of registry from custom_metrics/client.go
parent
b5a41e77
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
client.go
...ng/src/k8s.io/metrics/pkg/client/custom_metrics/client.go
+16
-4
No files found.
staging/src/k8s.io/metrics/pkg/client/custom_metrics/client.go
View file @
0b3eb50b
...
@@ -23,7 +23,7 @@ import (
...
@@ -23,7 +23,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
serializer
"k8s.io/apimachinery/pkg/runtime/serializer"
serializer
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/
pkg/api
"
"k8s.io/client-go/
kubernetes/scheme
"
"k8s.io/client-go/rest"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/metrics/pkg/apis/custom_metrics/v1alpha1"
"k8s.io/metrics/pkg/apis/custom_metrics/v1alpha1"
...
@@ -35,7 +35,9 @@ type customMetricsClient struct {
...
@@ -35,7 +35,9 @@ type customMetricsClient struct {
}
}
func
New
(
client
rest
.
Interface
)
CustomMetricsClient
{
func
New
(
client
rest
.
Interface
)
CustomMetricsClient
{
return
NewForMapper
(
client
,
api
.
Registry
.
RESTMapper
())
return
&
customMetricsClient
{
client
:
client
,
}
}
}
func
NewForConfig
(
c
*
rest
.
Config
)
(
CustomMetricsClient
,
error
)
{
func
NewForConfig
(
c
*
rest
.
Config
)
(
CustomMetricsClient
,
error
)
{
...
@@ -48,7 +50,7 @@ func NewForConfig(c *rest.Config) (CustomMetricsClient, error) {
...
@@ -48,7 +50,7 @@ func NewForConfig(c *rest.Config) (CustomMetricsClient, error) {
configShallowCopy
.
UserAgent
=
rest
.
DefaultKubernetesUserAgent
()
configShallowCopy
.
UserAgent
=
rest
.
DefaultKubernetesUserAgent
()
}
}
configShallowCopy
.
GroupVersion
=
&
v1alpha1
.
SchemeGroupVersion
configShallowCopy
.
GroupVersion
=
&
v1alpha1
.
SchemeGroupVersion
configShallowCopy
.
NegotiatedSerializer
=
serializer
.
DirectCodecFactory
{
CodecFactory
:
api
.
Codecs
}
configShallowCopy
.
NegotiatedSerializer
=
serializer
.
DirectCodecFactory
{
CodecFactory
:
scheme
.
Codecs
}
client
,
err
:=
rest
.
RESTClientFor
(
&
configShallowCopy
)
client
,
err
:=
rest
.
RESTClientFor
(
&
configShallowCopy
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -66,6 +68,8 @@ func NewForConfigOrDie(c *rest.Config) CustomMetricsClient {
...
@@ -66,6 +68,8 @@ func NewForConfigOrDie(c *rest.Config) CustomMetricsClient {
return
client
return
client
}
}
// NewForMapper constucts the client with a RESTMapper, which allows more
// accurate translation from GroupVersionKind to GroupVersionResource.
func
NewForMapper
(
client
rest
.
Interface
,
mapper
meta
.
RESTMapper
)
CustomMetricsClient
{
func
NewForMapper
(
client
rest
.
Interface
,
mapper
meta
.
RESTMapper
)
CustomMetricsClient
{
return
&
customMetricsClient
{
return
&
customMetricsClient
{
client
:
client
,
client
:
client
,
...
@@ -85,6 +89,15 @@ func (c *customMetricsClient) NamespacedMetrics(namespace string) MetricsInterfa
...
@@ -85,6 +89,15 @@ func (c *customMetricsClient) NamespacedMetrics(namespace string) MetricsInterfa
}
}
func
(
c
*
customMetricsClient
)
qualResourceForKind
(
groupKind
schema
.
GroupKind
)
(
string
,
error
)
{
func
(
c
*
customMetricsClient
)
qualResourceForKind
(
groupKind
schema
.
GroupKind
)
(
string
,
error
)
{
if
c
.
mapper
==
nil
{
// the version doesn't matter
gvk
:=
groupKind
.
WithVersion
(
""
)
gvr
,
_
:=
meta
.
UnsafeGuessKindToResource
(
gvk
)
gr
:=
gvr
.
GroupResource
()
return
gr
.
String
(),
nil
}
// use the mapper if it's available
mapping
,
err
:=
c
.
mapper
.
RESTMapping
(
groupKind
)
mapping
,
err
:=
c
.
mapper
.
RESTMapping
(
groupKind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"unable to map kind %s to resource: %v"
,
groupKind
.
String
(),
err
)
return
""
,
fmt
.
Errorf
(
"unable to map kind %s to resource: %v"
,
groupKind
.
String
(),
err
)
...
@@ -94,7 +107,6 @@ func (c *customMetricsClient) qualResourceForKind(groupKind schema.GroupKind) (s
...
@@ -94,7 +107,6 @@ func (c *customMetricsClient) qualResourceForKind(groupKind schema.GroupKind) (s
Group
:
mapping
.
GroupVersionKind
.
Group
,
Group
:
mapping
.
GroupVersionKind
.
Group
,
Resource
:
mapping
.
Resource
,
Resource
:
mapping
.
Resource
,
}
}
return
groupResource
.
String
(),
nil
return
groupResource
.
String
(),
nil
}
}
...
...
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