add vendor

Signed-off-by: Poor12 <shentiecheng@huawei.com>
This commit is contained in:
Poor12 2023-05-29 15:05:49 +08:00
parent 1e7ab937eb
commit 314b46ddd3
23 changed files with 3824 additions and 0 deletions

24
vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/doc.go generated vendored Normal file
View File

@ -0,0 +1,24 @@
/*
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.
*/
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=package
// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics
// +k8s:openapi-gen=true
// +groupName=metrics.k8s.io
// Package v1alpha1 is the v1alpha1 version of the metrics API.
package v1alpha1 // import "k8s.io/metrics/pkg/apis/metrics/v1alpha1"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,95 @@
/*
Copyright 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.
*/
// This file was autogenerated by go-to-protobuf. Do not edit it manually!
syntax = "proto2";
package k8s.io.metrics.pkg.apis.metrics.v1alpha1;
import "k8s.io/api/core/v1/generated.proto";
import "k8s.io/apimachinery/pkg/api/resource/generated.proto";
import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto";
// Package-wide variables from generator "generated".
option go_package = "k8s.io/metrics/pkg/apis/metrics/v1alpha1";
// ContainerMetrics sets resource usage metrics of a container.
message ContainerMetrics {
// Container name corresponding to the one from pod.spec.containers.
optional string name = 1;
// The memory usage is the memory working set.
map<string, k8s.io.apimachinery.pkg.api.resource.Quantity> usage = 2;
}
// NodeMetrics sets resource usage metrics of a node.
message NodeMetrics {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
// The following fields define time interval from which metrics were
// collected from the interval [Timestamp-Window, Timestamp].
optional k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2;
optional k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3;
// The memory usage is the memory working set.
map<string, k8s.io.apimachinery.pkg.api.resource.Quantity> usage = 4;
}
// NodeMetricsList is a list of NodeMetrics.
message NodeMetricsList {
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
// List of node metrics.
repeated NodeMetrics items = 2;
}
// PodMetrics sets resource usage metrics of a pod.
message PodMetrics {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
// The following fields define time interval from which metrics were
// collected from the interval [Timestamp-Window, Timestamp].
optional k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2;
optional k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3;
// Metrics for all containers are collected within the same time window.
repeated ContainerMetrics containers = 4;
}
// PodMetricsList is a list of PodMetrics.
message PodMetricsList {
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
// List of pod metrics.
repeated PodMetrics items = 2;
}

View File

@ -0,0 +1,53 @@
/*
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 v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name use in this package
const GroupName = "metrics.k8s.io"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
// SchemeBuilder points to a list of functions added to Scheme.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
localSchemeBuilder = &SchemeBuilder
// AddToScheme applies all the stored functions to the scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&NodeMetrics{},
&NodeMetricsList{},
&PodMetrics{},
&PodMetricsList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

View File

@ -0,0 +1,101 @@
/*
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 v1alpha1
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +resourceName=nodes
// +genclient:readonly
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// NodeMetrics sets resource usage metrics of a node.
type NodeMetrics struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// The following fields define time interval from which metrics were
// collected from the interval [Timestamp-Window, Timestamp].
Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"`
Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"`
// The memory usage is the memory working set.
Usage v1.ResourceList `json:"usage" protobuf:"bytes,4,rep,name=usage,casttype=k8s.io/api/core/v1.ResourceList,castkey=k8s.io/api/core/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// NodeMetricsList is a list of NodeMetrics.
type NodeMetricsList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of node metrics.
Items []NodeMetrics `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// +genclient
// +resourceName=pods
// +genclient:readonly
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PodMetrics sets resource usage metrics of a pod.
type PodMetrics struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// The following fields define time interval from which metrics were
// collected from the interval [Timestamp-Window, Timestamp].
Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"`
Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"`
// Metrics for all containers are collected within the same time window.
Containers []ContainerMetrics `json:"containers" protobuf:"bytes,4,rep,name=containers"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PodMetricsList is a list of PodMetrics.
type PodMetricsList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of pod metrics.
Items []PodMetrics `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// ContainerMetrics sets resource usage metrics of a container.
type ContainerMetrics struct {
// Container name corresponding to the one from pod.spec.containers.
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// The memory usage is the memory working set.
Usage v1.ResourceList `json:"usage" protobuf:"bytes,2,rep,name=usage,casttype=k8s.io/api/core/v1.ResourceList,castkey=k8s.io/api/core/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"`
}

View File

@ -0,0 +1,209 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
Copyright 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.
*/
// Code generated by conversion-gen. DO NOT EDIT.
package v1alpha1
import (
unsafe "unsafe"
v1 "k8s.io/api/core/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
metrics "k8s.io/metrics/pkg/apis/metrics"
)
func init() {
localSchemeBuilder.Register(RegisterConversions)
}
// RegisterConversions adds conversion functions to the given scheme.
// Public to allow building arbitrary schemes.
func RegisterConversions(s *runtime.Scheme) error {
if err := s.AddGeneratedConversionFunc((*ContainerMetrics)(nil), (*metrics.ContainerMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(a.(*ContainerMetrics), b.(*metrics.ContainerMetrics), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*metrics.ContainerMetrics)(nil), (*ContainerMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(a.(*metrics.ContainerMetrics), b.(*ContainerMetrics), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*NodeMetrics)(nil), (*metrics.NodeMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(a.(*NodeMetrics), b.(*metrics.NodeMetrics), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*metrics.NodeMetrics)(nil), (*NodeMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(a.(*metrics.NodeMetrics), b.(*NodeMetrics), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*NodeMetricsList)(nil), (*metrics.NodeMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(a.(*NodeMetricsList), b.(*metrics.NodeMetricsList), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*metrics.NodeMetricsList)(nil), (*NodeMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(a.(*metrics.NodeMetricsList), b.(*NodeMetricsList), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*PodMetrics)(nil), (*metrics.PodMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_PodMetrics_To_metrics_PodMetrics(a.(*PodMetrics), b.(*metrics.PodMetrics), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*metrics.PodMetrics)(nil), (*PodMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_metrics_PodMetrics_To_v1alpha1_PodMetrics(a.(*metrics.PodMetrics), b.(*PodMetrics), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*PodMetricsList)(nil), (*metrics.PodMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(a.(*PodMetricsList), b.(*metrics.PodMetricsList), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*metrics.PodMetricsList)(nil), (*PodMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(a.(*metrics.PodMetricsList), b.(*PodMetricsList), scope)
}); err != nil {
return err
}
return nil
}
func autoConvert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(in *ContainerMetrics, out *metrics.ContainerMetrics, s conversion.Scope) error {
out.Name = in.Name
out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage))
return nil
}
// Convert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics is an autogenerated conversion function.
func Convert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(in *ContainerMetrics, out *metrics.ContainerMetrics, s conversion.Scope) error {
return autoConvert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(in, out, s)
}
func autoConvert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(in *metrics.ContainerMetrics, out *ContainerMetrics, s conversion.Scope) error {
out.Name = in.Name
out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage))
return nil
}
// Convert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics is an autogenerated conversion function.
func Convert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(in *metrics.ContainerMetrics, out *ContainerMetrics, s conversion.Scope) error {
return autoConvert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(in, out, s)
}
func autoConvert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(in *NodeMetrics, out *metrics.NodeMetrics, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Timestamp = in.Timestamp
out.Window = in.Window
out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage))
return nil
}
// Convert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics is an autogenerated conversion function.
func Convert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(in *NodeMetrics, out *metrics.NodeMetrics, s conversion.Scope) error {
return autoConvert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(in, out, s)
}
func autoConvert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(in *metrics.NodeMetrics, out *NodeMetrics, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Timestamp = in.Timestamp
out.Window = in.Window
out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage))
return nil
}
// Convert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics is an autogenerated conversion function.
func Convert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(in *metrics.NodeMetrics, out *NodeMetrics, s conversion.Scope) error {
return autoConvert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(in, out, s)
}
func autoConvert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(in *NodeMetricsList, out *metrics.NodeMetricsList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]metrics.NodeMetrics)(unsafe.Pointer(&in.Items))
return nil
}
// Convert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList is an autogenerated conversion function.
func Convert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(in *NodeMetricsList, out *metrics.NodeMetricsList, s conversion.Scope) error {
return autoConvert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(in, out, s)
}
func autoConvert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(in *metrics.NodeMetricsList, out *NodeMetricsList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]NodeMetrics)(unsafe.Pointer(&in.Items))
return nil
}
// Convert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList is an autogenerated conversion function.
func Convert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(in *metrics.NodeMetricsList, out *NodeMetricsList, s conversion.Scope) error {
return autoConvert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(in, out, s)
}
func autoConvert_v1alpha1_PodMetrics_To_metrics_PodMetrics(in *PodMetrics, out *metrics.PodMetrics, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Timestamp = in.Timestamp
out.Window = in.Window
out.Containers = *(*[]metrics.ContainerMetrics)(unsafe.Pointer(&in.Containers))
return nil
}
// Convert_v1alpha1_PodMetrics_To_metrics_PodMetrics is an autogenerated conversion function.
func Convert_v1alpha1_PodMetrics_To_metrics_PodMetrics(in *PodMetrics, out *metrics.PodMetrics, s conversion.Scope) error {
return autoConvert_v1alpha1_PodMetrics_To_metrics_PodMetrics(in, out, s)
}
func autoConvert_metrics_PodMetrics_To_v1alpha1_PodMetrics(in *metrics.PodMetrics, out *PodMetrics, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Timestamp = in.Timestamp
out.Window = in.Window
out.Containers = *(*[]ContainerMetrics)(unsafe.Pointer(&in.Containers))
return nil
}
// Convert_metrics_PodMetrics_To_v1alpha1_PodMetrics is an autogenerated conversion function.
func Convert_metrics_PodMetrics_To_v1alpha1_PodMetrics(in *metrics.PodMetrics, out *PodMetrics, s conversion.Scope) error {
return autoConvert_metrics_PodMetrics_To_v1alpha1_PodMetrics(in, out, s)
}
func autoConvert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(in *PodMetricsList, out *metrics.PodMetricsList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]metrics.PodMetrics)(unsafe.Pointer(&in.Items))
return nil
}
// Convert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList is an autogenerated conversion function.
func Convert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(in *PodMetricsList, out *metrics.PodMetricsList, s conversion.Scope) error {
return autoConvert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(in, out, s)
}
func autoConvert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(in *metrics.PodMetricsList, out *PodMetricsList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]PodMetrics)(unsafe.Pointer(&in.Items))
return nil
}
// Convert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList is an autogenerated conversion function.
func Convert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(in *metrics.PodMetricsList, out *PodMetricsList, s conversion.Scope) error {
return autoConvert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(in, out, s)
}

View File

@ -0,0 +1,186 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
Copyright 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.
*/
// Code generated by deepcopy-gen. DO NOT EDIT.
package v1alpha1
import (
v1 "k8s.io/api/core/v1"
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 *ContainerMetrics) DeepCopyInto(out *ContainerMetrics) {
*out = *in
if in.Usage != nil {
in, out := &in.Usage, &out.Usage
*out = make(v1.ResourceList, len(*in))
for key, val := range *in {
(*out)[key] = val.DeepCopy()
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerMetrics.
func (in *ContainerMetrics) DeepCopy() *ContainerMetrics {
if in == nil {
return nil
}
out := new(ContainerMetrics)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetrics) DeepCopyInto(out *NodeMetrics) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Timestamp.DeepCopyInto(&out.Timestamp)
out.Window = in.Window
if in.Usage != nil {
in, out := &in.Usage, &out.Usage
*out = make(v1.ResourceList, len(*in))
for key, val := range *in {
(*out)[key] = val.DeepCopy()
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetrics.
func (in *NodeMetrics) DeepCopy() *NodeMetrics {
if in == nil {
return nil
}
out := new(NodeMetrics)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *NodeMetrics) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetricsList) DeepCopyInto(out *NodeMetricsList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]NodeMetrics, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricsList.
func (in *NodeMetricsList) DeepCopy() *NodeMetricsList {
if in == nil {
return nil
}
out := new(NodeMetricsList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *NodeMetricsList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodMetrics) DeepCopyInto(out *PodMetrics) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Timestamp.DeepCopyInto(&out.Timestamp)
out.Window = in.Window
if in.Containers != nil {
in, out := &in.Containers, &out.Containers
*out = make([]ContainerMetrics, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetrics.
func (in *PodMetrics) DeepCopy() *PodMetrics {
if in == nil {
return nil
}
out := new(PodMetrics)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *PodMetrics) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodMetricsList) DeepCopyInto(out *PodMetricsList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]PodMetrics, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricsList.
func (in *PodMetricsList) DeepCopy() *PodMetricsList {
if in == nil {
return nil
}
out := new(PodMetricsList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *PodMetricsList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

View File

@ -0,0 +1,20 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// This package contains the scheme of the automatically generated clientset.
package scheme

View File

@ -0,0 +1,58 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package scheme
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1"
metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
)
var Scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(Scheme)
var ParameterCodec = runtime.NewParameterCodec(Scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
metricsv1alpha1.AddToScheme,
metricsv1beta1.AddToScheme,
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
var AddToScheme = localSchemeBuilder.AddToScheme
func init() {
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
utilruntime.Must(AddToScheme(Scheme))
}

View File

@ -0,0 +1,20 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// This package has the automatically generated typed clients.
package v1beta1

View File

@ -0,0 +1,23 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1beta1
type NodeMetricsExpansion interface{}
type PodMetricsExpansion interface{}

View File

@ -0,0 +1,112 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1beta1
import (
"net/http"
rest "k8s.io/client-go/rest"
v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
"k8s.io/metrics/pkg/client/clientset/versioned/scheme"
)
type MetricsV1beta1Interface interface {
RESTClient() rest.Interface
NodeMetricsesGetter
PodMetricsesGetter
}
// MetricsV1beta1Client is used to interact with features provided by the metrics.k8s.io group.
type MetricsV1beta1Client struct {
restClient rest.Interface
}
func (c *MetricsV1beta1Client) NodeMetricses() NodeMetricsInterface {
return newNodeMetricses(c)
}
func (c *MetricsV1beta1Client) PodMetricses(namespace string) PodMetricsInterface {
return newPodMetricses(c, namespace)
}
// NewForConfig creates a new MetricsV1beta1Client for the given config.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *rest.Config) (*MetricsV1beta1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
httpClient, err := rest.HTTPClientFor(&config)
if err != nil {
return nil, err
}
return NewForConfigAndClient(&config, httpClient)
}
// NewForConfigAndClient creates a new MetricsV1beta1Client for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(c *rest.Config, h *http.Client) (*MetricsV1beta1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientForConfigAndClient(&config, h)
if err != nil {
return nil, err
}
return &MetricsV1beta1Client{client}, nil
}
// NewForConfigOrDie creates a new MetricsV1beta1Client for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *MetricsV1beta1Client {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}
// New creates a new MetricsV1beta1Client for the given RESTClient.
func New(c rest.Interface) *MetricsV1beta1Client {
return &MetricsV1beta1Client{c}
}
func setConfigDefaults(config *rest.Config) error {
gv := v1beta1.SchemeGroupVersion
config.GroupVersion = &gv
config.APIPath = "/apis"
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
if config.UserAgent == "" {
config.UserAgent = rest.DefaultKubernetesUserAgent()
}
return nil
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *MetricsV1beta1Client) RESTClient() rest.Interface {
if c == nil {
return nil
}
return c.restClient
}

View File

@ -0,0 +1,98 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1beta1
import (
"context"
"time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme"
)
// NodeMetricsesGetter has a method to return a NodeMetricsInterface.
// A group's client should implement this interface.
type NodeMetricsesGetter interface {
NodeMetricses() NodeMetricsInterface
}
// NodeMetricsInterface has methods to work with NodeMetrics resources.
type NodeMetricsInterface interface {
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.NodeMetrics, error)
List(ctx context.Context, opts v1.ListOptions) (*v1beta1.NodeMetricsList, error)
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
NodeMetricsExpansion
}
// nodeMetricses implements NodeMetricsInterface
type nodeMetricses struct {
client rest.Interface
}
// newNodeMetricses returns a NodeMetricses
func newNodeMetricses(c *MetricsV1beta1Client) *nodeMetricses {
return &nodeMetricses{
client: c.RESTClient(),
}
}
// Get takes name of the nodeMetrics, and returns the corresponding nodeMetrics object, and an error if there is any.
func (c *nodeMetricses) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.NodeMetrics, err error) {
result = &v1beta1.NodeMetrics{}
err = c.client.Get().
Resource("nodes").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of NodeMetricses that match those selectors.
func (c *nodeMetricses) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.NodeMetricsList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1beta1.NodeMetricsList{}
err = c.client.Get().
Resource("nodes").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested nodeMetricses.
func (c *nodeMetricses) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Resource("nodes").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}

View File

@ -0,0 +1,103 @@
/*
Copyright 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1beta1
import (
"context"
"time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme"
)
// PodMetricsesGetter has a method to return a PodMetricsInterface.
// A group's client should implement this interface.
type PodMetricsesGetter interface {
PodMetricses(namespace string) PodMetricsInterface
}
// PodMetricsInterface has methods to work with PodMetrics resources.
type PodMetricsInterface interface {
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.PodMetrics, error)
List(ctx context.Context, opts v1.ListOptions) (*v1beta1.PodMetricsList, error)
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
PodMetricsExpansion
}
// podMetricses implements PodMetricsInterface
type podMetricses struct {
client rest.Interface
ns string
}
// newPodMetricses returns a PodMetricses
func newPodMetricses(c *MetricsV1beta1Client, namespace string) *podMetricses {
return &podMetricses{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the podMetrics, and returns the corresponding podMetrics object, and an error if there is any.
func (c *podMetricses) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.PodMetrics, err error) {
result = &v1beta1.PodMetrics{}
err = c.client.Get().
Namespace(c.ns).
Resource("pods").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of PodMetricses that match those selectors.
func (c *podMetricses) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.PodMetricsList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1beta1.PodMetricsList{}
err = c.client.Get().
Namespace(c.ns).
Resource("pods").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested podMetricses.
func (c *podMetricses) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("pods").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}

View File

@ -0,0 +1,122 @@
/*
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 custom_metrics
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"
cmint "k8s.io/metrics/pkg/apis/custom_metrics"
cmv1beta1 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
cmv1beta2 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
"k8s.io/metrics/pkg/client/custom_metrics/scheme"
)
var (
// MetricVersions is the set of metric versions accepted by the converter.
MetricVersions = []schema.GroupVersion{
cmv1beta2.SchemeGroupVersion,
cmv1beta1.SchemeGroupVersion,
cmint.SchemeGroupVersion,
}
)
// MetricConverter knows how to convert between external MetricValue versions.
type MetricConverter struct {
scheme *runtime.Scheme
codecs serializer.CodecFactory
internalVersioner runtime.GroupVersioner
}
// NewMetricConverter creates a MetricConverter which knows how to convert objects
// between different versions of the custom metrics api.
func NewMetricConverter() *MetricConverter {
return &MetricConverter{
scheme: scheme.Scheme,
codecs: serializer.NewCodecFactory(scheme.Scheme),
internalVersioner: runtime.NewMultiGroupVersioner(
scheme.SchemeGroupVersion,
schema.GroupKind{Group: cmint.GroupName, Kind: ""},
schema.GroupKind{Group: cmv1beta1.GroupName, Kind: ""},
schema.GroupKind{Group: cmv1beta2.GroupName, Kind: ""},
),
}
}
// Scheme returns the scheme used by this metric converter.
func (c *MetricConverter) Scheme() *runtime.Scheme {
return c.scheme
}
// Codecs returns the codecs used by this metric converter
func (c *MetricConverter) Codecs() serializer.CodecFactory {
return c.codecs
}
// ConvertListOptionsToVersion converts converts a set of MetricListOptions
// to the provided GroupVersion.
func (c *MetricConverter) ConvertListOptionsToVersion(opts *cmint.MetricListOptions, version schema.GroupVersion) (runtime.Object, error) {
paramObj, err := c.UnsafeConvertToVersionVia(opts, version)
if err != nil {
return nil, err
}
return paramObj, nil
}
// ConvertResultToVersion converts a Result to the provided GroupVersion
func (c *MetricConverter) ConvertResultToVersion(res rest.Result, gv schema.GroupVersion) (runtime.Object, error) {
if err := res.Error(); err != nil {
return nil, err
}
metricBytes, err := res.Raw()
if err != nil {
return nil, err
}
decoder := c.codecs.UniversalDecoder(MetricVersions...)
rawMetricObj, err := runtime.Decode(decoder, metricBytes)
if err != nil {
return nil, err
}
metricObj, err := c.UnsafeConvertToVersionVia(rawMetricObj, gv)
if err != nil {
return nil, err
}
return metricObj, nil
}
// UnsafeConvertToVersionVia is like Scheme.UnsafeConvertToVersion, but it does so via an internal version first.
// We use it here to work with the v1beta2 client internally, while preserving backwards compatibility for existing custom metrics adapters
func (c *MetricConverter) UnsafeConvertToVersionVia(obj runtime.Object, externalVersion schema.GroupVersion) (runtime.Object, error) {
objInt, err := c.scheme.UnsafeConvertToVersion(obj, schema.GroupVersion{Group: externalVersion.Group, Version: runtime.APIVersionInternal})
if err != nil {
return nil, fmt.Errorf("failed to convert the given object to the internal version: %v", err)
}
objExt, err := c.scheme.UnsafeConvertToVersion(objInt, externalVersion)
if err != nil {
return nil, fmt.Errorf("failed to convert the given object back to the external version: %v", err)
}
return objExt, err
}

View File

@ -0,0 +1,145 @@
/*
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 custom_metrics
import (
"fmt"
"sync"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
cmint "k8s.io/metrics/pkg/apis/custom_metrics"
)
var (
// metricVersionsToGV is the map of string group-versions
// accepted by the converter to group-version objects (so
// we don't have to re-parse)
metricVersionsToGV map[string]schema.GroupVersion
)
func init() {
metricVersionsToGV = make(map[string]schema.GroupVersion)
for _, ver := range MetricVersions {
metricVersionsToGV[ver.String()] = ver
}
}
// NewAvailableAPIsGetter creates an AvailableAPIsGetter that checks discovery
// to find the available versions of the custom metrics api.
func NewAvailableAPIsGetter(client discovery.DiscoveryInterface) AvailableAPIsGetter {
return &apiVersionsFromDiscovery{
client: client,
}
}
// apiVersionsFromDiscovery caches a preferred version of the custom metrics api.
type apiVersionsFromDiscovery struct {
client discovery.DiscoveryInterface
// just cache the group directly since the discovery interface doesn't yet allow
// asking for a single API group's versions.
prefVersion *schema.GroupVersion
mu sync.RWMutex
}
// fetchVersions fetches the versions, but doesn't try to invalidate on cache misses.
func (d *apiVersionsFromDiscovery) fetchVersions() (*metav1.APIGroup, error) {
// TODO(directxman12): amend the discovery interface to ask for a particular group (/apis/foo)
groups, err := d.client.ServerGroups()
if err != nil {
return nil, err
}
// Determine the preferred version on the server by first finding the custom metrics group
var apiGroup *metav1.APIGroup
for _, group := range groups.Groups {
if group.Name == cmint.GroupName {
apiGroup = &group
break
}
}
if apiGroup == nil {
return nil, fmt.Errorf("no custom metrics API (%s) registered", cmint.GroupName)
}
return apiGroup, nil
}
// chooseVersion sets a preferred version of the custom metrics api based on available versions.
func (d *apiVersionsFromDiscovery) chooseVersion(apiGroup *metav1.APIGroup) (schema.GroupVersion, error) {
var preferredVersion *schema.GroupVersion
if gv, present := metricVersionsToGV[apiGroup.PreferredVersion.GroupVersion]; present && len(apiGroup.PreferredVersion.GroupVersion) != 0 {
preferredVersion = &gv
} else {
for _, version := range apiGroup.Versions {
if gv, present := metricVersionsToGV[version.GroupVersion]; present {
preferredVersion = &gv
break
}
}
}
if preferredVersion == nil {
return schema.GroupVersion{}, fmt.Errorf("no known available metric versions found")
}
return *preferredVersion, nil
}
// PreferredVersion returns the current preferred version of the custom metrics api.
// If none is specified, it will use the first known one.
func (d *apiVersionsFromDiscovery) PreferredVersion() (schema.GroupVersion, error) {
d.mu.RLock()
if d.prefVersion != nil {
// if we've already got one, proceed with that
defer d.mu.RUnlock()
return *d.prefVersion, nil
}
d.mu.RUnlock()
d.mu.Lock()
defer d.mu.Unlock()
// double check, someone might have beaten us to it
if d.prefVersion != nil {
return *d.prefVersion, nil
}
// populate our cache
groupInfo, err := d.fetchVersions()
if err != nil {
return schema.GroupVersion{}, err
}
prefVersion, err := d.chooseVersion(groupInfo)
if err != nil {
return schema.GroupVersion{}, err
}
d.prefVersion = &prefVersion
return *d.prefVersion, nil
}
// Invalidate refreshes the preferred version information.
func (d *apiVersionsFromDiscovery) Invalidate() {
d.mu.Lock()
defer d.mu.Unlock()
d.prefVersion = nil
}

View File

@ -0,0 +1,54 @@
/*
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 custom_metrics
import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
)
// CustomMetricsClient is a client for fetching metrics
// describing both root-scoped and namespaced resources.
type CustomMetricsClient interface {
RootScopedMetricsGetter
NamespacedMetricsGetter
}
// RootScopedMetricsGetter provides access to an interface for fetching
// metrics describing root-scoped objects. Note that metrics describing
// a namespace are simply considered a special case of root-scoped metrics.
type RootScopedMetricsGetter interface {
RootScopedMetrics() MetricsInterface
}
// NamespacedMetricsGetter provides access to an interface for fetching
// metrics describing resources in a particular namespace.
type NamespacedMetricsGetter interface {
NamespacedMetrics(namespace string) MetricsInterface
}
// 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, 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, metricSelector labels.Selector) (*v1beta2.MetricValueList, error)
}

View File

@ -0,0 +1,138 @@
/*
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 custom_metrics
import (
"sync"
"time"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
)
// AvailableAPIsGetter knows how to fetch and cache the preferred custom metrics API version,
// and invalidate that cache when asked.
type AvailableAPIsGetter interface {
PreferredVersion() (schema.GroupVersion, error)
Invalidate()
}
// PeriodicallyInvalidate periodically invalidates the preferred version cache until
// told to stop.
func PeriodicallyInvalidate(cache AvailableAPIsGetter, interval time.Duration, stopCh <-chan struct{}) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
cache.Invalidate()
case <-stopCh:
return
}
}
}
// NewForConfig creates a new custom metrics client which delegates to a client which
// uses the preferred api version.
func NewForConfig(baseConfig *rest.Config, mapper meta.RESTMapper, availableAPIs AvailableAPIsGetter) CustomMetricsClient {
return &multiClient{
clients: make(map[schema.GroupVersion]CustomMetricsClient),
availableAPIs: availableAPIs,
newClient: func(ver schema.GroupVersion) (CustomMetricsClient, error) {
return NewForVersionForConfig(rest.CopyConfig(baseConfig), mapper, ver)
},
}
}
// multiClient is a CustomMetricsClient that can work with *any* metrics API version.
type multiClient struct {
newClient func(schema.GroupVersion) (CustomMetricsClient, error)
clients map[schema.GroupVersion]CustomMetricsClient
availableAPIs AvailableAPIsGetter
mu sync.RWMutex
}
// getPreferredClient returns a custom metrics client of the preferred api version.
func (c *multiClient) getPreferredClient() (CustomMetricsClient, error) {
pref, err := c.availableAPIs.PreferredVersion()
if err != nil {
return nil, err
}
c.mu.RLock()
client, present := c.clients[pref]
c.mu.RUnlock()
if present {
return client, nil
}
c.mu.Lock()
defer c.mu.Unlock()
client, err = c.newClient(pref)
if err != nil {
return nil, err
}
c.clients[pref] = client
return client, nil
}
func (c *multiClient) RootScopedMetrics() MetricsInterface {
return &multiClientInterface{clients: c}
}
func (c *multiClient) NamespacedMetrics(namespace string) MetricsInterface {
return &multiClientInterface{
clients: c,
namespace: &namespace,
}
}
type multiClientInterface struct {
clients *multiClient
namespace *string
}
func (m *multiClientInterface) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
client, err := m.clients.getPreferredClient()
if err != nil {
return nil, err
}
if m.namespace == nil {
return client.RootScopedMetrics().GetForObject(groupKind, name, metricName, metricSelector)
} else {
return client.NamespacedMetrics(*m.namespace).GetForObject(groupKind, name, metricName, metricSelector)
}
}
func (m *multiClientInterface) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) {
client, err := m.clients.getPreferredClient()
if err != nil {
return nil, err
}
if m.namespace == nil {
return client.RootScopedMetrics().GetForObjects(groupKind, selector, metricName, metricSelector)
} else {
return client.NamespacedMetrics(*m.namespace).GetForObjects(groupKind, selector, metricName, metricSelector)
}
}

View File

@ -0,0 +1,67 @@
/*
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 scheme
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
cmint "k8s.io/metrics/pkg/apis/custom_metrics"
cmv1beta1 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
cmv1beta2 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
)
// GroupName is the group name use in this package.
const GroupName = cmv1beta1.GroupName
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}
// Scheme is the runtime.Scheme to which all custom metrics api types are registered.
var Scheme = runtime.NewScheme()
// Codecs provides access to encoding and decoding for the scheme.
var Codecs = serializer.NewCodecFactory(Scheme)
// ParameterCodec handles versioning of objects that are converted to query parameters.
var ParameterCodec = runtime.NewParameterCodec(Scheme)
func init() {
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
AddToScheme(Scheme)
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
func AddToScheme(scheme *runtime.Scheme) {
cmint.AddToScheme(scheme)
cmv1beta1.AddToScheme(scheme)
cmv1beta2.AddToScheme(scheme)
}

View File

@ -0,0 +1,292 @@
/*
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 custom_metrics
import (
"context"
"fmt"
"reflect"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol"
cmint "k8s.io/metrics/pkg/apis/custom_metrics"
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
"k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
"k8s.io/metrics/pkg/client/custom_metrics/scheme"
)
var versionConverter = NewMetricConverter()
type customMetricsClient struct {
client rest.Interface
version schema.GroupVersion
mapper meta.RESTMapper
}
// NewForVersion returns a new CustomMetricsClient for a particular api version.
func NewForVersion(client rest.Interface, mapper meta.RESTMapper, version schema.GroupVersion) CustomMetricsClient {
return &customMetricsClient{
client: client,
version: version,
mapper: mapper,
}
}
// NewForVersionForConfig returns a new CustomMetricsClient for a particular api version and base configuration.
func NewForVersionForConfig(c *rest.Config, mapper meta.RESTMapper, version schema.GroupVersion) (CustomMetricsClient, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
}
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
configShallowCopy.APIPath = "/apis"
if configShallowCopy.UserAgent == "" {
configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent()
}
configShallowCopy.GroupVersion = &version
configShallowCopy.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
client, err := rest.RESTClientFor(&configShallowCopy)
if err != nil {
return nil, err
}
return NewForVersion(client, mapper, version), nil
}
func (c *customMetricsClient) RootScopedMetrics() MetricsInterface {
return &rootScopedMetrics{c}
}
func (c *customMetricsClient) NamespacedMetrics(namespace string) MetricsInterface {
return &namespacedMetrics{
client: c,
namespace: namespace,
}
}
// qualResourceForKind returns the string format of a qualified group resource for the specified GroupKind
func (c *customMetricsClient) qualResourceForKind(groupKind schema.GroupKind) (string, error) {
mapping, err := c.mapper.RESTMapping(groupKind)
if err != nil {
return "", fmt.Errorf("unable to map kind %s to resource: %v", groupKind.String(), err)
}
gr := mapping.Resource.GroupResource()
return gr.String(), nil
}
type rootScopedMetrics struct {
client *customMetricsClient
}
func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) {
params, err := versionConverter.ConvertListOptionsToVersion(&cmint.MetricListOptions{
MetricLabelSelector: metricSelector.String(),
}, m.client.version)
if err != nil {
return nil, err
}
result := m.client.client.Get().
Resource("metrics").
Namespace(namespace).
Name(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
return nil, err
}
var res *v1beta2.MetricValueList
var ok bool
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
}
if len(res.Items) != 1 {
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
}
return &res.Items[0], nil
}
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, metricSelector)
}
resourceName, err := m.client.qualResourceForKind(groupKind)
if err != nil {
return nil, err
}
params, err := versionConverter.ConvertListOptionsToVersion(&cmint.MetricListOptions{
MetricLabelSelector: metricSelector.String(),
}, m.client.version)
if err != nil {
return nil, err
}
result := m.client.client.Get().
Resource(resourceName).
Name(name).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
return nil, err
}
var res *v1beta2.MetricValueList
var ok bool
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
}
if len(res.Items) != 1 {
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
}
return &res.Items[0], nil
}
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")
}
resourceName, err := m.client.qualResourceForKind(groupKind)
if err != nil {
return nil, err
}
params, err := versionConverter.ConvertListOptionsToVersion(&cmint.MetricListOptions{
LabelSelector: selector.String(),
MetricLabelSelector: metricSelector.String(),
}, m.client.version)
if err != nil {
return nil, err
}
result := m.client.client.Get().
Resource(resourceName).
Name(v1beta1.AllObjects).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
return nil, err
}
var res *v1beta2.MetricValueList
var ok bool
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
}
return res, nil
}
type namespacedMetrics struct {
client *customMetricsClient
namespace string
}
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
}
params, err := versionConverter.ConvertListOptionsToVersion(&cmint.MetricListOptions{
MetricLabelSelector: metricSelector.String(),
}, m.client.version)
if err != nil {
return nil, err
}
result := m.client.client.Get().
Resource(resourceName).
Namespace(m.namespace).
Name(name).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
return nil, err
}
var res *v1beta2.MetricValueList
var ok bool
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
}
if len(res.Items) != 1 {
return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(res.Items))
}
return &res.Items[0], nil
}
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
}
params, err := versionConverter.ConvertListOptionsToVersion(&cmint.MetricListOptions{
LabelSelector: selector.String(),
MetricLabelSelector: metricSelector.String(),
}, m.client.version)
if err != nil {
return nil, err
}
result := m.client.client.Get().
Resource(resourceName).
Namespace(m.namespace).
Name(v1beta1.AllObjects).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
return nil, err
}
var res *v1beta2.MetricValueList
var ok bool
if res, ok = metricObj.(*v1beta2.MetricValueList); !ok {
return nil, fmt.Errorf("the custom metrics API server didn't return MetricValueList, the type is %v", reflect.TypeOf(metricObj))
}
return res, nil
}

View File

@ -0,0 +1,100 @@
/*
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 external_metrics
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/metrics/pkg/apis/external_metrics/v1beta1"
)
type externalMetricsClient struct {
client rest.Interface
}
func New(client rest.Interface) ExternalMetricsClient {
return &externalMetricsClient{
client: client,
}
}
func NewForConfig(c *rest.Config) (ExternalMetricsClient, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
}
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
configShallowCopy.APIPath = "/apis"
if configShallowCopy.UserAgent == "" {
configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent()
}
configShallowCopy.GroupVersion = &v1beta1.SchemeGroupVersion
configShallowCopy.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
client, err := rest.RESTClientFor(&configShallowCopy)
if err != nil {
return nil, err
}
return New(client), nil
}
func NewForConfigOrDie(c *rest.Config) ExternalMetricsClient {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}
func (c *externalMetricsClient) NamespacedMetrics(namespace string) MetricsInterface {
return &namespacedMetrics{
client: c,
namespace: namespace,
}
}
type namespacedMetrics struct {
client *externalMetricsClient
namespace string
}
func (m *namespacedMetrics) List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error) {
res := &v1beta1.ExternalMetricValueList{}
err := m.client.client.Get().
Namespace(m.namespace).
Resource(metricName).
VersionedParams(&metav1.ListOptions{
LabelSelector: metricSelector.String(),
}, metav1.ParameterCodec).
Do(context.TODO()).
Into(res)
if err != nil {
return nil, err
}
return res, nil
}

View File

@ -0,0 +1,40 @@
/*
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 external_metrics
import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/metrics/pkg/apis/external_metrics/v1beta1"
)
// ExternalMetricsClient is a client for fetching external metrics.
type ExternalMetricsClient interface {
NamespacedMetricsGetter
}
// NamespacedMetricsGetter provides access to an interface for fetching
// metrics in a particular namespace.
type NamespacedMetricsGetter interface {
NamespacedMetrics(namespace string) MetricsInterface
}
// MetricsInterface provides access to external metrics.
type MetricsInterface interface {
// List fetches the metric for the given namespace that maches the given
// metricSelector.
List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error)
}

6
vendor/modules.txt vendored
View File

@ -1614,7 +1614,13 @@ k8s.io/metrics/pkg/apis/external_metrics/install
k8s.io/metrics/pkg/apis/external_metrics/v1beta1
k8s.io/metrics/pkg/apis/metrics
k8s.io/metrics/pkg/apis/metrics/install
k8s.io/metrics/pkg/apis/metrics/v1alpha1
k8s.io/metrics/pkg/apis/metrics/v1beta1
k8s.io/metrics/pkg/client/clientset/versioned/scheme
k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1
k8s.io/metrics/pkg/client/custom_metrics
k8s.io/metrics/pkg/client/custom_metrics/scheme
k8s.io/metrics/pkg/client/external_metrics
# k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
## explicit; go 1.18
k8s.io/utils/buffer