mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 23:03:40 +00:00
Update metrics API to include autoscaling/v2beta2 changes
This commit is contained in:
parent
c7102ee5dc
commit
e31eff092f
4
staging/src/k8s.io/metrics/Godeps/Godeps.json
generated
4
staging/src/k8s.io/metrics/Godeps/Godeps.json
generated
@ -194,6 +194,10 @@
|
||||
"ImportPath": "k8s.io/api/autoscaling/v2beta1",
|
||||
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/autoscaling/v2beta2",
|
||||
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/batch/v1",
|
||||
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
@ -37,6 +37,7 @@ filegroup(
|
||||
":package-srcs",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/install:all-srcs",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta1:all-srcs",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta2:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
@ -1,20 +1,17 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["install.go"],
|
||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/metrics/pkg/apis/custom_metrics/install",
|
||||
importpath = "k8s.io/metrics/pkg/apis/custom_metrics/install",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta2:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@ -29,4 +26,5 @@ filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
@ -23,11 +23,13 @@ import (
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
|
||||
)
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(scheme *runtime.Scheme) {
|
||||
utilruntime.Must(custom_metrics.AddToScheme(scheme))
|
||||
utilruntime.Must(v1beta2.AddToScheme(scheme))
|
||||
utilruntime.Must(v1beta1.AddToScheme(scheme))
|
||||
utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion))
|
||||
utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion, v1beta2.SchemeGroupVersion))
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ load(
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"conversion.go",
|
||||
"doc.go",
|
||||
"generated.pb.go",
|
||||
"register.go",
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright 2018 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 v1beta1
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
)
|
||||
|
||||
func addConversionFuncs(scheme *runtime.Scheme) error {
|
||||
// Add non-generated conversion functions
|
||||
err := scheme.AddConversionFuncs(
|
||||
Convert_v1beta1_MetricValue_To_custom_metrics_MetricValue,
|
||||
Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_v1beta1_MetricValue_To_custom_metrics_MetricValue(in *MetricValue, out *custom_metrics.MetricValue, s conversion.Scope) error {
|
||||
out.Metric.Name = in.MetricName
|
||||
out.Metric.Selector = in.Selector
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in *custom_metrics.MetricValue, out *MetricValue, s conversion.Scope) error {
|
||||
out.MetricName = in.Metric.Name
|
||||
out.Selector = in.Metric.Selector
|
||||
return nil
|
||||
}
|
@ -34,7 +34,7 @@ func Resource(resource string) schema.GroupResource {
|
||||
}
|
||||
|
||||
var (
|
||||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
|
||||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes, addConversionFuncs)
|
||||
localSchemeBuilder = &SchemeBuilder
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
|
@ -63,30 +63,35 @@ func autoConvert_v1beta1_MetricValue_To_custom_metrics_MetricValue(in *MetricVal
|
||||
if err := s.Convert(&in.DescribedObject, &out.DescribedObject, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
out.MetricName = in.MetricName
|
||||
// WARNING: in.MetricName requires manual conversion: does not exist in peer-type
|
||||
out.Timestamp = in.Timestamp
|
||||
out.WindowSeconds = (*int64)(unsafe.Pointer(in.WindowSeconds))
|
||||
out.Value = in.Value
|
||||
return nil
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Convert_v1beta1_MetricValue_To_custom_metrics_MetricValue is an autogenerated conversion function.
|
||||
func Convert_v1beta1_MetricValue_To_custom_metrics_MetricValue(in *MetricValue, out *custommetrics.MetricValue, s conversion.Scope) error {
|
||||
return autoConvert_v1beta1_MetricValue_To_custom_metrics_MetricValue(in, out, s)
|
||||
}
|
||||
|
||||
func autoConvert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in *custommetrics.MetricValue, out *MetricValue, s conversion.Scope) error {
|
||||
=======
|
||||
func autoConvert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in *custom_metrics.MetricValue, out *MetricValue, s conversion.Scope) error {
|
||||
>>>>>>> Update metrics API to include autoscaling/v2beta2 changes
|
||||
// TODO: Inefficient conversion - can we improve it?
|
||||
if err := s.Convert(&in.DescribedObject, &out.DescribedObject, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
out.MetricName = in.MetricName
|
||||
// WARNING: in.Metric requires manual conversion: does not exist in peer-type
|
||||
out.Timestamp = in.Timestamp
|
||||
out.WindowSeconds = (*int64)(unsafe.Pointer(in.WindowSeconds))
|
||||
out.Value = in.Value
|
||||
return nil
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue is an autogenerated conversion function.
|
||||
func Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in *custommetrics.MetricValue, out *MetricValue, s conversion.Scope) error {
|
||||
return autoConvert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in, out, s)
|
||||
@ -95,6 +100,21 @@ func Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in *custommetrics
|
||||
func autoConvert_v1beta1_MetricValueList_To_custom_metrics_MetricValueList(in *MetricValueList, out *custommetrics.MetricValueList, s conversion.Scope) error {
|
||||
out.ListMeta = in.ListMeta
|
||||
out.Items = *(*[]custommetrics.MetricValue)(unsafe.Pointer(&in.Items))
|
||||
=======
|
||||
func autoConvert_v1beta1_MetricValueList_To_custom_metrics_MetricValueList(in *MetricValueList, out *custom_metrics.MetricValueList, s conversion.Scope) error {
|
||||
out.ListMeta = in.ListMeta
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]custom_metrics.MetricValue, len(*in))
|
||||
for i := range *in {
|
||||
if err := Convert_v1beta1_MetricValue_To_custom_metrics_MetricValue(&(*in)[i], &(*out)[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Items = nil
|
||||
}
|
||||
>>>>>>> Update metrics API to include autoscaling/v2beta2 changes
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -105,7 +125,17 @@ func Convert_v1beta1_MetricValueList_To_custom_metrics_MetricValueList(in *Metri
|
||||
|
||||
func autoConvert_custom_metrics_MetricValueList_To_v1beta1_MetricValueList(in *custommetrics.MetricValueList, out *MetricValueList, s conversion.Scope) error {
|
||||
out.ListMeta = in.ListMeta
|
||||
out.Items = *(*[]MetricValue)(unsafe.Pointer(&in.Items))
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]MetricValue, len(*in))
|
||||
for i := range *in {
|
||||
if err := Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue(&(*in)[i], &(*out)[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Items = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,28 @@ import (
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *MetricIdent) DeepCopyInto(out *MetricIdent) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricIdent.
|
||||
func (in *MetricIdent) DeepCopy() *MetricIdent {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(MetricIdent)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *MetricValue) DeepCopyInto(out *MetricValue) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
out.DescribedObject = in.DescribedObject
|
||||
out.Metric = in.Metric
|
||||
in.Timestamp.DeepCopyInto(&out.Timestamp)
|
||||
if in.WindowSeconds != nil {
|
||||
in, out := &in.WindowSeconds, &out.WindowSeconds
|
||||
|
@ -1,9 +1,4 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@ -13,16 +8,16 @@ go_library(
|
||||
],
|
||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/metrics/pkg/client/custom_metrics",
|
||||
importpath = "k8s.io/metrics/pkg/client/custom_metrics",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta2:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics/scheme:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@ -38,6 +33,8 @@ filegroup(
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics/fake:all-srcs",
|
||||
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics/scheme:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
@ -20,14 +20,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/util/flowcontrol"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
|
||||
"k8s.io/metrics/pkg/client/custom_metrics/scheme"
|
||||
)
|
||||
|
||||
type customMetricsClient struct {
|
||||
@ -50,7 +49,7 @@ func NewForConfig(c *rest.Config) (CustomMetricsClient, error) {
|
||||
if configShallowCopy.UserAgent == "" {
|
||||
configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent()
|
||||
}
|
||||
configShallowCopy.GroupVersion = &v1beta1.SchemeGroupVersion
|
||||
configShallowCopy.GroupVersion = &v1beta2.SchemeGroupVersion
|
||||
configShallowCopy.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
|
||||
|
||||
client, err := rest.RESTClientFor(&configShallowCopy)
|
||||
@ -112,12 +111,15 @@ type rootScopedMetrics struct {
|
||||
client *customMetricsClient
|
||||
}
|
||||
|
||||
func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string) (*v1beta1.MetricValue, error) {
|
||||
res := &v1beta1.MetricValueList{}
|
||||
func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
|
||||
res := &v1beta2.MetricValueList{}
|
||||
err := m.client.client.Get().
|
||||
Resource("metrics").
|
||||
Namespace(namespace).
|
||||
Name(metricName).
|
||||
VersionedParams(&v1beta2.MetricListOptions{
|
||||
MetricLabelSelector: metricSelector.String(),
|
||||
}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Into(res)
|
||||
|
||||
@ -132,10 +134,10 @@ func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string)
|
||||
return &res.Items[0], nil
|
||||
}
|
||||
|
||||
func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string) (*v1beta1.MetricValue, error) {
|
||||
func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
|
||||
// handle namespace separately
|
||||
if groupKind.Kind == "Namespace" && groupKind.Group == "" {
|
||||
return m.getForNamespace(name, metricName)
|
||||
return m.getForNamespace(name, metricName, metricSelector)
|
||||
}
|
||||
|
||||
resourceName, err := m.client.qualResourceForKind(groupKind)
|
||||
@ -143,11 +145,14 @@ func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := &v1beta1.MetricValueList{}
|
||||
res := &v1beta2.MetricValueList{}
|
||||
err = m.client.client.Get().
|
||||
Resource(resourceName).
|
||||
Name(name).
|
||||
SubResource(metricName).
|
||||
VersionedParams(&v1beta2.MetricListOptions{
|
||||
MetricLabelSelector: metricSelector.String(),
|
||||
}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Into(res)
|
||||
|
||||
@ -162,7 +167,7 @@ func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string
|
||||
return &res.Items[0], nil
|
||||
}
|
||||
|
||||
func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string) (*v1beta1.MetricValueList, error) {
|
||||
func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) {
|
||||
// we can't wildcard-fetch for namespaces
|
||||
if groupKind.Kind == "Namespace" && groupKind.Group == "" {
|
||||
return nil, fmt.Errorf("cannot fetch metrics for multiple namespaces at once")
|
||||
@ -173,14 +178,15 @@ func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := &v1beta1.MetricValueList{}
|
||||
res := &v1beta2.MetricValueList{}
|
||||
err = m.client.client.Get().
|
||||
Resource(resourceName).
|
||||
Name(v1beta1.AllObjects).
|
||||
Name(v1beta2.AllObjects).
|
||||
SubResource(metricName).
|
||||
VersionedParams(&metav1.ListOptions{
|
||||
LabelSelector: selector.String(),
|
||||
}, metav1.ParameterCodec).
|
||||
VersionedParams(&v1beta2.MetricListOptions{
|
||||
LabelSelector: selector.String(),
|
||||
MetricLabelSelector: metricSelector.String(),
|
||||
}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Into(res)
|
||||
|
||||
@ -196,18 +202,21 @@ type namespacedMetrics struct {
|
||||
namespace string
|
||||
}
|
||||
|
||||
func (m *namespacedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string) (*v1beta1.MetricValue, error) {
|
||||
func (m *namespacedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
|
||||
resourceName, err := m.client.qualResourceForKind(groupKind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := &v1beta1.MetricValueList{}
|
||||
res := &v1beta2.MetricValueList{}
|
||||
err = m.client.client.Get().
|
||||
Resource(resourceName).
|
||||
Namespace(m.namespace).
|
||||
Name(name).
|
||||
SubResource(metricName).
|
||||
VersionedParams(&v1beta2.MetricListOptions{
|
||||
MetricLabelSelector: metricSelector.String(),
|
||||
}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Into(res)
|
||||
|
||||
@ -222,21 +231,22 @@ func (m *namespacedMetrics) GetForObject(groupKind schema.GroupKind, name string
|
||||
return &res.Items[0], nil
|
||||
}
|
||||
|
||||
func (m *namespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string) (*v1beta1.MetricValueList, error) {
|
||||
func (m *namespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) {
|
||||
resourceName, err := m.client.qualResourceForKind(groupKind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := &v1beta1.MetricValueList{}
|
||||
res := &v1beta2.MetricValueList{}
|
||||
err = m.client.client.Get().
|
||||
Resource(resourceName).
|
||||
Namespace(m.namespace).
|
||||
Name(v1beta1.AllObjects).
|
||||
Name(v1beta2.AllObjects).
|
||||
SubResource(metricName).
|
||||
VersionedParams(&metav1.ListOptions{
|
||||
LabelSelector: selector.String(),
|
||||
}, metav1.ParameterCodec).
|
||||
VersionedParams(&v1beta2.MetricListOptions{
|
||||
LabelSelector: selector.String(),
|
||||
MetricLabelSelector: metricSelector.String(),
|
||||
}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Into(res)
|
||||
|
||||
|
@ -1,21 +1,17 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["fake_client.go"],
|
||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/metrics/pkg/client/custom_metrics/fake",
|
||||
importpath = "k8s.io/metrics/pkg/client/custom_metrics/fake",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/testing:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/apis/custom_metrics/v1beta2:go_default_library",
|
||||
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics:go_default_library",
|
||||
],
|
||||
)
|
||||
@ -31,4 +27,5 @@ filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/testing"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
|
||||
cmclient "k8s.io/metrics/pkg/client/custom_metrics"
|
||||
)
|
||||
|
||||
@ -72,7 +72,7 @@ func NewGetForAction(groupKind schema.GroupKind, namespace, name string, metricN
|
||||
Resource: gvr.Resource,
|
||||
}
|
||||
resource := schema.GroupResource{
|
||||
Group: v1beta1.SchemeGroupVersion.Group,
|
||||
Group: v1beta2.SchemeGroupVersion.Group,
|
||||
Resource: groupResourceForKind.String(),
|
||||
}
|
||||
return GetForActionImpl{
|
||||
@ -91,7 +91,7 @@ func NewRootGetForAction(groupKind schema.GroupKind, name string, metricName str
|
||||
Resource: gvr.Resource,
|
||||
}
|
||||
resource := schema.GroupResource{
|
||||
Group: v1beta1.SchemeGroupVersion.Group,
|
||||
Group: v1beta2.SchemeGroupVersion.Group,
|
||||
Resource: groupResourceForKind.String(),
|
||||
}
|
||||
return GetForActionImpl{
|
||||
@ -123,15 +123,15 @@ type fakeNamespacedMetrics struct {
|
||||
ns string
|
||||
}
|
||||
|
||||
func (m *fakeNamespacedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string) (*v1beta1.MetricValue, error) {
|
||||
func (m *fakeNamespacedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
|
||||
obj, err := m.Fake.
|
||||
Invokes(NewGetForAction(groupKind, m.ns, name, metricName, nil), &v1beta1.MetricValueList{})
|
||||
Invokes(NewGetForAction(groupKind, m.ns, name, metricName, nil), &v1beta2.MetricValueList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
objList := obj.(*v1beta1.MetricValueList)
|
||||
objList := obj.(*v1beta2.MetricValueList)
|
||||
if len(objList.Items) != 1 {
|
||||
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(objList.Items))
|
||||
}
|
||||
@ -139,30 +139,30 @@ func (m *fakeNamespacedMetrics) GetForObject(groupKind schema.GroupKind, name st
|
||||
return &objList.Items[0], err
|
||||
}
|
||||
|
||||
func (m *fakeNamespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string) (*v1beta1.MetricValueList, error) {
|
||||
func (m *fakeNamespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) {
|
||||
obj, err := m.Fake.
|
||||
Invokes(NewGetForAction(groupKind, m.ns, "*", metricName, selector), &v1beta1.MetricValueList{})
|
||||
Invokes(NewGetForAction(groupKind, m.ns, "*", metricName, selector), &v1beta2.MetricValueList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.(*v1beta1.MetricValueList), err
|
||||
return obj.(*v1beta2.MetricValueList), err
|
||||
}
|
||||
|
||||
type fakeRootScopedMetrics struct {
|
||||
Fake *FakeCustomMetricsClient
|
||||
}
|
||||
|
||||
func (m *fakeRootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string) (*v1beta1.MetricValue, error) {
|
||||
func (m *fakeRootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
|
||||
obj, err := m.Fake.
|
||||
Invokes(NewRootGetForAction(groupKind, name, metricName, nil), &v1beta1.MetricValueList{})
|
||||
Invokes(NewRootGetForAction(groupKind, name, metricName, nil), &v1beta2.MetricValueList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
objList := obj.(*v1beta1.MetricValueList)
|
||||
objList := obj.(*v1beta2.MetricValueList)
|
||||
if len(objList.Items) != 1 {
|
||||
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(objList.Items))
|
||||
}
|
||||
@ -170,13 +170,13 @@ func (m *fakeRootScopedMetrics) GetForObject(groupKind schema.GroupKind, name st
|
||||
return &objList.Items[0], err
|
||||
}
|
||||
|
||||
func (m *fakeRootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string) (*v1beta1.MetricValueList, error) {
|
||||
func (m *fakeRootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) {
|
||||
obj, err := m.Fake.
|
||||
Invokes(NewRootGetForAction(groupKind, "*", metricName, selector), &v1beta1.MetricValueList{})
|
||||
Invokes(NewRootGetForAction(groupKind, "*", metricName, selector), &v1beta2.MetricValueList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.(*v1beta1.MetricValueList), err
|
||||
return obj.(*v1beta2.MetricValueList), err
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package custom_metrics
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
|
||||
)
|
||||
|
||||
// CustomMetricsClient is a client for fetching metrics
|
||||
@ -45,10 +45,10 @@ type NamespacedMetricsGetter interface {
|
||||
// MetricsInterface provides access to metrics describing Kubernetes objects.
|
||||
type MetricsInterface interface {
|
||||
// GetForObject fetchs the given metric describing the given object.
|
||||
GetForObject(groupKind schema.GroupKind, name string, metricName string) (*v1beta1.MetricValue, error)
|
||||
GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error)
|
||||
|
||||
// GetForObjects fetches the given metric describing all objects of the given
|
||||
// type matching the given label selector (or simply all objects of the given type
|
||||
// if the selector is nil).
|
||||
GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string) (*v1beta1.MetricValueList, error)
|
||||
GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ type NamespacedMetricsGetter interface {
|
||||
|
||||
// MetricsInterface provides access to external metrics.
|
||||
type MetricsInterface interface {
|
||||
// Get fetches the metric for the given namespace that maches the given
|
||||
// List fetches the metric for the given namespace that maches the given
|
||||
// metricSelector.
|
||||
List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user