├── .github └── PULL_REQUEST_TEMPLATE.md ├── CONTRIBUTING.md ├── LICENSE ├── OWNERS ├── README.md ├── SECURITY_CONTACTS ├── code-of-conduct.md ├── doc.go ├── go.mod ├── go.sum ├── hack ├── boilerplate.go.txt ├── tools.go ├── update-codegen.sh └── verify-codegen.sh └── pkg ├── apis ├── OWNERS ├── custom_metrics │ ├── conversion.go │ ├── doc.go │ ├── install │ │ └── install.go │ ├── register.go │ ├── types.go │ ├── v1beta1 │ │ ├── conversion.go │ │ ├── doc.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── register.go │ │ ├── types.go │ │ ├── zz_generated.conversion.go │ │ └── zz_generated.deepcopy.go │ ├── v1beta2 │ │ ├── doc.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── register.go │ │ ├── types.go │ │ ├── zz_generated.conversion.go │ │ └── zz_generated.deepcopy.go │ └── zz_generated.deepcopy.go ├── external_metrics │ ├── doc.go │ ├── install │ │ └── install.go │ ├── register.go │ ├── types.go │ ├── v1beta1 │ │ ├── doc.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── register.go │ │ ├── types.go │ │ ├── zz_generated.conversion.go │ │ └── zz_generated.deepcopy.go │ └── zz_generated.deepcopy.go ├── metrics │ ├── doc.go │ ├── install │ │ └── install.go │ ├── register.go │ ├── types.go │ ├── v1alpha1 │ │ ├── doc.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── register.go │ │ ├── types.go │ │ ├── zz_generated.conversion.go │ │ └── zz_generated.deepcopy.go │ ├── v1beta1 │ │ ├── doc.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── register.go │ │ ├── types.go │ │ ├── zz_generated.conversion.go │ │ └── zz_generated.deepcopy.go │ └── zz_generated.deepcopy.go └── roundtrip_test.go └── client ├── clientset └── versioned │ ├── clientset.go │ ├── fake │ ├── clientset_generated.go │ ├── doc.go │ └── register.go │ ├── scheme │ ├── doc.go │ └── register.go │ └── typed │ └── metrics │ ├── v1alpha1 │ ├── doc.go │ ├── fake │ │ ├── doc.go │ │ ├── fake_metrics_client.go │ │ ├── fake_nodemetrics.go │ │ └── fake_podmetrics.go │ ├── generated_expansion.go │ ├── metrics_client.go │ ├── nodemetrics.go │ └── podmetrics.go │ └── v1beta1 │ ├── doc.go │ ├── fake │ ├── doc.go │ ├── fake_metrics_client.go │ ├── fake_nodemetrics.go │ └── fake_podmetrics.go │ ├── generated_expansion.go │ ├── metrics_client.go │ ├── nodemetrics.go │ └── podmetrics.go ├── clientset_test └── clientset_test.go ├── custom_metrics ├── converter.go ├── discovery.go ├── fake │ └── fake_client.go ├── interfaces.go ├── multi_client.go ├── scheme │ └── register.go ├── util_test.go └── versioned_client.go └── external_metrics ├── client.go ├── fake └── fake_client.go └── interfaces.go /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Sorry, we do not accept changes directly against this repository. Please see 2 | CONTRIBUTING.md for information on where and how to contribute instead. 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | Do not open pull requests directly against this repository, they will be ignored. Instead, please open pull requests against [kubernetes/kubernetes](https://git.k8s.io/kubernetes/). Please follow the same [contributing guide](https://git.k8s.io/kubernetes/CONTRIBUTING.md) you would follow for any other pull request made to kubernetes/kubernetes. 4 | 5 | This repository is published from [kubernetes/kubernetes/staging/src/k8s.io/metrics](https://git.k8s.io/kubernetes/staging/src/k8s.io/metrics) by the [kubernetes publishing-bot](https://git.k8s.io/publishing-bot). 6 | 7 | Please see [Staging Directory and Publishing](https://git.k8s.io/community/contributors/devel/sig-architecture/staging.md) for more information 8 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - sig-instrumentation-approvers 5 | labels: 6 | - sig/instrumentation 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # metrics 2 | 3 | Kubernetes metrics API type definitions and clients. 4 | 5 | ## Purpose 6 | 7 | This repository contains type definitions and client code for the metrics 8 | APIs that Kubernetes makes use of. Depending on the API, the actual 9 | implementations live elsewhere. 10 | 11 | Consumers of the metrics APIs can make use of this repository to access 12 | implementations of the APIs, while implementors should make use of this 13 | library when implementing their API servers. 14 | 15 | ## APIs 16 | 17 | This repository contains types and clients for several APIs. 18 | 19 | ### Custom Metrics API 20 | 21 | This API allows consumers to access arbitrary metrics which describe 22 | Kubernetes resources. 23 | 24 | The API is intended to be implemented by monitoring pipeline vendors, on 25 | top of their metrics storage solutions. 26 | 27 | If you want to implement this as an API server for this API, please see the 28 | [kubernetes-sigs/custom-metrics-apiserver](https://github.com/kubernetes-sigs/custom-metrics-apiserver) 29 | library, which contains the basic infrastructure required to set up such 30 | an API server. 31 | 32 | Import Path: `k8s.io/metrics/pkg/apis/custom_metrics`. 33 | 34 | ### Resource Metrics API 35 | 36 | This API allows consumers to access resource metrics (CPU and memory) for 37 | pods and nodes. 38 | 39 | The API is implemented by [metrics-server](https://github.com/kubernetes-sigs/metrics-server) and [prometheus-adapter](https://github.com/kubernetes-sigs/prometheus-adapter). 40 | 41 | Import Path: `k8s.io/metrics/pkg/apis/metrics`. 42 | 43 | ## Compatibility 44 | 45 | The APIs in this repository follow the standard guarantees for Kubernetes 46 | APIs, and will follow Kubernetes releases. 47 | 48 | ## Community, discussion, contribution, and support 49 | 50 | Learn how to engage with the Kubernetes community on the [community 51 | page](http://kubernetes.io/community/). 52 | 53 | You can reach the maintainers of this repository at: 54 | 55 | - Slack: [#sig-instrumentation channel](https://kubernetes.slack.com/messages/sig-instrumentation), you can get an 56 | invite at [slack.kubernetes.io](https://slack.kubernetes.io). 57 | - [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-sig-instrumentation) 58 | 59 | ### Code of Conduct 60 | 61 | Participation in the Kubernetes community is governed by the [Kubernetes 62 | Code of Conduct](code-of-conduct.md). 63 | 64 | ### Contibution Guidelines 65 | 66 | See [CONTRIBUTING.md](CONTRIBUTING.md) for more information. 67 | 68 | -------------------------------------------------------------------------------- /SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Committee to reach out 4 | # to for triaging and handling of incoming issues. 5 | # 6 | # The below names agree to abide by the 7 | # [Embargo Policy](https://git.k8s.io/security/private-distributors-list.md#embargo-policy) 8 | # and will be removed and replaced if they violate that agreement. 9 | # 10 | # DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE 11 | # INSTRUCTIONS AT https://kubernetes.io/security/ 12 | 13 | cjcullen 14 | joelsmith 15 | liggitt 16 | philips 17 | tallclair 18 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Community Code of Conduct 2 | 3 | Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) 4 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package metrics 18 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | // This is a generated file. Do not edit directly. 2 | 3 | module k8s.io/metrics 4 | 5 | go 1.24.0 6 | 7 | godebug default=go1.24 8 | 9 | require ( 10 | github.com/gogo/protobuf v1.3.2 11 | github.com/stretchr/testify v1.10.0 12 | k8s.io/api v0.0.0-20250516033257-ffe08c772d5b 13 | k8s.io/apimachinery v0.0.0-20250516032956-da3bba90543c 14 | k8s.io/client-go v0.0.0-20250516033711-025e06660a23 15 | k8s.io/code-generator v0.0.0-20250516034928-3a6fa0a71475 16 | ) 17 | 18 | require ( 19 | github.com/davecgh/go-spew v1.1.1 // indirect 20 | github.com/emicklei/go-restful/v3 v3.11.0 // indirect 21 | github.com/fxamacker/cbor/v2 v2.8.0 // indirect 22 | github.com/go-logr/logr v1.4.2 // indirect 23 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 24 | github.com/go-openapi/jsonreference v0.20.2 // indirect 25 | github.com/go-openapi/swag v0.23.0 // indirect 26 | github.com/google/gnostic-models v0.6.9 // indirect 27 | github.com/google/go-cmp v0.7.0 // indirect 28 | github.com/google/uuid v1.6.0 // indirect 29 | github.com/josharian/intern v1.0.0 // indirect 30 | github.com/json-iterator/go v1.1.12 // indirect 31 | github.com/mailru/easyjson v0.7.7 // indirect 32 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 33 | github.com/modern-go/reflect2 v1.0.2 // indirect 34 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 35 | github.com/pkg/errors v0.9.1 // indirect 36 | github.com/pmezard/go-difflib v1.0.0 // indirect 37 | github.com/spf13/pflag v1.0.6 // indirect 38 | github.com/x448/float16 v0.8.4 // indirect 39 | golang.org/x/mod v0.21.0 // indirect 40 | golang.org/x/net v0.38.0 // indirect 41 | golang.org/x/oauth2 v0.27.0 // indirect 42 | golang.org/x/sync v0.12.0 // indirect 43 | golang.org/x/sys v0.31.0 // indirect 44 | golang.org/x/term v0.30.0 // indirect 45 | golang.org/x/text v0.23.0 // indirect 46 | golang.org/x/time v0.9.0 // indirect 47 | golang.org/x/tools v0.26.0 // indirect 48 | google.golang.org/protobuf v1.36.5 // indirect 49 | gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect 50 | gopkg.in/inf.v0 v0.9.1 // indirect 51 | gopkg.in/yaml.v3 v3.0.1 // indirect 52 | k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect 53 | k8s.io/klog/v2 v2.130.1 // indirect 54 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect 55 | k8s.io/utils v0.0.0-20250502105355-0f33e8f1c979 // indirect 56 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect 57 | sigs.k8s.io/randfill v1.0.0 // indirect 58 | sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect 59 | sigs.k8s.io/yaml v1.4.0 // indirect 60 | ) 61 | -------------------------------------------------------------------------------- /hack/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /hack/tools.go: -------------------------------------------------------------------------------- 1 | //go:build tools 2 | // +build tools 3 | 4 | /* 5 | Copyright 2019 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // This package imports things required by build scripts, to force `go mod` to see them as dependencies 21 | package tools 22 | 23 | import _ "k8s.io/code-generator" 24 | -------------------------------------------------------------------------------- /hack/update-codegen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o nounset 19 | set -o pipefail 20 | 21 | SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. 22 | CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} 23 | 24 | source "${CODEGEN_PKG}/kube_codegen.sh" 25 | 26 | THIS_PKG="k8s.io/metrics" 27 | 28 | # we skip informers and listers for metrics, because we don't quite support the requisite operations yet 29 | # we skip generating the internal clientset as it's not really needed 30 | 31 | kube::codegen::gen_helpers \ 32 | --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ 33 | "${SCRIPT_ROOT}/pkg/apis" 34 | 35 | kube::codegen::gen_client \ 36 | --output-dir "${SCRIPT_ROOT}/pkg/client" \ 37 | --output-pkg "${THIS_PKG}/pkg/client" \ 38 | --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ 39 | --prefers-protobuf \ 40 | "${SCRIPT_ROOT}/pkg/apis" 41 | -------------------------------------------------------------------------------- /hack/verify-codegen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o nounset 19 | set -o pipefail 20 | 21 | SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" 22 | DIFFROOT="${SCRIPT_ROOT}/pkg" 23 | TMP_DIFFROOT="$(mktemp -d -t "$(basename "$0").XXXXXX")/pkg" 24 | 25 | cleanup() { 26 | rm -rf "${TMP_DIFFROOT}" 27 | } 28 | trap "cleanup" EXIT SIGINT 29 | 30 | cleanup 31 | 32 | mkdir -p "${TMP_DIFFROOT}" 33 | cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" 34 | 35 | "${SCRIPT_ROOT}/hack/update-codegen.sh" 36 | echo "diffing ${DIFFROOT} against freshly generated codegen" 37 | ret=0 38 | diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? 39 | if [[ $ret -eq 0 ]]; then 40 | echo "${DIFFROOT} up to date." 41 | else 42 | echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh" 43 | fi 44 | exit $ret 45 | -------------------------------------------------------------------------------- /pkg/apis/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | # Disable inheritance as this is an api owners file 4 | options: 5 | no_parent_owners: true 6 | approvers: 7 | - api-approvers 8 | reviewers: 9 | - api-reviewers 10 | - sig-autoscaling-maintainers 11 | labels: 12 | - kind/api-change 13 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/conversion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "k8s.io/api/core/v1" 21 | "k8s.io/apimachinery/pkg/conversion" 22 | ) 23 | 24 | func Convert_v1_ObjectReference_To_custom_metrics_ObjectReference(in *v1.ObjectReference, out *ObjectReference, s conversion.Scope) error { 25 | out.APIVersion = in.APIVersion 26 | 27 | out.Kind = in.Kind 28 | out.Namespace = in.Namespace 29 | out.Name = in.Name 30 | out.UID = in.UID 31 | out.ResourceVersion = in.ResourceVersion 32 | out.FieldPath = in.FieldPath 33 | return nil 34 | } 35 | 36 | func Convert_custom_metrics_ObjectReference_To_v1_ObjectReference(in *ObjectReference, out *v1.ObjectReference, s conversion.Scope) error { 37 | out.APIVersion = in.APIVersion 38 | 39 | out.Kind = in.Kind 40 | out.Namespace = in.Namespace 41 | out.Name = in.Name 42 | out.UID = in.UID 43 | out.ResourceVersion = in.ResourceVersion 44 | out.FieldPath = in.FieldPath 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +groupName=custom.metrics.k8s.io 19 | 20 | // Package custom_metrics defines an API for using custom metrics. 21 | package custom_metrics 22 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/install/install.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package install installs the experimental API group, making it available as 18 | // an option to all of the API encoding/decoding machinery. 19 | package install 20 | 21 | import ( 22 | "k8s.io/apimachinery/pkg/runtime" 23 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 24 | "k8s.io/metrics/pkg/apis/custom_metrics" 25 | "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1" 26 | "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 27 | ) 28 | 29 | // Install registers the API group and adds types to a scheme 30 | func Install(scheme *runtime.Scheme) { 31 | utilruntime.Must(custom_metrics.AddToScheme(scheme)) 32 | utilruntime.Must(v1beta2.AddToScheme(scheme)) 33 | utilruntime.Must(v1beta1.AddToScheme(scheme)) 34 | utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion, v1beta2.SchemeGroupVersion)) 35 | } 36 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | ) 23 | 24 | // GroupName is the group name use in this package 25 | const GroupName = "custom.metrics.k8s.io" 26 | 27 | // SchemeGroupVersion is group version used to register these objects 28 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} 29 | 30 | // Kind takes an unqualified kind and returns back a Group qualified GroupKind 31 | func Kind(kind string) schema.GroupKind { 32 | return SchemeGroupVersion.WithKind(kind).GroupKind() 33 | } 34 | 35 | // Resource takes an unqualified resource and returns back a Group qualified GroupResource 36 | func Resource(resource string) schema.GroupResource { 37 | return SchemeGroupVersion.WithResource(resource).GroupResource() 38 | } 39 | 40 | var ( 41 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 42 | AddToScheme = SchemeBuilder.AddToScheme 43 | ) 44 | 45 | func addKnownTypes(scheme *runtime.Scheme) error { 46 | scheme.AddKnownTypes(SchemeGroupVersion, 47 | &MetricValue{}, 48 | &MetricValueList{}, 49 | &MetricListOptions{}, 50 | ) 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/api/resource" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "k8s.io/apimachinery/pkg/types" 23 | ) 24 | 25 | type MetricIdentifier struct { 26 | // name is the name of the given metric 27 | Name string 28 | // selector represents the label selector that could be used to select 29 | // this metric, and will generally just be the selector passed in to 30 | // the query used to fetch this metric. 31 | // +optional 32 | Selector *metav1.LabelSelector 33 | } 34 | 35 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 36 | 37 | // a list of values for a given metric for some set of objects 38 | type MetricValueList struct { 39 | metav1.TypeMeta `json:",inline"` 40 | metav1.ListMeta `json:"metadata,omitempty"` 41 | 42 | // the value of the metric across the described objects 43 | Items []MetricValue `json:"items"` 44 | } 45 | 46 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 47 | 48 | // a metric value for some object 49 | type MetricValue struct { 50 | metav1.TypeMeta 51 | 52 | // a reference to the described object 53 | DescribedObject ObjectReference 54 | 55 | Metric MetricIdentifier 56 | 57 | // indicates the time at which the metrics were produced 58 | Timestamp metav1.Time 59 | 60 | // indicates the window ([Timestamp-Window, Timestamp]) from 61 | // which these metrics were calculated, when returning rate 62 | // metrics calculated from cumulative metrics (or zero for 63 | // non-calculated instantaneous metrics). 64 | WindowSeconds *int64 65 | 66 | // the value of the metric for this 67 | Value resource.Quantity 68 | } 69 | 70 | // allObjects is a wildcard used to select metrics 71 | // for all objects matching the given label selector 72 | const AllObjects = "*" 73 | 74 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 75 | 76 | // MetricListOptions is used to select metrics by their label selectors 77 | type MetricListOptions struct { 78 | metav1.TypeMeta 79 | 80 | // A selector to restrict the list of returned objects by their labels. 81 | // Defaults to everything. 82 | // +optional 83 | LabelSelector string 84 | 85 | // A selector to restrict the list of returned metrics by their labels 86 | // +optional 87 | MetricLabelSelector string 88 | } 89 | 90 | // NOTE: ObjectReference is copied from k8s.io/kubernetes/pkg/api/types.go. We 91 | // cannot depend on k8s.io/kubernetes/pkg/api because that creates cyclic 92 | // dependency between k8s.io/metrics and k8s.io/kubernetes. We cannot depend on 93 | // k8s.io/client-go/pkg/api because the package is going to be deprecated soon. 94 | // There is no need to keep it an exact copy. Each repo can define its own 95 | // internal objects. 96 | 97 | // ObjectReference contains enough information to let you inspect or modify the referred object. 98 | type ObjectReference struct { 99 | Kind string 100 | Namespace string 101 | Name string 102 | UID types.UID 103 | APIVersion string 104 | ResourceVersion string 105 | FieldPath string 106 | } 107 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta1/conversion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/conversion" 21 | "k8s.io/metrics/pkg/apis/custom_metrics" 22 | ) 23 | 24 | func Convert_v1beta1_MetricValue_To_custom_metrics_MetricValue(in *MetricValue, out *custom_metrics.MetricValue, s conversion.Scope) error { 25 | if err := autoConvert_v1beta1_MetricValue_To_custom_metrics_MetricValue(in, out, s); err != nil { 26 | return err 27 | } 28 | out.Metric.Name = in.MetricName 29 | out.Metric.Selector = in.Selector 30 | return nil 31 | } 32 | 33 | func Convert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in *custom_metrics.MetricValue, out *MetricValue, s conversion.Scope) error { 34 | if err := autoConvert_custom_metrics_MetricValue_To_v1beta1_MetricValue(in, out, s); err != nil { 35 | return err 36 | } 37 | out.MetricName = in.Metric.Name 38 | out.Selector = in.Metric.Selector 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:protobuf-gen=package 19 | // +k8s:conversion-gen=k8s.io/metrics/pkg/apis/custom_metrics 20 | // +k8s:openapi-gen=true 21 | 22 | // Package v1beta1 is the v1beta1 version of the custom_metrics API. 23 | package v1beta1 24 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta1/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.metrics.pkg.apis.custom_metrics.v1beta1; 23 | 24 | import "k8s.io/api/core/v1/generated.proto"; 25 | import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; 26 | import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; 27 | import "k8s.io/apimachinery/pkg/runtime/generated.proto"; 28 | import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; 29 | 30 | // Package-wide variables from generator "generated". 31 | option go_package = "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"; 32 | 33 | // MetricListOptions is used to select metrics by their label selectors 34 | message MetricListOptions { 35 | // A selector to restrict the list of returned objects by their labels. 36 | // Defaults to everything. 37 | // +optional 38 | optional string labelSelector = 1; 39 | 40 | // A selector to restrict the list of returned metrics by their labels 41 | // +optional 42 | optional string metricLabelSelector = 2; 43 | } 44 | 45 | // MetricValue is a metric value for some object 46 | message MetricValue { 47 | // a reference to the described object 48 | optional .k8s.io.api.core.v1.ObjectReference describedObject = 1; 49 | 50 | // the name of the metric 51 | optional string metricName = 2; 52 | 53 | // indicates the time at which the metrics were produced 54 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 3; 55 | 56 | // indicates the window ([Timestamp-Window, Timestamp]) from 57 | // which these metrics were calculated, when returning rate 58 | // metrics calculated from cumulative metrics (or zero for 59 | // non-calculated instantaneous metrics). 60 | optional int64 window = 4; 61 | 62 | // the value of the metric for this 63 | optional .k8s.io.apimachinery.pkg.api.resource.Quantity value = 5; 64 | 65 | // selector represents the label selector that could be used to select 66 | // this metric, and will generally just be the selector passed in to 67 | // the query used to fetch this metric. 68 | // When left blank, only the metric's Name will be used to gather metrics. 69 | // +optional 70 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector selector = 6; 71 | } 72 | 73 | // MetricValueList is a list of values for a given metric for some set of objects 74 | message MetricValueList { 75 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 76 | 77 | // the value of the metric across the described objects 78 | repeated MetricValue items = 2; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | // GroupName is the group name use in this package 26 | const GroupName = "custom.metrics.k8s.io" 27 | 28 | // SchemeGroupVersion is group version used to register these objects 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} 30 | 31 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 32 | func Resource(resource string) schema.GroupResource { 33 | return SchemeGroupVersion.WithResource(resource).GroupResource() 34 | } 35 | 36 | var ( 37 | // SchemeBuilder points to a list of functions added to Scheme. 38 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 39 | localSchemeBuilder = &SchemeBuilder 40 | // AddToScheme applies all the stored functions to the scheme. 41 | AddToScheme = localSchemeBuilder.AddToScheme 42 | ) 43 | 44 | func addKnownTypes(scheme *runtime.Scheme) error { 45 | scheme.AddKnownTypes(SchemeGroupVersion, 46 | &MetricValue{}, 47 | &MetricValueList{}, 48 | &MetricListOptions{}, 49 | ) 50 | metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta1/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | "k8s.io/api/core/v1" 21 | "k8s.io/apimachinery/pkg/api/resource" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | ) 24 | 25 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 26 | 27 | // MetricValueList is a list of values for a given metric for some set of objects 28 | type MetricValueList struct { 29 | metav1.TypeMeta `json:",inline"` 30 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 31 | 32 | // the value of the metric across the described objects 33 | Items []MetricValue `json:"items" protobuf:"bytes,2,rep,name=items"` 34 | } 35 | 36 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 37 | 38 | // MetricValue is a metric value for some object 39 | type MetricValue struct { 40 | metav1.TypeMeta `json:",inline"` 41 | 42 | // a reference to the described object 43 | DescribedObject v1.ObjectReference `json:"describedObject" protobuf:"bytes,1,name=describedObject"` 44 | 45 | // the name of the metric 46 | MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"` 47 | 48 | // indicates the time at which the metrics were produced 49 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,3,name=timestamp"` 50 | 51 | // indicates the window ([Timestamp-Window, Timestamp]) from 52 | // which these metrics were calculated, when returning rate 53 | // metrics calculated from cumulative metrics (or zero for 54 | // non-calculated instantaneous metrics). 55 | WindowSeconds *int64 `json:"window,omitempty" protobuf:"bytes,4,opt,name=window"` 56 | 57 | // the value of the metric for this 58 | Value resource.Quantity `json:"value" protobuf:"bytes,5,name=value"` 59 | 60 | // selector represents the label selector that could be used to select 61 | // this metric, and will generally just be the selector passed in to 62 | // the query used to fetch this metric. 63 | // When left blank, only the metric's Name will be used to gather metrics. 64 | // +optional 65 | Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,6,opt,name=selector"` 66 | } 67 | 68 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 69 | 70 | // MetricListOptions is used to select metrics by their label selectors 71 | type MetricListOptions struct { 72 | metav1.TypeMeta `json:",inline"` 73 | 74 | // A selector to restrict the list of returned objects by their labels. 75 | // Defaults to everything. 76 | // +optional 77 | LabelSelector string `json:"labelSelector,omitempty" protobuf:"bytes,1,opt,name=labelSelector"` 78 | 79 | // A selector to restrict the list of returned metrics by their labels 80 | // +optional 81 | MetricLabelSelector string `json:"metricLabelSelector,omitempty" protobuf:"bytes,2,opt,name=metricLabelSelector"` 82 | } 83 | 84 | // AllObjects is a wildcard used to select metrics 85 | // for all objects matching the given label selector 86 | const AllObjects = "*" 87 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta1/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1beta1 23 | 24 | import ( 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *MetricListOptions) DeepCopyInto(out *MetricListOptions) { 31 | *out = *in 32 | out.TypeMeta = in.TypeMeta 33 | return 34 | } 35 | 36 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricListOptions. 37 | func (in *MetricListOptions) DeepCopy() *MetricListOptions { 38 | if in == nil { 39 | return nil 40 | } 41 | out := new(MetricListOptions) 42 | in.DeepCopyInto(out) 43 | return out 44 | } 45 | 46 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 47 | func (in *MetricListOptions) DeepCopyObject() runtime.Object { 48 | if c := in.DeepCopy(); c != nil { 49 | return c 50 | } 51 | return nil 52 | } 53 | 54 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 55 | func (in *MetricValue) DeepCopyInto(out *MetricValue) { 56 | *out = *in 57 | out.TypeMeta = in.TypeMeta 58 | out.DescribedObject = in.DescribedObject 59 | in.Timestamp.DeepCopyInto(&out.Timestamp) 60 | if in.WindowSeconds != nil { 61 | in, out := &in.WindowSeconds, &out.WindowSeconds 62 | *out = new(int64) 63 | **out = **in 64 | } 65 | out.Value = in.Value.DeepCopy() 66 | if in.Selector != nil { 67 | in, out := &in.Selector, &out.Selector 68 | *out = new(v1.LabelSelector) 69 | (*in).DeepCopyInto(*out) 70 | } 71 | return 72 | } 73 | 74 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricValue. 75 | func (in *MetricValue) DeepCopy() *MetricValue { 76 | if in == nil { 77 | return nil 78 | } 79 | out := new(MetricValue) 80 | in.DeepCopyInto(out) 81 | return out 82 | } 83 | 84 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 85 | func (in *MetricValue) DeepCopyObject() runtime.Object { 86 | if c := in.DeepCopy(); c != nil { 87 | return c 88 | } 89 | return nil 90 | } 91 | 92 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 93 | func (in *MetricValueList) DeepCopyInto(out *MetricValueList) { 94 | *out = *in 95 | out.TypeMeta = in.TypeMeta 96 | in.ListMeta.DeepCopyInto(&out.ListMeta) 97 | if in.Items != nil { 98 | in, out := &in.Items, &out.Items 99 | *out = make([]MetricValue, len(*in)) 100 | for i := range *in { 101 | (*in)[i].DeepCopyInto(&(*out)[i]) 102 | } 103 | } 104 | return 105 | } 106 | 107 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricValueList. 108 | func (in *MetricValueList) DeepCopy() *MetricValueList { 109 | if in == nil { 110 | return nil 111 | } 112 | out := new(MetricValueList) 113 | in.DeepCopyInto(out) 114 | return out 115 | } 116 | 117 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 118 | func (in *MetricValueList) DeepCopyObject() runtime.Object { 119 | if c := in.DeepCopy(); c != nil { 120 | return c 121 | } 122 | return nil 123 | } 124 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta2/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:protobuf-gen=package 19 | // +k8s:conversion-gen=k8s.io/metrics/pkg/apis/custom_metrics 20 | // +k8s:openapi-gen=true 21 | 22 | // Package v1beta2 is the v1beta2 version of the custom_metrics API. 23 | package v1beta2 24 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta2/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.metrics.pkg.apis.custom_metrics.v1beta2; 23 | 24 | import "k8s.io/api/core/v1/generated.proto"; 25 | import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; 26 | import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; 27 | import "k8s.io/apimachinery/pkg/runtime/generated.proto"; 28 | import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; 29 | 30 | // Package-wide variables from generator "generated". 31 | option go_package = "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"; 32 | 33 | // MetricIdentifier identifies a metric by name and, optionally, selector 34 | message MetricIdentifier { 35 | // name is the name of the given metric 36 | optional string name = 1; 37 | 38 | // selector represents the label selector that could be used to select 39 | // this metric, and will generally just be the selector passed in to 40 | // the query used to fetch this metric. 41 | // When left blank, only the metric's Name will be used to gather metrics. 42 | // +optional 43 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector selector = 2; 44 | } 45 | 46 | // MetricListOptions is used to select metrics by their label selectors 47 | message MetricListOptions { 48 | // A selector to restrict the list of returned objects by their labels. 49 | // Defaults to everything. 50 | // +optional 51 | optional string labelSelector = 1; 52 | 53 | // A selector to restrict the list of returned metrics by their labels 54 | // +optional 55 | optional string metricLabelSelector = 2; 56 | } 57 | 58 | // MetricValue is the metric value for some object 59 | message MetricValue { 60 | // a reference to the described object 61 | optional .k8s.io.api.core.v1.ObjectReference describedObject = 1; 62 | 63 | optional MetricIdentifier metric = 2; 64 | 65 | // indicates the time at which the metrics were produced 66 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 3; 67 | 68 | // indicates the window ([Timestamp-Window, Timestamp]) from 69 | // which these metrics were calculated, when returning rate 70 | // metrics calculated from cumulative metrics (or zero for 71 | // non-calculated instantaneous metrics). 72 | optional int64 windowSeconds = 4; 73 | 74 | // the value of the metric for this 75 | optional .k8s.io.apimachinery.pkg.api.resource.Quantity value = 5; 76 | } 77 | 78 | // MetricValueList is a list of values for a given metric for some set of objects 79 | message MetricValueList { 80 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 81 | 82 | // the value of the metric across the described objects 83 | repeated MetricValue items = 2; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta2/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta2 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | // GroupName is the group name use in this package 26 | const GroupName = "custom.metrics.k8s.io" 27 | 28 | // SchemeGroupVersion is group version used to register these objects 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta2"} 30 | 31 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 32 | func Resource(resource string) schema.GroupResource { 33 | return SchemeGroupVersion.WithResource(resource).GroupResource() 34 | } 35 | 36 | var ( 37 | // SchemeBuilder points to a list of functions added to Scheme. 38 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 39 | localSchemeBuilder = &SchemeBuilder 40 | // AddToScheme applies all the stored functions to the scheme. 41 | AddToScheme = localSchemeBuilder.AddToScheme 42 | ) 43 | 44 | func addKnownTypes(scheme *runtime.Scheme) error { 45 | scheme.AddKnownTypes(SchemeGroupVersion, 46 | &MetricValue{}, 47 | &MetricValueList{}, 48 | &MetricListOptions{}, 49 | ) 50 | metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta2/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta2 18 | 19 | import ( 20 | "k8s.io/api/core/v1" 21 | "k8s.io/apimachinery/pkg/api/resource" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | ) 24 | 25 | // MetricIdentifier identifies a metric by name and, optionally, selector 26 | type MetricIdentifier struct { 27 | // name is the name of the given metric 28 | Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 29 | // selector represents the label selector that could be used to select 30 | // this metric, and will generally just be the selector passed in to 31 | // the query used to fetch this metric. 32 | // When left blank, only the metric's Name will be used to gather metrics. 33 | // +optional 34 | Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"` 35 | } 36 | 37 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 38 | 39 | // MetricValueList is a list of values for a given metric for some set of objects 40 | type MetricValueList struct { 41 | metav1.TypeMeta `json:",inline"` 42 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 43 | 44 | // the value of the metric across the described objects 45 | Items []MetricValue `json:"items" protobuf:"bytes,2,rep,name=items"` 46 | } 47 | 48 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 49 | 50 | // MetricValue is the metric value for some object 51 | type MetricValue struct { 52 | metav1.TypeMeta `json:",inline"` 53 | 54 | // a reference to the described object 55 | DescribedObject v1.ObjectReference `json:"describedObject" protobuf:"bytes,1,name=describedObject"` 56 | 57 | Metric MetricIdentifier `json:"metric" protobuf:"bytes,2,name=metric"` 58 | 59 | // indicates the time at which the metrics were produced 60 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,3,name=timestamp"` 61 | 62 | // indicates the window ([Timestamp-Window, Timestamp]) from 63 | // which these metrics were calculated, when returning rate 64 | // metrics calculated from cumulative metrics (or zero for 65 | // non-calculated instantaneous metrics). 66 | WindowSeconds *int64 `json:"windowSeconds,omitempty" protobuf:"bytes,4,opt,name=windowSeconds"` 67 | 68 | // the value of the metric for this 69 | Value resource.Quantity `json:"value" protobuf:"bytes,5,name=value"` 70 | } 71 | 72 | // AllObjects is a wildcard used to select metrics 73 | // for all objects matching the given label selector 74 | const AllObjects = "*" 75 | 76 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 77 | 78 | // MetricListOptions is used to select metrics by their label selectors 79 | type MetricListOptions struct { 80 | metav1.TypeMeta `json:",inline"` 81 | 82 | // A selector to restrict the list of returned objects by their labels. 83 | // Defaults to everything. 84 | // +optional 85 | LabelSelector string `json:"labelSelector,omitempty" protobuf:"bytes,1,opt,name=labelSelector"` 86 | 87 | // A selector to restrict the list of returned metrics by their labels 88 | // +optional 89 | MetricLabelSelector string `json:"metricLabelSelector,omitempty" protobuf:"bytes,2,opt,name=metricLabelSelector"` 90 | } 91 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/v1beta2/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1beta2 23 | 24 | import ( 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *MetricIdentifier) DeepCopyInto(out *MetricIdentifier) { 31 | *out = *in 32 | if in.Selector != nil { 33 | in, out := &in.Selector, &out.Selector 34 | *out = new(v1.LabelSelector) 35 | (*in).DeepCopyInto(*out) 36 | } 37 | return 38 | } 39 | 40 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricIdentifier. 41 | func (in *MetricIdentifier) DeepCopy() *MetricIdentifier { 42 | if in == nil { 43 | return nil 44 | } 45 | out := new(MetricIdentifier) 46 | in.DeepCopyInto(out) 47 | return out 48 | } 49 | 50 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 51 | func (in *MetricListOptions) DeepCopyInto(out *MetricListOptions) { 52 | *out = *in 53 | out.TypeMeta = in.TypeMeta 54 | return 55 | } 56 | 57 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricListOptions. 58 | func (in *MetricListOptions) DeepCopy() *MetricListOptions { 59 | if in == nil { 60 | return nil 61 | } 62 | out := new(MetricListOptions) 63 | in.DeepCopyInto(out) 64 | return out 65 | } 66 | 67 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 68 | func (in *MetricListOptions) DeepCopyObject() runtime.Object { 69 | if c := in.DeepCopy(); c != nil { 70 | return c 71 | } 72 | return nil 73 | } 74 | 75 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 76 | func (in *MetricValue) DeepCopyInto(out *MetricValue) { 77 | *out = *in 78 | out.TypeMeta = in.TypeMeta 79 | out.DescribedObject = in.DescribedObject 80 | in.Metric.DeepCopyInto(&out.Metric) 81 | in.Timestamp.DeepCopyInto(&out.Timestamp) 82 | if in.WindowSeconds != nil { 83 | in, out := &in.WindowSeconds, &out.WindowSeconds 84 | *out = new(int64) 85 | **out = **in 86 | } 87 | out.Value = in.Value.DeepCopy() 88 | return 89 | } 90 | 91 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricValue. 92 | func (in *MetricValue) DeepCopy() *MetricValue { 93 | if in == nil { 94 | return nil 95 | } 96 | out := new(MetricValue) 97 | in.DeepCopyInto(out) 98 | return out 99 | } 100 | 101 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 102 | func (in *MetricValue) DeepCopyObject() runtime.Object { 103 | if c := in.DeepCopy(); c != nil { 104 | return c 105 | } 106 | return nil 107 | } 108 | 109 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 110 | func (in *MetricValueList) DeepCopyInto(out *MetricValueList) { 111 | *out = *in 112 | out.TypeMeta = in.TypeMeta 113 | in.ListMeta.DeepCopyInto(&out.ListMeta) 114 | if in.Items != nil { 115 | in, out := &in.Items, &out.Items 116 | *out = make([]MetricValue, len(*in)) 117 | for i := range *in { 118 | (*in)[i].DeepCopyInto(&(*out)[i]) 119 | } 120 | } 121 | return 122 | } 123 | 124 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricValueList. 125 | func (in *MetricValueList) DeepCopy() *MetricValueList { 126 | if in == nil { 127 | return nil 128 | } 129 | out := new(MetricValueList) 130 | in.DeepCopyInto(out) 131 | return out 132 | } 133 | 134 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 135 | func (in *MetricValueList) DeepCopyObject() runtime.Object { 136 | if c := in.DeepCopy(); c != nil { 137 | return c 138 | } 139 | return nil 140 | } 141 | -------------------------------------------------------------------------------- /pkg/apis/custom_metrics/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package custom_metrics 23 | 24 | import ( 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *MetricIdentifier) DeepCopyInto(out *MetricIdentifier) { 31 | *out = *in 32 | if in.Selector != nil { 33 | in, out := &in.Selector, &out.Selector 34 | *out = new(v1.LabelSelector) 35 | (*in).DeepCopyInto(*out) 36 | } 37 | return 38 | } 39 | 40 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricIdentifier. 41 | func (in *MetricIdentifier) DeepCopy() *MetricIdentifier { 42 | if in == nil { 43 | return nil 44 | } 45 | out := new(MetricIdentifier) 46 | in.DeepCopyInto(out) 47 | return out 48 | } 49 | 50 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 51 | func (in *MetricListOptions) DeepCopyInto(out *MetricListOptions) { 52 | *out = *in 53 | out.TypeMeta = in.TypeMeta 54 | return 55 | } 56 | 57 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricListOptions. 58 | func (in *MetricListOptions) DeepCopy() *MetricListOptions { 59 | if in == nil { 60 | return nil 61 | } 62 | out := new(MetricListOptions) 63 | in.DeepCopyInto(out) 64 | return out 65 | } 66 | 67 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 68 | func (in *MetricListOptions) DeepCopyObject() runtime.Object { 69 | if c := in.DeepCopy(); c != nil { 70 | return c 71 | } 72 | return nil 73 | } 74 | 75 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 76 | func (in *MetricValue) DeepCopyInto(out *MetricValue) { 77 | *out = *in 78 | out.TypeMeta = in.TypeMeta 79 | out.DescribedObject = in.DescribedObject 80 | in.Metric.DeepCopyInto(&out.Metric) 81 | in.Timestamp.DeepCopyInto(&out.Timestamp) 82 | if in.WindowSeconds != nil { 83 | in, out := &in.WindowSeconds, &out.WindowSeconds 84 | *out = new(int64) 85 | **out = **in 86 | } 87 | out.Value = in.Value.DeepCopy() 88 | return 89 | } 90 | 91 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricValue. 92 | func (in *MetricValue) DeepCopy() *MetricValue { 93 | if in == nil { 94 | return nil 95 | } 96 | out := new(MetricValue) 97 | in.DeepCopyInto(out) 98 | return out 99 | } 100 | 101 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 102 | func (in *MetricValue) DeepCopyObject() runtime.Object { 103 | if c := in.DeepCopy(); c != nil { 104 | return c 105 | } 106 | return nil 107 | } 108 | 109 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 110 | func (in *MetricValueList) DeepCopyInto(out *MetricValueList) { 111 | *out = *in 112 | out.TypeMeta = in.TypeMeta 113 | in.ListMeta.DeepCopyInto(&out.ListMeta) 114 | if in.Items != nil { 115 | in, out := &in.Items, &out.Items 116 | *out = make([]MetricValue, len(*in)) 117 | for i := range *in { 118 | (*in)[i].DeepCopyInto(&(*out)[i]) 119 | } 120 | } 121 | return 122 | } 123 | 124 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricValueList. 125 | func (in *MetricValueList) DeepCopy() *MetricValueList { 126 | if in == nil { 127 | return nil 128 | } 129 | out := new(MetricValueList) 130 | in.DeepCopyInto(out) 131 | return out 132 | } 133 | 134 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 135 | func (in *MetricValueList) DeepCopyObject() runtime.Object { 136 | if c := in.DeepCopy(); c != nil { 137 | return c 138 | } 139 | return nil 140 | } 141 | 142 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 143 | func (in *ObjectReference) DeepCopyInto(out *ObjectReference) { 144 | *out = *in 145 | return 146 | } 147 | 148 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectReference. 149 | func (in *ObjectReference) DeepCopy() *ObjectReference { 150 | if in == nil { 151 | return nil 152 | } 153 | out := new(ObjectReference) 154 | in.DeepCopyInto(out) 155 | return out 156 | } 157 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +groupName=external.metrics.k8s.io 19 | 20 | // Package external_metrics adds support for defining external metrics. 21 | package external_metrics 22 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/install/install.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package install installs the experimental API group, making it available as 18 | // an option to all of the API encoding/decoding machinery. 19 | package install 20 | 21 | import ( 22 | "k8s.io/apimachinery/pkg/runtime" 23 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 24 | "k8s.io/metrics/pkg/apis/external_metrics" 25 | "k8s.io/metrics/pkg/apis/external_metrics/v1beta1" 26 | ) 27 | 28 | // Install registers the API group and adds types to a scheme 29 | func Install(scheme *runtime.Scheme) { 30 | utilruntime.Must(external_metrics.AddToScheme(scheme)) 31 | utilruntime.Must(v1beta1.AddToScheme(scheme)) 32 | utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion)) 33 | } 34 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package external_metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | ) 23 | 24 | // GroupName is the group name use in this package 25 | const GroupName = "external.metrics.k8s.io" 26 | 27 | // SchemeGroupVersion is group version used to register these objects 28 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} 29 | 30 | // Kind takes an unqualified kind and returns back a Group qualified GroupKind 31 | func Kind(kind string) schema.GroupKind { 32 | return SchemeGroupVersion.WithKind(kind).GroupKind() 33 | } 34 | 35 | // Resource takes an unqualified resource and returns back a Group qualified GroupResource 36 | func Resource(resource string) schema.GroupResource { 37 | return SchemeGroupVersion.WithResource(resource).GroupResource() 38 | } 39 | 40 | var ( 41 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 42 | AddToScheme = SchemeBuilder.AddToScheme 43 | ) 44 | 45 | func addKnownTypes(scheme *runtime.Scheme) error { 46 | scheme.AddKnownTypes(SchemeGroupVersion, 47 | &ExternalMetricValue{}, 48 | &ExternalMetricValueList{}, 49 | ) 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package external_metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/api/resource" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 25 | 26 | // a list of values for a given metric for some set labels 27 | type ExternalMetricValueList struct { 28 | metav1.TypeMeta `json:",inline"` 29 | metav1.ListMeta `json:"metadata,omitempty"` 30 | 31 | // value of the metric matching a given set of labels 32 | Items []ExternalMetricValue `json:"items"` 33 | } 34 | 35 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 36 | 37 | // a metric value for external metric 38 | // A single metric value is identified by metric name and a set of string labels. 39 | // For one metric there can be multiple values with different sets of labels. 40 | type ExternalMetricValue struct { 41 | metav1.TypeMeta `json:",inline"` 42 | 43 | // the name of the metric 44 | MetricName string `json:"metricName"` 45 | 46 | // a set of labels that identify a single time series for the metric 47 | MetricLabels map[string]string `json:"metricLabels"` 48 | 49 | // indicates the time at which the metrics were produced 50 | Timestamp metav1.Time `json:"timestamp"` 51 | 52 | // indicates the window ([Timestamp-Window, Timestamp]) from 53 | // which these metrics were calculated, when returning rate 54 | // metrics calculated from cumulative metrics (or zero for 55 | // non-calculated instantaneous metrics). 56 | WindowSeconds *int64 `json:"window,omitempty"` 57 | 58 | // the value of the metric 59 | Value resource.Quantity `json:"value"` 60 | } 61 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/v1beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:protobuf-gen=package 19 | // +k8s:conversion-gen=k8s.io/metrics/pkg/apis/external_metrics 20 | // +k8s:openapi-gen=true 21 | 22 | // Package v1beta1 is the v1beta1 version of the external metrics API. 23 | package v1beta1 24 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/v1beta1/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.metrics.pkg.apis.external_metrics.v1beta1; 23 | 24 | import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; 25 | import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; 26 | import "k8s.io/apimachinery/pkg/runtime/generated.proto"; 27 | import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; 28 | 29 | // Package-wide variables from generator "generated". 30 | option go_package = "k8s.io/metrics/pkg/apis/external_metrics/v1beta1"; 31 | 32 | // ExternalMetricValue is a metric value for external metric 33 | // A single metric value is identified by metric name and a set of string labels. 34 | // For one metric there can be multiple values with different sets of labels. 35 | message ExternalMetricValue { 36 | // the name of the metric 37 | optional string metricName = 1; 38 | 39 | // a set of labels that identify a single time series for the metric 40 | map metricLabels = 2; 41 | 42 | // indicates the time at which the metrics were produced 43 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 3; 44 | 45 | // indicates the window ([Timestamp-Window, Timestamp]) from 46 | // which these metrics were calculated, when returning rate 47 | // metrics calculated from cumulative metrics (or zero for 48 | // non-calculated instantaneous metrics). 49 | optional int64 window = 4; 50 | 51 | // the value of the metric 52 | optional .k8s.io.apimachinery.pkg.api.resource.Quantity value = 5; 53 | } 54 | 55 | // ExternalMetricValueList is a list of values for a given metric for some set labels 56 | message ExternalMetricValueList { 57 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 58 | 59 | // value of the metric matching a given set of labels 60 | repeated ExternalMetricValue items = 2; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/v1beta1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | // GroupName is the group name use in this package 26 | const GroupName = "external.metrics.k8s.io" 27 | 28 | // SchemeGroupVersion is group version used to register these objects 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} 30 | 31 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 32 | func Resource(resource string) schema.GroupResource { 33 | return SchemeGroupVersion.WithResource(resource).GroupResource() 34 | } 35 | 36 | var ( 37 | // SchemeBuilder points to a list of functions added to Scheme. 38 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 39 | localSchemeBuilder = &SchemeBuilder 40 | // AddToScheme applies all the stored functions to the scheme. 41 | AddToScheme = localSchemeBuilder.AddToScheme 42 | ) 43 | 44 | func addKnownTypes(scheme *runtime.Scheme) error { 45 | scheme.AddKnownTypes(SchemeGroupVersion, 46 | &ExternalMetricValue{}, 47 | &ExternalMetricValueList{}, 48 | ) 49 | metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/v1beta1/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/api/resource" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 25 | 26 | // ExternalMetricValueList is a list of values for a given metric for some set labels 27 | type ExternalMetricValueList struct { 28 | metav1.TypeMeta `json:",inline"` 29 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 30 | 31 | // value of the metric matching a given set of labels 32 | Items []ExternalMetricValue `json:"items" protobuf:"bytes,2,rep,name=items"` 33 | } 34 | 35 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 36 | 37 | // ExternalMetricValue is a metric value for external metric 38 | // A single metric value is identified by metric name and a set of string labels. 39 | // For one metric there can be multiple values with different sets of labels. 40 | type ExternalMetricValue struct { 41 | metav1.TypeMeta `json:",inline"` 42 | 43 | // the name of the metric 44 | MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"` 45 | 46 | // a set of labels that identify a single time series for the metric 47 | MetricLabels map[string]string `json:"metricLabels" protobuf:"bytes,2,rep,name=metricLabels"` 48 | 49 | // indicates the time at which the metrics were produced 50 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,3,name=timestamp"` 51 | 52 | // indicates the window ([Timestamp-Window, Timestamp]) from 53 | // which these metrics were calculated, when returning rate 54 | // metrics calculated from cumulative metrics (or zero for 55 | // non-calculated instantaneous metrics). 56 | WindowSeconds *int64 `json:"window,omitempty" protobuf:"bytes,4,opt,name=window"` 57 | 58 | // the value of the metric 59 | Value resource.Quantity `json:"value" protobuf:"bytes,5,name=value"` 60 | } 61 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/v1beta1/zz_generated.conversion.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by conversion-gen. DO NOT EDIT. 21 | 22 | package v1beta1 23 | 24 | import ( 25 | unsafe "unsafe" 26 | 27 | conversion "k8s.io/apimachinery/pkg/conversion" 28 | runtime "k8s.io/apimachinery/pkg/runtime" 29 | externalmetrics "k8s.io/metrics/pkg/apis/external_metrics" 30 | ) 31 | 32 | func init() { 33 | localSchemeBuilder.Register(RegisterConversions) 34 | } 35 | 36 | // RegisterConversions adds conversion functions to the given scheme. 37 | // Public to allow building arbitrary schemes. 38 | func RegisterConversions(s *runtime.Scheme) error { 39 | if err := s.AddGeneratedConversionFunc((*ExternalMetricValue)(nil), (*externalmetrics.ExternalMetricValue)(nil), func(a, b interface{}, scope conversion.Scope) error { 40 | return Convert_v1beta1_ExternalMetricValue_To_external_metrics_ExternalMetricValue(a.(*ExternalMetricValue), b.(*externalmetrics.ExternalMetricValue), scope) 41 | }); err != nil { 42 | return err 43 | } 44 | if err := s.AddGeneratedConversionFunc((*externalmetrics.ExternalMetricValue)(nil), (*ExternalMetricValue)(nil), func(a, b interface{}, scope conversion.Scope) error { 45 | return Convert_external_metrics_ExternalMetricValue_To_v1beta1_ExternalMetricValue(a.(*externalmetrics.ExternalMetricValue), b.(*ExternalMetricValue), scope) 46 | }); err != nil { 47 | return err 48 | } 49 | if err := s.AddGeneratedConversionFunc((*ExternalMetricValueList)(nil), (*externalmetrics.ExternalMetricValueList)(nil), func(a, b interface{}, scope conversion.Scope) error { 50 | return Convert_v1beta1_ExternalMetricValueList_To_external_metrics_ExternalMetricValueList(a.(*ExternalMetricValueList), b.(*externalmetrics.ExternalMetricValueList), scope) 51 | }); err != nil { 52 | return err 53 | } 54 | if err := s.AddGeneratedConversionFunc((*externalmetrics.ExternalMetricValueList)(nil), (*ExternalMetricValueList)(nil), func(a, b interface{}, scope conversion.Scope) error { 55 | return Convert_external_metrics_ExternalMetricValueList_To_v1beta1_ExternalMetricValueList(a.(*externalmetrics.ExternalMetricValueList), b.(*ExternalMetricValueList), scope) 56 | }); err != nil { 57 | return err 58 | } 59 | return nil 60 | } 61 | 62 | func autoConvert_v1beta1_ExternalMetricValue_To_external_metrics_ExternalMetricValue(in *ExternalMetricValue, out *externalmetrics.ExternalMetricValue, s conversion.Scope) error { 63 | out.MetricName = in.MetricName 64 | out.MetricLabels = *(*map[string]string)(unsafe.Pointer(&in.MetricLabels)) 65 | out.Timestamp = in.Timestamp 66 | out.WindowSeconds = (*int64)(unsafe.Pointer(in.WindowSeconds)) 67 | out.Value = in.Value 68 | return nil 69 | } 70 | 71 | // Convert_v1beta1_ExternalMetricValue_To_external_metrics_ExternalMetricValue is an autogenerated conversion function. 72 | func Convert_v1beta1_ExternalMetricValue_To_external_metrics_ExternalMetricValue(in *ExternalMetricValue, out *externalmetrics.ExternalMetricValue, s conversion.Scope) error { 73 | return autoConvert_v1beta1_ExternalMetricValue_To_external_metrics_ExternalMetricValue(in, out, s) 74 | } 75 | 76 | func autoConvert_external_metrics_ExternalMetricValue_To_v1beta1_ExternalMetricValue(in *externalmetrics.ExternalMetricValue, out *ExternalMetricValue, s conversion.Scope) error { 77 | out.MetricName = in.MetricName 78 | out.MetricLabels = *(*map[string]string)(unsafe.Pointer(&in.MetricLabels)) 79 | out.Timestamp = in.Timestamp 80 | out.WindowSeconds = (*int64)(unsafe.Pointer(in.WindowSeconds)) 81 | out.Value = in.Value 82 | return nil 83 | } 84 | 85 | // Convert_external_metrics_ExternalMetricValue_To_v1beta1_ExternalMetricValue is an autogenerated conversion function. 86 | func Convert_external_metrics_ExternalMetricValue_To_v1beta1_ExternalMetricValue(in *externalmetrics.ExternalMetricValue, out *ExternalMetricValue, s conversion.Scope) error { 87 | return autoConvert_external_metrics_ExternalMetricValue_To_v1beta1_ExternalMetricValue(in, out, s) 88 | } 89 | 90 | func autoConvert_v1beta1_ExternalMetricValueList_To_external_metrics_ExternalMetricValueList(in *ExternalMetricValueList, out *externalmetrics.ExternalMetricValueList, s conversion.Scope) error { 91 | out.ListMeta = in.ListMeta 92 | out.Items = *(*[]externalmetrics.ExternalMetricValue)(unsafe.Pointer(&in.Items)) 93 | return nil 94 | } 95 | 96 | // Convert_v1beta1_ExternalMetricValueList_To_external_metrics_ExternalMetricValueList is an autogenerated conversion function. 97 | func Convert_v1beta1_ExternalMetricValueList_To_external_metrics_ExternalMetricValueList(in *ExternalMetricValueList, out *externalmetrics.ExternalMetricValueList, s conversion.Scope) error { 98 | return autoConvert_v1beta1_ExternalMetricValueList_To_external_metrics_ExternalMetricValueList(in, out, s) 99 | } 100 | 101 | func autoConvert_external_metrics_ExternalMetricValueList_To_v1beta1_ExternalMetricValueList(in *externalmetrics.ExternalMetricValueList, out *ExternalMetricValueList, s conversion.Scope) error { 102 | out.ListMeta = in.ListMeta 103 | out.Items = *(*[]ExternalMetricValue)(unsafe.Pointer(&in.Items)) 104 | return nil 105 | } 106 | 107 | // Convert_external_metrics_ExternalMetricValueList_To_v1beta1_ExternalMetricValueList is an autogenerated conversion function. 108 | func Convert_external_metrics_ExternalMetricValueList_To_v1beta1_ExternalMetricValueList(in *externalmetrics.ExternalMetricValueList, out *ExternalMetricValueList, s conversion.Scope) error { 109 | return autoConvert_external_metrics_ExternalMetricValueList_To_v1beta1_ExternalMetricValueList(in, out, s) 110 | } 111 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/v1beta1/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1beta1 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 29 | func (in *ExternalMetricValue) DeepCopyInto(out *ExternalMetricValue) { 30 | *out = *in 31 | out.TypeMeta = in.TypeMeta 32 | if in.MetricLabels != nil { 33 | in, out := &in.MetricLabels, &out.MetricLabels 34 | *out = make(map[string]string, len(*in)) 35 | for key, val := range *in { 36 | (*out)[key] = val 37 | } 38 | } 39 | in.Timestamp.DeepCopyInto(&out.Timestamp) 40 | if in.WindowSeconds != nil { 41 | in, out := &in.WindowSeconds, &out.WindowSeconds 42 | *out = new(int64) 43 | **out = **in 44 | } 45 | out.Value = in.Value.DeepCopy() 46 | return 47 | } 48 | 49 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalMetricValue. 50 | func (in *ExternalMetricValue) DeepCopy() *ExternalMetricValue { 51 | if in == nil { 52 | return nil 53 | } 54 | out := new(ExternalMetricValue) 55 | in.DeepCopyInto(out) 56 | return out 57 | } 58 | 59 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 60 | func (in *ExternalMetricValue) DeepCopyObject() runtime.Object { 61 | if c := in.DeepCopy(); c != nil { 62 | return c 63 | } 64 | return nil 65 | } 66 | 67 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 68 | func (in *ExternalMetricValueList) DeepCopyInto(out *ExternalMetricValueList) { 69 | *out = *in 70 | out.TypeMeta = in.TypeMeta 71 | in.ListMeta.DeepCopyInto(&out.ListMeta) 72 | if in.Items != nil { 73 | in, out := &in.Items, &out.Items 74 | *out = make([]ExternalMetricValue, len(*in)) 75 | for i := range *in { 76 | (*in)[i].DeepCopyInto(&(*out)[i]) 77 | } 78 | } 79 | return 80 | } 81 | 82 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalMetricValueList. 83 | func (in *ExternalMetricValueList) DeepCopy() *ExternalMetricValueList { 84 | if in == nil { 85 | return nil 86 | } 87 | out := new(ExternalMetricValueList) 88 | in.DeepCopyInto(out) 89 | return out 90 | } 91 | 92 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 93 | func (in *ExternalMetricValueList) DeepCopyObject() runtime.Object { 94 | if c := in.DeepCopy(); c != nil { 95 | return c 96 | } 97 | return nil 98 | } 99 | -------------------------------------------------------------------------------- /pkg/apis/external_metrics/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package external_metrics 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 29 | func (in *ExternalMetricValue) DeepCopyInto(out *ExternalMetricValue) { 30 | *out = *in 31 | out.TypeMeta = in.TypeMeta 32 | if in.MetricLabels != nil { 33 | in, out := &in.MetricLabels, &out.MetricLabels 34 | *out = make(map[string]string, len(*in)) 35 | for key, val := range *in { 36 | (*out)[key] = val 37 | } 38 | } 39 | in.Timestamp.DeepCopyInto(&out.Timestamp) 40 | if in.WindowSeconds != nil { 41 | in, out := &in.WindowSeconds, &out.WindowSeconds 42 | *out = new(int64) 43 | **out = **in 44 | } 45 | out.Value = in.Value.DeepCopy() 46 | return 47 | } 48 | 49 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalMetricValue. 50 | func (in *ExternalMetricValue) DeepCopy() *ExternalMetricValue { 51 | if in == nil { 52 | return nil 53 | } 54 | out := new(ExternalMetricValue) 55 | in.DeepCopyInto(out) 56 | return out 57 | } 58 | 59 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 60 | func (in *ExternalMetricValue) DeepCopyObject() runtime.Object { 61 | if c := in.DeepCopy(); c != nil { 62 | return c 63 | } 64 | return nil 65 | } 66 | 67 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 68 | func (in *ExternalMetricValueList) DeepCopyInto(out *ExternalMetricValueList) { 69 | *out = *in 70 | out.TypeMeta = in.TypeMeta 71 | in.ListMeta.DeepCopyInto(&out.ListMeta) 72 | if in.Items != nil { 73 | in, out := &in.Items, &out.Items 74 | *out = make([]ExternalMetricValue, len(*in)) 75 | for i := range *in { 76 | (*in)[i].DeepCopyInto(&(*out)[i]) 77 | } 78 | } 79 | return 80 | } 81 | 82 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalMetricValueList. 83 | func (in *ExternalMetricValueList) DeepCopy() *ExternalMetricValueList { 84 | if in == nil { 85 | return nil 86 | } 87 | out := new(ExternalMetricValueList) 88 | in.DeepCopyInto(out) 89 | return out 90 | } 91 | 92 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 93 | func (in *ExternalMetricValueList) DeepCopyObject() runtime.Object { 94 | if c := in.DeepCopy(); c != nil { 95 | return c 96 | } 97 | return nil 98 | } 99 | -------------------------------------------------------------------------------- /pkg/apis/metrics/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +groupName=metrics.k8s.io 19 | 20 | // Package metrics defines an API for exposing metrics. 21 | package metrics 22 | -------------------------------------------------------------------------------- /pkg/apis/metrics/install/install.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package install installs the experimental API group, making it available as 18 | // an option to all of the API encoding/decoding machinery. 19 | package install 20 | 21 | import ( 22 | "k8s.io/apimachinery/pkg/runtime" 23 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 24 | "k8s.io/metrics/pkg/apis/metrics" 25 | "k8s.io/metrics/pkg/apis/metrics/v1beta1" 26 | ) 27 | 28 | // Install registers the API group and adds types to a scheme 29 | func Install(scheme *runtime.Scheme) { 30 | utilruntime.Must(metrics.AddToScheme(scheme)) 31 | utilruntime.Must(v1beta1.AddToScheme(scheme)) 32 | utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion)) 33 | } 34 | -------------------------------------------------------------------------------- /pkg/apis/metrics/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | ) 23 | 24 | // GroupName is the group name use in this package 25 | const GroupName = "metrics.k8s.io" 26 | 27 | // SchemeGroupVersion is group version used to register these objects 28 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} 29 | 30 | // Kind takes an unqualified kind and returns back a Group qualified GroupKind 31 | func Kind(kind string) schema.GroupKind { 32 | return SchemeGroupVersion.WithKind(kind).GroupKind() 33 | } 34 | 35 | // Resource takes an unqualified resource and returns back a Group qualified GroupResource 36 | func Resource(resource string) schema.GroupResource { 37 | return SchemeGroupVersion.WithResource(resource).GroupResource() 38 | } 39 | 40 | var ( 41 | // SchemeBuilder is the scheme builder with scheme init functions to run for this API package 42 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 43 | // AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme 44 | AddToScheme = SchemeBuilder.AddToScheme 45 | ) 46 | 47 | func addKnownTypes(scheme *runtime.Scheme) error { 48 | scheme.AddKnownTypes(SchemeGroupVersion, 49 | &NodeMetrics{}, 50 | &NodeMetricsList{}, 51 | &PodMetrics{}, 52 | &PodMetricsList{}, 53 | ) 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /pkg/apis/metrics/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package metrics 18 | 19 | import ( 20 | corev1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // +genclient 25 | // +resourceName=nodes 26 | // +genclient:readonly 27 | // +genclient:nonNamespaced 28 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 29 | 30 | // NodeMetrics sets resource usage metrics of a node. 31 | type NodeMetrics struct { 32 | metav1.TypeMeta 33 | // Standard object's metadata. 34 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 35 | // +optional 36 | metav1.ObjectMeta 37 | 38 | // The following fields define time interval from which metrics were 39 | // collected from the interval [Timestamp-Window, Timestamp]. 40 | Timestamp metav1.Time 41 | Window metav1.Duration 42 | 43 | // The memory usage is the memory working set. 44 | Usage corev1.ResourceList 45 | } 46 | 47 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 48 | 49 | // NodeMetricsList is a list of NodeMetrics. 50 | type NodeMetricsList struct { 51 | metav1.TypeMeta 52 | // Standard list metadata. 53 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 54 | metav1.ListMeta 55 | 56 | // List of node metrics. 57 | Items []NodeMetrics 58 | } 59 | 60 | // +genclient 61 | // +resourceName=pods 62 | // +genclient:readonly 63 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 64 | 65 | // PodMetrics sets resource usage metrics of a pod. 66 | type PodMetrics struct { 67 | metav1.TypeMeta 68 | // Standard object's metadata. 69 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 70 | // +optional 71 | metav1.ObjectMeta 72 | 73 | // The following fields define time interval from which metrics were 74 | // collected from the interval [Timestamp-Window, Timestamp]. 75 | Timestamp metav1.Time 76 | Window metav1.Duration 77 | 78 | // Metrics for all containers are collected within the same time window. 79 | Containers []ContainerMetrics 80 | } 81 | 82 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 83 | 84 | // PodMetricsList is a list of PodMetrics. 85 | type PodMetricsList struct { 86 | metav1.TypeMeta 87 | // Standard list metadata. 88 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 89 | metav1.ListMeta 90 | 91 | // List of pod metrics. 92 | Items []PodMetrics 93 | } 94 | 95 | // ContainerMetrics sets resource usage metrics of a container. 96 | type ContainerMetrics struct { 97 | // Container name corresponding to the one from pod.spec.containers. 98 | Name string 99 | // The memory usage is the memory working set. 100 | Usage corev1.ResourceList 101 | } 102 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1alpha1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:protobuf-gen=package 19 | // +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics 20 | // +k8s:openapi-gen=true 21 | // +groupName=metrics.k8s.io 22 | 23 | // Package v1alpha1 is the v1alpha1 version of the metrics API. 24 | package v1alpha1 25 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1alpha1/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.metrics.pkg.apis.metrics.v1alpha1; 23 | 24 | import "k8s.io/api/core/v1/generated.proto"; 25 | import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; 26 | import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; 27 | import "k8s.io/apimachinery/pkg/runtime/generated.proto"; 28 | import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; 29 | 30 | // Package-wide variables from generator "generated". 31 | option go_package = "k8s.io/metrics/pkg/apis/metrics/v1alpha1"; 32 | 33 | // ContainerMetrics sets resource usage metrics of a container. 34 | message ContainerMetrics { 35 | // Container name corresponding to the one from pod.spec.containers. 36 | optional string name = 1; 37 | 38 | // The memory usage is the memory working set. 39 | map usage = 2; 40 | } 41 | 42 | // NodeMetrics sets resource usage metrics of a node. 43 | message NodeMetrics { 44 | // Standard object's metadata. 45 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 46 | // +optional 47 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; 48 | 49 | // The following fields define time interval from which metrics were 50 | // collected from the interval [Timestamp-Window, Timestamp]. 51 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2; 52 | 53 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3; 54 | 55 | // The memory usage is the memory working set. 56 | map usage = 4; 57 | } 58 | 59 | // NodeMetricsList is a list of NodeMetrics. 60 | message NodeMetricsList { 61 | // Standard list metadata. 62 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 63 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 64 | 65 | // List of node metrics. 66 | repeated NodeMetrics items = 2; 67 | } 68 | 69 | // PodMetrics sets resource usage metrics of a pod. 70 | message PodMetrics { 71 | // Standard object's metadata. 72 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 73 | // +optional 74 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; 75 | 76 | // The following fields define time interval from which metrics were 77 | // collected from the interval [Timestamp-Window, Timestamp]. 78 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2; 79 | 80 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3; 81 | 82 | // Metrics for all containers are collected within the same time window. 83 | // +listType=atomic 84 | repeated ContainerMetrics containers = 4; 85 | } 86 | 87 | // PodMetricsList is a list of PodMetrics. 88 | message PodMetricsList { 89 | // Standard list metadata. 90 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 91 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 92 | 93 | // List of pod metrics. 94 | repeated PodMetrics items = 2; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1alpha1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | // GroupName is the group name use in this package 26 | const GroupName = "metrics.k8s.io" 27 | 28 | // SchemeGroupVersion is group version used to register these objects 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} 30 | 31 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 32 | func Resource(resource string) schema.GroupResource { 33 | return SchemeGroupVersion.WithResource(resource).GroupResource() 34 | } 35 | 36 | var ( 37 | // SchemeBuilder points to a list of functions added to Scheme. 38 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 39 | localSchemeBuilder = &SchemeBuilder 40 | // AddToScheme applies all the stored functions to the scheme. 41 | AddToScheme = SchemeBuilder.AddToScheme 42 | ) 43 | 44 | func addKnownTypes(scheme *runtime.Scheme) error { 45 | scheme.AddKnownTypes(SchemeGroupVersion, 46 | &NodeMetrics{}, 47 | &NodeMetricsList{}, 48 | &PodMetrics{}, 49 | &PodMetricsList{}, 50 | ) 51 | metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1alpha1/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | v1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // +genclient 25 | // +resourceName=nodes 26 | // +genclient:readonly 27 | // +genclient:nonNamespaced 28 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 29 | 30 | // NodeMetrics sets resource usage metrics of a node. 31 | type NodeMetrics struct { 32 | metav1.TypeMeta `json:",inline"` 33 | // Standard object's metadata. 34 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 35 | // +optional 36 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 37 | 38 | // The following fields define time interval from which metrics were 39 | // collected from the interval [Timestamp-Window, Timestamp]. 40 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` 41 | Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` 42 | 43 | // The memory usage is the memory working set. 44 | 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"` 45 | } 46 | 47 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 48 | 49 | // NodeMetricsList is a list of NodeMetrics. 50 | type NodeMetricsList struct { 51 | metav1.TypeMeta `json:",inline"` 52 | // Standard list metadata. 53 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 54 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 55 | 56 | // List of node metrics. 57 | Items []NodeMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` 58 | } 59 | 60 | // +genclient 61 | // +resourceName=pods 62 | // +genclient:readonly 63 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 64 | 65 | // PodMetrics sets resource usage metrics of a pod. 66 | type PodMetrics struct { 67 | metav1.TypeMeta `json:",inline"` 68 | // Standard object's metadata. 69 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 70 | // +optional 71 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 72 | 73 | // The following fields define time interval from which metrics were 74 | // collected from the interval [Timestamp-Window, Timestamp]. 75 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` 76 | Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` 77 | 78 | // Metrics for all containers are collected within the same time window. 79 | // +listType=atomic 80 | Containers []ContainerMetrics `json:"containers" protobuf:"bytes,4,rep,name=containers"` 81 | } 82 | 83 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 84 | 85 | // PodMetricsList is a list of PodMetrics. 86 | type PodMetricsList struct { 87 | metav1.TypeMeta `json:",inline"` 88 | // Standard list metadata. 89 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 90 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 91 | 92 | // List of pod metrics. 93 | Items []PodMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` 94 | } 95 | 96 | // ContainerMetrics sets resource usage metrics of a container. 97 | type ContainerMetrics struct { 98 | // Container name corresponding to the one from pod.spec.containers. 99 | Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 100 | // The memory usage is the memory working set. 101 | 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"` 102 | } 103 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1alpha1/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1alpha1 23 | 24 | import ( 25 | v1 "k8s.io/api/core/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *ContainerMetrics) DeepCopyInto(out *ContainerMetrics) { 31 | *out = *in 32 | if in.Usage != nil { 33 | in, out := &in.Usage, &out.Usage 34 | *out = make(v1.ResourceList, len(*in)) 35 | for key, val := range *in { 36 | (*out)[key] = val.DeepCopy() 37 | } 38 | } 39 | return 40 | } 41 | 42 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerMetrics. 43 | func (in *ContainerMetrics) DeepCopy() *ContainerMetrics { 44 | if in == nil { 45 | return nil 46 | } 47 | out := new(ContainerMetrics) 48 | in.DeepCopyInto(out) 49 | return out 50 | } 51 | 52 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 53 | func (in *NodeMetrics) DeepCopyInto(out *NodeMetrics) { 54 | *out = *in 55 | out.TypeMeta = in.TypeMeta 56 | in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 57 | in.Timestamp.DeepCopyInto(&out.Timestamp) 58 | out.Window = in.Window 59 | if in.Usage != nil { 60 | in, out := &in.Usage, &out.Usage 61 | *out = make(v1.ResourceList, len(*in)) 62 | for key, val := range *in { 63 | (*out)[key] = val.DeepCopy() 64 | } 65 | } 66 | return 67 | } 68 | 69 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetrics. 70 | func (in *NodeMetrics) DeepCopy() *NodeMetrics { 71 | if in == nil { 72 | return nil 73 | } 74 | out := new(NodeMetrics) 75 | in.DeepCopyInto(out) 76 | return out 77 | } 78 | 79 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 80 | func (in *NodeMetrics) DeepCopyObject() runtime.Object { 81 | if c := in.DeepCopy(); c != nil { 82 | return c 83 | } 84 | return nil 85 | } 86 | 87 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 88 | func (in *NodeMetricsList) DeepCopyInto(out *NodeMetricsList) { 89 | *out = *in 90 | out.TypeMeta = in.TypeMeta 91 | in.ListMeta.DeepCopyInto(&out.ListMeta) 92 | if in.Items != nil { 93 | in, out := &in.Items, &out.Items 94 | *out = make([]NodeMetrics, len(*in)) 95 | for i := range *in { 96 | (*in)[i].DeepCopyInto(&(*out)[i]) 97 | } 98 | } 99 | return 100 | } 101 | 102 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricsList. 103 | func (in *NodeMetricsList) DeepCopy() *NodeMetricsList { 104 | if in == nil { 105 | return nil 106 | } 107 | out := new(NodeMetricsList) 108 | in.DeepCopyInto(out) 109 | return out 110 | } 111 | 112 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 113 | func (in *NodeMetricsList) DeepCopyObject() runtime.Object { 114 | if c := in.DeepCopy(); c != nil { 115 | return c 116 | } 117 | return nil 118 | } 119 | 120 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 121 | func (in *PodMetrics) DeepCopyInto(out *PodMetrics) { 122 | *out = *in 123 | out.TypeMeta = in.TypeMeta 124 | in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 125 | in.Timestamp.DeepCopyInto(&out.Timestamp) 126 | out.Window = in.Window 127 | if in.Containers != nil { 128 | in, out := &in.Containers, &out.Containers 129 | *out = make([]ContainerMetrics, len(*in)) 130 | for i := range *in { 131 | (*in)[i].DeepCopyInto(&(*out)[i]) 132 | } 133 | } 134 | return 135 | } 136 | 137 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetrics. 138 | func (in *PodMetrics) DeepCopy() *PodMetrics { 139 | if in == nil { 140 | return nil 141 | } 142 | out := new(PodMetrics) 143 | in.DeepCopyInto(out) 144 | return out 145 | } 146 | 147 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 148 | func (in *PodMetrics) DeepCopyObject() runtime.Object { 149 | if c := in.DeepCopy(); c != nil { 150 | return c 151 | } 152 | return nil 153 | } 154 | 155 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 156 | func (in *PodMetricsList) DeepCopyInto(out *PodMetricsList) { 157 | *out = *in 158 | out.TypeMeta = in.TypeMeta 159 | in.ListMeta.DeepCopyInto(&out.ListMeta) 160 | if in.Items != nil { 161 | in, out := &in.Items, &out.Items 162 | *out = make([]PodMetrics, len(*in)) 163 | for i := range *in { 164 | (*in)[i].DeepCopyInto(&(*out)[i]) 165 | } 166 | } 167 | return 168 | } 169 | 170 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricsList. 171 | func (in *PodMetricsList) DeepCopy() *PodMetricsList { 172 | if in == nil { 173 | return nil 174 | } 175 | out := new(PodMetricsList) 176 | in.DeepCopyInto(out) 177 | return out 178 | } 179 | 180 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 181 | func (in *PodMetricsList) DeepCopyObject() runtime.Object { 182 | if c := in.DeepCopy(); c != nil { 183 | return c 184 | } 185 | return nil 186 | } 187 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:protobuf-gen=package 19 | // +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics 20 | // +k8s:openapi-gen=true 21 | // +groupName=metrics.k8s.io 22 | 23 | // Package v1beta1 is the v1beta1 version of the metrics API. 24 | package v1beta1 25 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1beta1/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.metrics.pkg.apis.metrics.v1beta1; 23 | 24 | import "k8s.io/api/core/v1/generated.proto"; 25 | import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; 26 | import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; 27 | import "k8s.io/apimachinery/pkg/runtime/generated.proto"; 28 | import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; 29 | 30 | // Package-wide variables from generator "generated". 31 | option go_package = "k8s.io/metrics/pkg/apis/metrics/v1beta1"; 32 | 33 | // ContainerMetrics sets resource usage metrics of a container. 34 | message ContainerMetrics { 35 | // Container name corresponding to the one from pod.spec.containers. 36 | optional string name = 1; 37 | 38 | // The memory usage is the memory working set. 39 | map usage = 2; 40 | } 41 | 42 | // NodeMetrics sets resource usage metrics of a node. 43 | message NodeMetrics { 44 | // Standard object's metadata. 45 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 46 | // +optional 47 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; 48 | 49 | // The following fields define time interval from which metrics were 50 | // collected from the interval [Timestamp-Window, Timestamp]. 51 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2; 52 | 53 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3; 54 | 55 | // The memory usage is the memory working set. 56 | map usage = 4; 57 | } 58 | 59 | // NodeMetricsList is a list of NodeMetrics. 60 | message NodeMetricsList { 61 | // Standard list metadata. 62 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 63 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 64 | 65 | // List of node metrics. 66 | repeated NodeMetrics items = 2; 67 | } 68 | 69 | // PodMetrics sets resource usage metrics of a pod. 70 | message PodMetrics { 71 | // Standard object's metadata. 72 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 73 | // +optional 74 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; 75 | 76 | // The following fields define time interval from which metrics were 77 | // collected from the interval [Timestamp-Window, Timestamp]. 78 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2; 79 | 80 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3; 81 | 82 | // Metrics for all containers are collected within the same time window. 83 | // +listType=atomic 84 | repeated ContainerMetrics containers = 4; 85 | } 86 | 87 | // PodMetricsList is a list of PodMetrics. 88 | message PodMetricsList { 89 | // Standard list metadata. 90 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 91 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; 92 | 93 | // List of pod metrics. 94 | repeated PodMetrics items = 2; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1beta1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | // GroupName is the group name use in this package 26 | const GroupName = "metrics.k8s.io" 27 | 28 | // SchemeGroupVersion is group version used to register these objects 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} 30 | 31 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 32 | func Resource(resource string) schema.GroupResource { 33 | return SchemeGroupVersion.WithResource(resource).GroupResource() 34 | } 35 | 36 | var ( 37 | // SchemeBuilder points to a list of functions added to Scheme. 38 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 39 | localSchemeBuilder = &SchemeBuilder 40 | // AddToScheme applies all the stored functions to the scheme. 41 | AddToScheme = SchemeBuilder.AddToScheme 42 | ) 43 | 44 | func addKnownTypes(scheme *runtime.Scheme) error { 45 | scheme.AddKnownTypes(SchemeGroupVersion, 46 | &NodeMetrics{}, 47 | &NodeMetricsList{}, 48 | &PodMetrics{}, 49 | &PodMetricsList{}, 50 | ) 51 | metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1beta1/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | v1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // +genclient 25 | // +resourceName=nodes 26 | // +genclient:readonly 27 | // +genclient:nonNamespaced 28 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 29 | 30 | // NodeMetrics sets resource usage metrics of a node. 31 | type NodeMetrics struct { 32 | metav1.TypeMeta `json:",inline"` 33 | // Standard object's metadata. 34 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 35 | // +optional 36 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 37 | 38 | // The following fields define time interval from which metrics were 39 | // collected from the interval [Timestamp-Window, Timestamp]. 40 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` 41 | Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` 42 | 43 | // The memory usage is the memory working set. 44 | 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"` 45 | } 46 | 47 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 48 | 49 | // NodeMetricsList is a list of NodeMetrics. 50 | type NodeMetricsList struct { 51 | metav1.TypeMeta `json:",inline"` 52 | // Standard list metadata. 53 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 54 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 55 | 56 | // List of node metrics. 57 | Items []NodeMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` 58 | } 59 | 60 | // +genclient 61 | // +resourceName=pods 62 | // +genclient:readonly 63 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 64 | 65 | // PodMetrics sets resource usage metrics of a pod. 66 | type PodMetrics struct { 67 | metav1.TypeMeta `json:",inline"` 68 | // Standard object's metadata. 69 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 70 | // +optional 71 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 72 | 73 | // The following fields define time interval from which metrics were 74 | // collected from the interval [Timestamp-Window, Timestamp]. 75 | Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` 76 | Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` 77 | 78 | // Metrics for all containers are collected within the same time window. 79 | // +listType=atomic 80 | Containers []ContainerMetrics `json:"containers" protobuf:"bytes,4,rep,name=containers"` 81 | } 82 | 83 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 84 | 85 | // PodMetricsList is a list of PodMetrics. 86 | type PodMetricsList struct { 87 | metav1.TypeMeta `json:",inline"` 88 | // Standard list metadata. 89 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 90 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 91 | 92 | // List of pod metrics. 93 | Items []PodMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` 94 | } 95 | 96 | // ContainerMetrics sets resource usage metrics of a container. 97 | type ContainerMetrics struct { 98 | // Container name corresponding to the one from pod.spec.containers. 99 | Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 100 | // The memory usage is the memory working set. 101 | 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"` 102 | } 103 | -------------------------------------------------------------------------------- /pkg/apis/metrics/v1beta1/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1beta1 23 | 24 | import ( 25 | v1 "k8s.io/api/core/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *ContainerMetrics) DeepCopyInto(out *ContainerMetrics) { 31 | *out = *in 32 | if in.Usage != nil { 33 | in, out := &in.Usage, &out.Usage 34 | *out = make(v1.ResourceList, len(*in)) 35 | for key, val := range *in { 36 | (*out)[key] = val.DeepCopy() 37 | } 38 | } 39 | return 40 | } 41 | 42 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerMetrics. 43 | func (in *ContainerMetrics) DeepCopy() *ContainerMetrics { 44 | if in == nil { 45 | return nil 46 | } 47 | out := new(ContainerMetrics) 48 | in.DeepCopyInto(out) 49 | return out 50 | } 51 | 52 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 53 | func (in *NodeMetrics) DeepCopyInto(out *NodeMetrics) { 54 | *out = *in 55 | out.TypeMeta = in.TypeMeta 56 | in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 57 | in.Timestamp.DeepCopyInto(&out.Timestamp) 58 | out.Window = in.Window 59 | if in.Usage != nil { 60 | in, out := &in.Usage, &out.Usage 61 | *out = make(v1.ResourceList, len(*in)) 62 | for key, val := range *in { 63 | (*out)[key] = val.DeepCopy() 64 | } 65 | } 66 | return 67 | } 68 | 69 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetrics. 70 | func (in *NodeMetrics) DeepCopy() *NodeMetrics { 71 | if in == nil { 72 | return nil 73 | } 74 | out := new(NodeMetrics) 75 | in.DeepCopyInto(out) 76 | return out 77 | } 78 | 79 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 80 | func (in *NodeMetrics) DeepCopyObject() runtime.Object { 81 | if c := in.DeepCopy(); c != nil { 82 | return c 83 | } 84 | return nil 85 | } 86 | 87 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 88 | func (in *NodeMetricsList) DeepCopyInto(out *NodeMetricsList) { 89 | *out = *in 90 | out.TypeMeta = in.TypeMeta 91 | in.ListMeta.DeepCopyInto(&out.ListMeta) 92 | if in.Items != nil { 93 | in, out := &in.Items, &out.Items 94 | *out = make([]NodeMetrics, len(*in)) 95 | for i := range *in { 96 | (*in)[i].DeepCopyInto(&(*out)[i]) 97 | } 98 | } 99 | return 100 | } 101 | 102 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricsList. 103 | func (in *NodeMetricsList) DeepCopy() *NodeMetricsList { 104 | if in == nil { 105 | return nil 106 | } 107 | out := new(NodeMetricsList) 108 | in.DeepCopyInto(out) 109 | return out 110 | } 111 | 112 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 113 | func (in *NodeMetricsList) DeepCopyObject() runtime.Object { 114 | if c := in.DeepCopy(); c != nil { 115 | return c 116 | } 117 | return nil 118 | } 119 | 120 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 121 | func (in *PodMetrics) DeepCopyInto(out *PodMetrics) { 122 | *out = *in 123 | out.TypeMeta = in.TypeMeta 124 | in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 125 | in.Timestamp.DeepCopyInto(&out.Timestamp) 126 | out.Window = in.Window 127 | if in.Containers != nil { 128 | in, out := &in.Containers, &out.Containers 129 | *out = make([]ContainerMetrics, len(*in)) 130 | for i := range *in { 131 | (*in)[i].DeepCopyInto(&(*out)[i]) 132 | } 133 | } 134 | return 135 | } 136 | 137 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetrics. 138 | func (in *PodMetrics) DeepCopy() *PodMetrics { 139 | if in == nil { 140 | return nil 141 | } 142 | out := new(PodMetrics) 143 | in.DeepCopyInto(out) 144 | return out 145 | } 146 | 147 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 148 | func (in *PodMetrics) DeepCopyObject() runtime.Object { 149 | if c := in.DeepCopy(); c != nil { 150 | return c 151 | } 152 | return nil 153 | } 154 | 155 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 156 | func (in *PodMetricsList) DeepCopyInto(out *PodMetricsList) { 157 | *out = *in 158 | out.TypeMeta = in.TypeMeta 159 | in.ListMeta.DeepCopyInto(&out.ListMeta) 160 | if in.Items != nil { 161 | in, out := &in.Items, &out.Items 162 | *out = make([]PodMetrics, len(*in)) 163 | for i := range *in { 164 | (*in)[i].DeepCopyInto(&(*out)[i]) 165 | } 166 | } 167 | return 168 | } 169 | 170 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricsList. 171 | func (in *PodMetricsList) DeepCopy() *PodMetricsList { 172 | if in == nil { 173 | return nil 174 | } 175 | out := new(PodMetricsList) 176 | in.DeepCopyInto(out) 177 | return out 178 | } 179 | 180 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 181 | func (in *PodMetricsList) DeepCopyObject() runtime.Object { 182 | if c := in.DeepCopy(); c != nil { 183 | return c 184 | } 185 | return nil 186 | } 187 | -------------------------------------------------------------------------------- /pkg/apis/metrics/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package metrics 23 | 24 | import ( 25 | v1 "k8s.io/api/core/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *ContainerMetrics) DeepCopyInto(out *ContainerMetrics) { 31 | *out = *in 32 | if in.Usage != nil { 33 | in, out := &in.Usage, &out.Usage 34 | *out = make(v1.ResourceList, len(*in)) 35 | for key, val := range *in { 36 | (*out)[key] = val.DeepCopy() 37 | } 38 | } 39 | return 40 | } 41 | 42 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerMetrics. 43 | func (in *ContainerMetrics) DeepCopy() *ContainerMetrics { 44 | if in == nil { 45 | return nil 46 | } 47 | out := new(ContainerMetrics) 48 | in.DeepCopyInto(out) 49 | return out 50 | } 51 | 52 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 53 | func (in *NodeMetrics) DeepCopyInto(out *NodeMetrics) { 54 | *out = *in 55 | out.TypeMeta = in.TypeMeta 56 | in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 57 | in.Timestamp.DeepCopyInto(&out.Timestamp) 58 | out.Window = in.Window 59 | if in.Usage != nil { 60 | in, out := &in.Usage, &out.Usage 61 | *out = make(v1.ResourceList, len(*in)) 62 | for key, val := range *in { 63 | (*out)[key] = val.DeepCopy() 64 | } 65 | } 66 | return 67 | } 68 | 69 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetrics. 70 | func (in *NodeMetrics) DeepCopy() *NodeMetrics { 71 | if in == nil { 72 | return nil 73 | } 74 | out := new(NodeMetrics) 75 | in.DeepCopyInto(out) 76 | return out 77 | } 78 | 79 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 80 | func (in *NodeMetrics) DeepCopyObject() runtime.Object { 81 | if c := in.DeepCopy(); c != nil { 82 | return c 83 | } 84 | return nil 85 | } 86 | 87 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 88 | func (in *NodeMetricsList) DeepCopyInto(out *NodeMetricsList) { 89 | *out = *in 90 | out.TypeMeta = in.TypeMeta 91 | in.ListMeta.DeepCopyInto(&out.ListMeta) 92 | if in.Items != nil { 93 | in, out := &in.Items, &out.Items 94 | *out = make([]NodeMetrics, len(*in)) 95 | for i := range *in { 96 | (*in)[i].DeepCopyInto(&(*out)[i]) 97 | } 98 | } 99 | return 100 | } 101 | 102 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricsList. 103 | func (in *NodeMetricsList) DeepCopy() *NodeMetricsList { 104 | if in == nil { 105 | return nil 106 | } 107 | out := new(NodeMetricsList) 108 | in.DeepCopyInto(out) 109 | return out 110 | } 111 | 112 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 113 | func (in *NodeMetricsList) DeepCopyObject() runtime.Object { 114 | if c := in.DeepCopy(); c != nil { 115 | return c 116 | } 117 | return nil 118 | } 119 | 120 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 121 | func (in *PodMetrics) DeepCopyInto(out *PodMetrics) { 122 | *out = *in 123 | out.TypeMeta = in.TypeMeta 124 | in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 125 | in.Timestamp.DeepCopyInto(&out.Timestamp) 126 | out.Window = in.Window 127 | if in.Containers != nil { 128 | in, out := &in.Containers, &out.Containers 129 | *out = make([]ContainerMetrics, len(*in)) 130 | for i := range *in { 131 | (*in)[i].DeepCopyInto(&(*out)[i]) 132 | } 133 | } 134 | return 135 | } 136 | 137 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetrics. 138 | func (in *PodMetrics) DeepCopy() *PodMetrics { 139 | if in == nil { 140 | return nil 141 | } 142 | out := new(PodMetrics) 143 | in.DeepCopyInto(out) 144 | return out 145 | } 146 | 147 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 148 | func (in *PodMetrics) DeepCopyObject() runtime.Object { 149 | if c := in.DeepCopy(); c != nil { 150 | return c 151 | } 152 | return nil 153 | } 154 | 155 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 156 | func (in *PodMetricsList) DeepCopyInto(out *PodMetricsList) { 157 | *out = *in 158 | out.TypeMeta = in.TypeMeta 159 | in.ListMeta.DeepCopyInto(&out.ListMeta) 160 | if in.Items != nil { 161 | in, out := &in.Items, &out.Items 162 | *out = make([]PodMetrics, len(*in)) 163 | for i := range *in { 164 | (*in)[i].DeepCopyInto(&(*out)[i]) 165 | } 166 | } 167 | return 168 | } 169 | 170 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricsList. 171 | func (in *PodMetricsList) DeepCopy() *PodMetricsList { 172 | if in == nil { 173 | return nil 174 | } 175 | out := new(PodMetricsList) 176 | in.DeepCopyInto(out) 177 | return out 178 | } 179 | 180 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 181 | func (in *PodMetricsList) DeepCopyObject() runtime.Object { 182 | if c := in.DeepCopy(); c != nil { 183 | return c 184 | } 185 | return nil 186 | } 187 | -------------------------------------------------------------------------------- /pkg/apis/roundtrip_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package testing 18 | 19 | import ( 20 | "math/rand" 21 | "testing" 22 | 23 | custommetrics "k8s.io/metrics/pkg/apis/custom_metrics" 24 | custommetricsv1beta1 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1" 25 | custommetricsv1beta2 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 26 | externalmetrics "k8s.io/metrics/pkg/apis/external_metrics" 27 | externalmetricsv1beta1 "k8s.io/metrics/pkg/apis/external_metrics/v1beta1" 28 | metrics "k8s.io/metrics/pkg/apis/metrics" 29 | metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 30 | metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 31 | 32 | "github.com/stretchr/testify/require" 33 | "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" 34 | "k8s.io/apimachinery/pkg/api/apitesting/roundtrip" 35 | genericfuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer" 36 | "k8s.io/apimachinery/pkg/runtime" 37 | "k8s.io/apimachinery/pkg/runtime/serializer" 38 | ) 39 | 40 | var groups = []runtime.SchemeBuilder{ 41 | custommetrics.SchemeBuilder, 42 | custommetricsv1beta1.SchemeBuilder, 43 | custommetricsv1beta2.SchemeBuilder, 44 | externalmetrics.SchemeBuilder, 45 | externalmetricsv1beta1.SchemeBuilder, 46 | metrics.SchemeBuilder, 47 | metricsv1alpha1.SchemeBuilder, 48 | metricsv1beta1.SchemeBuilder, 49 | } 50 | 51 | func TestRoundTripTypes(t *testing.T) { 52 | scheme := runtime.NewScheme() 53 | codecs := serializer.NewCodecFactory(scheme) 54 | for _, builder := range groups { 55 | require.NoError(t, builder.AddToScheme(scheme)) 56 | } 57 | seed := rand.Int63() 58 | // I'm only using the generic fuzzer funcs, but at some point in time we might need to 59 | // switch to specialized. For now we're happy with the current serialization test. 60 | fuzzer := fuzzer.FuzzerFor(genericfuzzer.Funcs, rand.NewSource(seed), codecs) 61 | 62 | roundtrip.RoundTripExternalTypes(t, scheme, codecs, fuzzer, nil) 63 | roundtrip.RoundTripTypes(t, scheme, codecs, fuzzer, nil) 64 | } 65 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/clientset.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package versioned 20 | 21 | import ( 22 | fmt "fmt" 23 | http "net/http" 24 | 25 | discovery "k8s.io/client-go/discovery" 26 | rest "k8s.io/client-go/rest" 27 | flowcontrol "k8s.io/client-go/util/flowcontrol" 28 | metricsv1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1" 29 | metricsv1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" 30 | ) 31 | 32 | type Interface interface { 33 | Discovery() discovery.DiscoveryInterface 34 | MetricsV1alpha1() metricsv1alpha1.MetricsV1alpha1Interface 35 | MetricsV1beta1() metricsv1beta1.MetricsV1beta1Interface 36 | } 37 | 38 | // Clientset contains the clients for groups. 39 | type Clientset struct { 40 | *discovery.DiscoveryClient 41 | metricsV1alpha1 *metricsv1alpha1.MetricsV1alpha1Client 42 | metricsV1beta1 *metricsv1beta1.MetricsV1beta1Client 43 | } 44 | 45 | // MetricsV1alpha1 retrieves the MetricsV1alpha1Client 46 | func (c *Clientset) MetricsV1alpha1() metricsv1alpha1.MetricsV1alpha1Interface { 47 | return c.metricsV1alpha1 48 | } 49 | 50 | // MetricsV1beta1 retrieves the MetricsV1beta1Client 51 | func (c *Clientset) MetricsV1beta1() metricsv1beta1.MetricsV1beta1Interface { 52 | return c.metricsV1beta1 53 | } 54 | 55 | // Discovery retrieves the DiscoveryClient 56 | func (c *Clientset) Discovery() discovery.DiscoveryInterface { 57 | if c == nil { 58 | return nil 59 | } 60 | return c.DiscoveryClient 61 | } 62 | 63 | // NewForConfig creates a new Clientset for the given config. 64 | // If config's RateLimiter is not set and QPS and Burst are acceptable, 65 | // NewForConfig will generate a rate-limiter in configShallowCopy. 66 | // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), 67 | // where httpClient was generated with rest.HTTPClientFor(c). 68 | func NewForConfig(c *rest.Config) (*Clientset, error) { 69 | configShallowCopy := *c 70 | 71 | if configShallowCopy.UserAgent == "" { 72 | configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() 73 | } 74 | 75 | // share the transport between all clients 76 | httpClient, err := rest.HTTPClientFor(&configShallowCopy) 77 | if err != nil { 78 | return nil, err 79 | } 80 | 81 | return NewForConfigAndClient(&configShallowCopy, httpClient) 82 | } 83 | 84 | // NewForConfigAndClient creates a new Clientset for the given config and http client. 85 | // Note the http client provided takes precedence over the configured transport values. 86 | // If config's RateLimiter is not set and QPS and Burst are acceptable, 87 | // NewForConfigAndClient will generate a rate-limiter in configShallowCopy. 88 | func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { 89 | configShallowCopy := *c 90 | if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 91 | if configShallowCopy.Burst <= 0 { 92 | 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") 93 | } 94 | configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 95 | } 96 | 97 | var cs Clientset 98 | var err error 99 | cs.metricsV1alpha1, err = metricsv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) 100 | if err != nil { 101 | return nil, err 102 | } 103 | cs.metricsV1beta1, err = metricsv1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) 104 | if err != nil { 105 | return nil, err 106 | } 107 | 108 | cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) 109 | if err != nil { 110 | return nil, err 111 | } 112 | return &cs, nil 113 | } 114 | 115 | // NewForConfigOrDie creates a new Clientset for the given config and 116 | // panics if there is an error in the config. 117 | func NewForConfigOrDie(c *rest.Config) *Clientset { 118 | cs, err := NewForConfig(c) 119 | if err != nil { 120 | panic(err) 121 | } 122 | return cs 123 | } 124 | 125 | // New creates a new Clientset for the given RESTClient. 126 | func New(c rest.Interface) *Clientset { 127 | var cs Clientset 128 | cs.metricsV1alpha1 = metricsv1alpha1.New(c) 129 | cs.metricsV1beta1 = metricsv1beta1.New(c) 130 | 131 | cs.DiscoveryClient = discovery.NewDiscoveryClient(c) 132 | return &cs 133 | } 134 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/clientset_generated.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | "k8s.io/apimachinery/pkg/runtime" 24 | "k8s.io/apimachinery/pkg/watch" 25 | "k8s.io/client-go/discovery" 26 | fakediscovery "k8s.io/client-go/discovery/fake" 27 | "k8s.io/client-go/testing" 28 | clientset "k8s.io/metrics/pkg/client/clientset/versioned" 29 | metricsv1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1" 30 | fakemetricsv1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1/fake" 31 | metricsv1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" 32 | fakemetricsv1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/fake" 33 | ) 34 | 35 | // NewSimpleClientset returns a clientset that will respond with the provided objects. 36 | // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, 37 | // without applying any field management, validations and/or defaults. It shouldn't be considered a replacement 38 | // for a real clientset and is mostly useful in simple unit tests. 39 | // 40 | // DEPRECATED: NewClientset replaces this with support for field management, which significantly improves 41 | // server side apply testing. NewClientset is only available when apply configurations are generated (e.g. 42 | // via --with-applyconfig). 43 | func NewSimpleClientset(objects ...runtime.Object) *Clientset { 44 | o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) 45 | for _, obj := range objects { 46 | if err := o.Add(obj); err != nil { 47 | panic(err) 48 | } 49 | } 50 | 51 | cs := &Clientset{tracker: o} 52 | cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} 53 | cs.AddReactor("*", "*", testing.ObjectReaction(o)) 54 | cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { 55 | var opts metav1.ListOptions 56 | if watchActcion, ok := action.(testing.WatchActionImpl); ok { 57 | opts = watchActcion.ListOptions 58 | } 59 | gvr := action.GetResource() 60 | ns := action.GetNamespace() 61 | watch, err := o.Watch(gvr, ns, opts) 62 | if err != nil { 63 | return false, nil, err 64 | } 65 | return true, watch, nil 66 | }) 67 | 68 | return cs 69 | } 70 | 71 | // Clientset implements clientset.Interface. Meant to be embedded into a 72 | // struct to get a default implementation. This makes faking out just the method 73 | // you want to test easier. 74 | type Clientset struct { 75 | testing.Fake 76 | discovery *fakediscovery.FakeDiscovery 77 | tracker testing.ObjectTracker 78 | } 79 | 80 | func (c *Clientset) Discovery() discovery.DiscoveryInterface { 81 | return c.discovery 82 | } 83 | 84 | func (c *Clientset) Tracker() testing.ObjectTracker { 85 | return c.tracker 86 | } 87 | 88 | var ( 89 | _ clientset.Interface = &Clientset{} 90 | _ testing.FakeClient = &Clientset{} 91 | ) 92 | 93 | // MetricsV1alpha1 retrieves the MetricsV1alpha1Client 94 | func (c *Clientset) MetricsV1alpha1() metricsv1alpha1.MetricsV1alpha1Interface { 95 | return &fakemetricsv1alpha1.FakeMetricsV1alpha1{Fake: &c.Fake} 96 | } 97 | 98 | // MetricsV1beta1 retrieves the MetricsV1beta1Client 99 | func (c *Clientset) MetricsV1beta1() metricsv1beta1.MetricsV1beta1Interface { 100 | return &fakemetricsv1beta1.FakeMetricsV1beta1{Fake: &c.Fake} 101 | } 102 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated fake clientset. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | runtime "k8s.io/apimachinery/pkg/runtime" 24 | schema "k8s.io/apimachinery/pkg/runtime/schema" 25 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 26 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 27 | metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 28 | metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 29 | ) 30 | 31 | var scheme = runtime.NewScheme() 32 | var codecs = serializer.NewCodecFactory(scheme) 33 | 34 | var localSchemeBuilder = runtime.SchemeBuilder{ 35 | metricsv1alpha1.AddToScheme, 36 | metricsv1beta1.AddToScheme, 37 | } 38 | 39 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 40 | // of clientsets, like in: 41 | // 42 | // import ( 43 | // "k8s.io/client-go/kubernetes" 44 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 45 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 46 | // ) 47 | // 48 | // kclientset, _ := kubernetes.NewForConfig(c) 49 | // _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 50 | // 51 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 52 | // correctly. 53 | var AddToScheme = localSchemeBuilder.AddToScheme 54 | 55 | func init() { 56 | v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) 57 | utilruntime.Must(AddToScheme(scheme)) 58 | } 59 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/scheme/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package contains the scheme of the automatically generated clientset. 20 | package scheme 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/scheme/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package scheme 20 | 21 | import ( 22 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | runtime "k8s.io/apimachinery/pkg/runtime" 24 | schema "k8s.io/apimachinery/pkg/runtime/schema" 25 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 26 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 27 | metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 28 | metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 29 | ) 30 | 31 | var Scheme = runtime.NewScheme() 32 | var Codecs = serializer.NewCodecFactory(Scheme) 33 | var ParameterCodec = runtime.NewParameterCodec(Scheme) 34 | var localSchemeBuilder = runtime.SchemeBuilder{ 35 | metricsv1alpha1.AddToScheme, 36 | metricsv1beta1.AddToScheme, 37 | } 38 | 39 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 40 | // of clientsets, like in: 41 | // 42 | // import ( 43 | // "k8s.io/client-go/kubernetes" 44 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 45 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 46 | // ) 47 | // 48 | // kclientset, _ := kubernetes.NewForConfig(c) 49 | // _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 50 | // 51 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 52 | // correctly. 53 | var AddToScheme = localSchemeBuilder.AddToScheme 54 | 55 | func init() { 56 | v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) 57 | utilruntime.Must(AddToScheme(Scheme)) 58 | } 59 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated typed clients. 20 | package v1alpha1 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // Package fake has the automatically generated clients. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/fake/fake_metrics_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | rest "k8s.io/client-go/rest" 23 | testing "k8s.io/client-go/testing" 24 | v1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1" 25 | ) 26 | 27 | type FakeMetricsV1alpha1 struct { 28 | *testing.Fake 29 | } 30 | 31 | func (c *FakeMetricsV1alpha1) NodeMetricses() v1alpha1.NodeMetricsInterface { 32 | return newFakeNodeMetricses(c) 33 | } 34 | 35 | func (c *FakeMetricsV1alpha1) PodMetricses(namespace string) v1alpha1.PodMetricsInterface { 36 | return newFakePodMetricses(c, namespace) 37 | } 38 | 39 | // RESTClient returns a RESTClient that is used to communicate 40 | // with API server by this client implementation. 41 | func (c *FakeMetricsV1alpha1) RESTClient() rest.Interface { 42 | var ret *rest.RESTClient 43 | return ret 44 | } 45 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/fake/fake_nodemetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | gentype "k8s.io/client-go/gentype" 23 | v1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 24 | metricsv1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1" 25 | ) 26 | 27 | // fakeNodeMetricses implements NodeMetricsInterface 28 | type fakeNodeMetricses struct { 29 | *gentype.FakeClientWithList[*v1alpha1.NodeMetrics, *v1alpha1.NodeMetricsList] 30 | Fake *FakeMetricsV1alpha1 31 | } 32 | 33 | func newFakeNodeMetricses(fake *FakeMetricsV1alpha1) metricsv1alpha1.NodeMetricsInterface { 34 | return &fakeNodeMetricses{ 35 | gentype.NewFakeClientWithList[*v1alpha1.NodeMetrics, *v1alpha1.NodeMetricsList]( 36 | fake.Fake, 37 | "", 38 | v1alpha1.SchemeGroupVersion.WithResource("nodes"), 39 | v1alpha1.SchemeGroupVersion.WithKind("NodeMetrics"), 40 | func() *v1alpha1.NodeMetrics { return &v1alpha1.NodeMetrics{} }, 41 | func() *v1alpha1.NodeMetricsList { return &v1alpha1.NodeMetricsList{} }, 42 | func(dst, src *v1alpha1.NodeMetricsList) { dst.ListMeta = src.ListMeta }, 43 | func(list *v1alpha1.NodeMetricsList) []*v1alpha1.NodeMetrics { 44 | return gentype.ToPointerSlice(list.Items) 45 | }, 46 | func(list *v1alpha1.NodeMetricsList, items []*v1alpha1.NodeMetrics) { 47 | list.Items = gentype.FromPointerSlice(items) 48 | }, 49 | ), 50 | fake, 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/fake/fake_podmetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | gentype "k8s.io/client-go/gentype" 23 | v1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 24 | metricsv1alpha1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1alpha1" 25 | ) 26 | 27 | // fakePodMetricses implements PodMetricsInterface 28 | type fakePodMetricses struct { 29 | *gentype.FakeClientWithList[*v1alpha1.PodMetrics, *v1alpha1.PodMetricsList] 30 | Fake *FakeMetricsV1alpha1 31 | } 32 | 33 | func newFakePodMetricses(fake *FakeMetricsV1alpha1, namespace string) metricsv1alpha1.PodMetricsInterface { 34 | return &fakePodMetricses{ 35 | gentype.NewFakeClientWithList[*v1alpha1.PodMetrics, *v1alpha1.PodMetricsList]( 36 | fake.Fake, 37 | namespace, 38 | v1alpha1.SchemeGroupVersion.WithResource("pods"), 39 | v1alpha1.SchemeGroupVersion.WithKind("PodMetrics"), 40 | func() *v1alpha1.PodMetrics { return &v1alpha1.PodMetrics{} }, 41 | func() *v1alpha1.PodMetricsList { return &v1alpha1.PodMetricsList{} }, 42 | func(dst, src *v1alpha1.PodMetricsList) { dst.ListMeta = src.ListMeta }, 43 | func(list *v1alpha1.PodMetricsList) []*v1alpha1.PodMetrics { return gentype.ToPointerSlice(list.Items) }, 44 | func(list *v1alpha1.PodMetricsList, items []*v1alpha1.PodMetrics) { 45 | list.Items = gentype.FromPointerSlice(items) 46 | }, 47 | ), 48 | fake, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/generated_expansion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | type NodeMetricsExpansion interface{} 22 | 23 | type PodMetricsExpansion interface{} 24 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/metrics_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | http "net/http" 23 | 24 | rest "k8s.io/client-go/rest" 25 | metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 26 | scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" 27 | ) 28 | 29 | type MetricsV1alpha1Interface interface { 30 | RESTClient() rest.Interface 31 | NodeMetricsesGetter 32 | PodMetricsesGetter 33 | } 34 | 35 | // MetricsV1alpha1Client is used to interact with features provided by the metrics.k8s.io group. 36 | type MetricsV1alpha1Client struct { 37 | restClient rest.Interface 38 | } 39 | 40 | func (c *MetricsV1alpha1Client) NodeMetricses() NodeMetricsInterface { 41 | return newNodeMetricses(c) 42 | } 43 | 44 | func (c *MetricsV1alpha1Client) PodMetricses(namespace string) PodMetricsInterface { 45 | return newPodMetricses(c, namespace) 46 | } 47 | 48 | // NewForConfig creates a new MetricsV1alpha1Client for the given config. 49 | // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), 50 | // where httpClient was generated with rest.HTTPClientFor(c). 51 | func NewForConfig(c *rest.Config) (*MetricsV1alpha1Client, error) { 52 | config := *c 53 | setConfigDefaults(&config) 54 | httpClient, err := rest.HTTPClientFor(&config) 55 | if err != nil { 56 | return nil, err 57 | } 58 | return NewForConfigAndClient(&config, httpClient) 59 | } 60 | 61 | // NewForConfigAndClient creates a new MetricsV1alpha1Client for the given config and http client. 62 | // Note the http client provided takes precedence over the configured transport values. 63 | func NewForConfigAndClient(c *rest.Config, h *http.Client) (*MetricsV1alpha1Client, error) { 64 | config := *c 65 | setConfigDefaults(&config) 66 | client, err := rest.RESTClientForConfigAndClient(&config, h) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return &MetricsV1alpha1Client{client}, nil 71 | } 72 | 73 | // NewForConfigOrDie creates a new MetricsV1alpha1Client for the given config and 74 | // panics if there is an error in the config. 75 | func NewForConfigOrDie(c *rest.Config) *MetricsV1alpha1Client { 76 | client, err := NewForConfig(c) 77 | if err != nil { 78 | panic(err) 79 | } 80 | return client 81 | } 82 | 83 | // New creates a new MetricsV1alpha1Client for the given RESTClient. 84 | func New(c rest.Interface) *MetricsV1alpha1Client { 85 | return &MetricsV1alpha1Client{c} 86 | } 87 | 88 | func setConfigDefaults(config *rest.Config) { 89 | gv := metricsv1alpha1.SchemeGroupVersion 90 | config.GroupVersion = &gv 91 | config.APIPath = "/apis" 92 | config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() 93 | 94 | if config.UserAgent == "" { 95 | config.UserAgent = rest.DefaultKubernetesUserAgent() 96 | } 97 | } 98 | 99 | // RESTClient returns a RESTClient that is used to communicate 100 | // with API server by this client implementation. 101 | func (c *MetricsV1alpha1Client) RESTClient() rest.Interface { 102 | if c == nil { 103 | return nil 104 | } 105 | return c.restClient 106 | } 107 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/nodemetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | context "context" 23 | 24 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | watch "k8s.io/apimachinery/pkg/watch" 26 | gentype "k8s.io/client-go/gentype" 27 | metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 28 | scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" 29 | ) 30 | 31 | // NodeMetricsesGetter has a method to return a NodeMetricsInterface. 32 | // A group's client should implement this interface. 33 | type NodeMetricsesGetter interface { 34 | NodeMetricses() NodeMetricsInterface 35 | } 36 | 37 | // NodeMetricsInterface has methods to work with NodeMetrics resources. 38 | type NodeMetricsInterface interface { 39 | Get(ctx context.Context, name string, opts v1.GetOptions) (*metricsv1alpha1.NodeMetrics, error) 40 | List(ctx context.Context, opts v1.ListOptions) (*metricsv1alpha1.NodeMetricsList, error) 41 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 42 | NodeMetricsExpansion 43 | } 44 | 45 | // nodeMetricses implements NodeMetricsInterface 46 | type nodeMetricses struct { 47 | *gentype.ClientWithList[*metricsv1alpha1.NodeMetrics, *metricsv1alpha1.NodeMetricsList] 48 | } 49 | 50 | // newNodeMetricses returns a NodeMetricses 51 | func newNodeMetricses(c *MetricsV1alpha1Client) *nodeMetricses { 52 | return &nodeMetricses{ 53 | gentype.NewClientWithList[*metricsv1alpha1.NodeMetrics, *metricsv1alpha1.NodeMetricsList]( 54 | "nodes", 55 | c.RESTClient(), 56 | scheme.ParameterCodec, 57 | "", 58 | func() *metricsv1alpha1.NodeMetrics { return &metricsv1alpha1.NodeMetrics{} }, 59 | func() *metricsv1alpha1.NodeMetricsList { return &metricsv1alpha1.NodeMetricsList{} }, 60 | gentype.PrefersProtobuf[*metricsv1alpha1.NodeMetrics](), 61 | ), 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1alpha1/podmetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | context "context" 23 | 24 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | watch "k8s.io/apimachinery/pkg/watch" 26 | gentype "k8s.io/client-go/gentype" 27 | metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" 28 | scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" 29 | ) 30 | 31 | // PodMetricsesGetter has a method to return a PodMetricsInterface. 32 | // A group's client should implement this interface. 33 | type PodMetricsesGetter interface { 34 | PodMetricses(namespace string) PodMetricsInterface 35 | } 36 | 37 | // PodMetricsInterface has methods to work with PodMetrics resources. 38 | type PodMetricsInterface interface { 39 | Get(ctx context.Context, name string, opts v1.GetOptions) (*metricsv1alpha1.PodMetrics, error) 40 | List(ctx context.Context, opts v1.ListOptions) (*metricsv1alpha1.PodMetricsList, error) 41 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 42 | PodMetricsExpansion 43 | } 44 | 45 | // podMetricses implements PodMetricsInterface 46 | type podMetricses struct { 47 | *gentype.ClientWithList[*metricsv1alpha1.PodMetrics, *metricsv1alpha1.PodMetricsList] 48 | } 49 | 50 | // newPodMetricses returns a PodMetricses 51 | func newPodMetricses(c *MetricsV1alpha1Client, namespace string) *podMetricses { 52 | return &podMetricses{ 53 | gentype.NewClientWithList[*metricsv1alpha1.PodMetrics, *metricsv1alpha1.PodMetricsList]( 54 | "pods", 55 | c.RESTClient(), 56 | scheme.ParameterCodec, 57 | namespace, 58 | func() *metricsv1alpha1.PodMetrics { return &metricsv1alpha1.PodMetrics{} }, 59 | func() *metricsv1alpha1.PodMetricsList { return &metricsv1alpha1.PodMetricsList{} }, 60 | gentype.PrefersProtobuf[*metricsv1alpha1.PodMetrics](), 61 | ), 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated typed clients. 20 | package v1beta1 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // Package fake has the automatically generated clients. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/fake/fake_metrics_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | rest "k8s.io/client-go/rest" 23 | testing "k8s.io/client-go/testing" 24 | v1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" 25 | ) 26 | 27 | type FakeMetricsV1beta1 struct { 28 | *testing.Fake 29 | } 30 | 31 | func (c *FakeMetricsV1beta1) NodeMetricses() v1beta1.NodeMetricsInterface { 32 | return newFakeNodeMetricses(c) 33 | } 34 | 35 | func (c *FakeMetricsV1beta1) PodMetricses(namespace string) v1beta1.PodMetricsInterface { 36 | return newFakePodMetricses(c, namespace) 37 | } 38 | 39 | // RESTClient returns a RESTClient that is used to communicate 40 | // with API server by this client implementation. 41 | func (c *FakeMetricsV1beta1) RESTClient() rest.Interface { 42 | var ret *rest.RESTClient 43 | return ret 44 | } 45 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/fake/fake_nodemetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | gentype "k8s.io/client-go/gentype" 23 | v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 24 | metricsv1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" 25 | ) 26 | 27 | // fakeNodeMetricses implements NodeMetricsInterface 28 | type fakeNodeMetricses struct { 29 | *gentype.FakeClientWithList[*v1beta1.NodeMetrics, *v1beta1.NodeMetricsList] 30 | Fake *FakeMetricsV1beta1 31 | } 32 | 33 | func newFakeNodeMetricses(fake *FakeMetricsV1beta1) metricsv1beta1.NodeMetricsInterface { 34 | return &fakeNodeMetricses{ 35 | gentype.NewFakeClientWithList[*v1beta1.NodeMetrics, *v1beta1.NodeMetricsList]( 36 | fake.Fake, 37 | "", 38 | v1beta1.SchemeGroupVersion.WithResource("nodes"), 39 | v1beta1.SchemeGroupVersion.WithKind("NodeMetrics"), 40 | func() *v1beta1.NodeMetrics { return &v1beta1.NodeMetrics{} }, 41 | func() *v1beta1.NodeMetricsList { return &v1beta1.NodeMetricsList{} }, 42 | func(dst, src *v1beta1.NodeMetricsList) { dst.ListMeta = src.ListMeta }, 43 | func(list *v1beta1.NodeMetricsList) []*v1beta1.NodeMetrics { return gentype.ToPointerSlice(list.Items) }, 44 | func(list *v1beta1.NodeMetricsList, items []*v1beta1.NodeMetrics) { 45 | list.Items = gentype.FromPointerSlice(items) 46 | }, 47 | ), 48 | fake, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/fake/fake_podmetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | gentype "k8s.io/client-go/gentype" 23 | v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 24 | metricsv1beta1 "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" 25 | ) 26 | 27 | // fakePodMetricses implements PodMetricsInterface 28 | type fakePodMetricses struct { 29 | *gentype.FakeClientWithList[*v1beta1.PodMetrics, *v1beta1.PodMetricsList] 30 | Fake *FakeMetricsV1beta1 31 | } 32 | 33 | func newFakePodMetricses(fake *FakeMetricsV1beta1, namespace string) metricsv1beta1.PodMetricsInterface { 34 | return &fakePodMetricses{ 35 | gentype.NewFakeClientWithList[*v1beta1.PodMetrics, *v1beta1.PodMetricsList]( 36 | fake.Fake, 37 | namespace, 38 | v1beta1.SchemeGroupVersion.WithResource("pods"), 39 | v1beta1.SchemeGroupVersion.WithKind("PodMetrics"), 40 | func() *v1beta1.PodMetrics { return &v1beta1.PodMetrics{} }, 41 | func() *v1beta1.PodMetricsList { return &v1beta1.PodMetricsList{} }, 42 | func(dst, src *v1beta1.PodMetricsList) { dst.ListMeta = src.ListMeta }, 43 | func(list *v1beta1.PodMetricsList) []*v1beta1.PodMetrics { return gentype.ToPointerSlice(list.Items) }, 44 | func(list *v1beta1.PodMetricsList, items []*v1beta1.PodMetrics) { 45 | list.Items = gentype.FromPointerSlice(items) 46 | }, 47 | ), 48 | fake, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/generated_expansion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1beta1 20 | 21 | type NodeMetricsExpansion interface{} 22 | 23 | type PodMetricsExpansion interface{} 24 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/metrics_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1beta1 20 | 21 | import ( 22 | http "net/http" 23 | 24 | rest "k8s.io/client-go/rest" 25 | metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 26 | scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" 27 | ) 28 | 29 | type MetricsV1beta1Interface interface { 30 | RESTClient() rest.Interface 31 | NodeMetricsesGetter 32 | PodMetricsesGetter 33 | } 34 | 35 | // MetricsV1beta1Client is used to interact with features provided by the metrics.k8s.io group. 36 | type MetricsV1beta1Client struct { 37 | restClient rest.Interface 38 | } 39 | 40 | func (c *MetricsV1beta1Client) NodeMetricses() NodeMetricsInterface { 41 | return newNodeMetricses(c) 42 | } 43 | 44 | func (c *MetricsV1beta1Client) PodMetricses(namespace string) PodMetricsInterface { 45 | return newPodMetricses(c, namespace) 46 | } 47 | 48 | // NewForConfig creates a new MetricsV1beta1Client for the given config. 49 | // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), 50 | // where httpClient was generated with rest.HTTPClientFor(c). 51 | func NewForConfig(c *rest.Config) (*MetricsV1beta1Client, error) { 52 | config := *c 53 | setConfigDefaults(&config) 54 | httpClient, err := rest.HTTPClientFor(&config) 55 | if err != nil { 56 | return nil, err 57 | } 58 | return NewForConfigAndClient(&config, httpClient) 59 | } 60 | 61 | // NewForConfigAndClient creates a new MetricsV1beta1Client for the given config and http client. 62 | // Note the http client provided takes precedence over the configured transport values. 63 | func NewForConfigAndClient(c *rest.Config, h *http.Client) (*MetricsV1beta1Client, error) { 64 | config := *c 65 | setConfigDefaults(&config) 66 | client, err := rest.RESTClientForConfigAndClient(&config, h) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return &MetricsV1beta1Client{client}, nil 71 | } 72 | 73 | // NewForConfigOrDie creates a new MetricsV1beta1Client for the given config and 74 | // panics if there is an error in the config. 75 | func NewForConfigOrDie(c *rest.Config) *MetricsV1beta1Client { 76 | client, err := NewForConfig(c) 77 | if err != nil { 78 | panic(err) 79 | } 80 | return client 81 | } 82 | 83 | // New creates a new MetricsV1beta1Client for the given RESTClient. 84 | func New(c rest.Interface) *MetricsV1beta1Client { 85 | return &MetricsV1beta1Client{c} 86 | } 87 | 88 | func setConfigDefaults(config *rest.Config) { 89 | gv := metricsv1beta1.SchemeGroupVersion 90 | config.GroupVersion = &gv 91 | config.APIPath = "/apis" 92 | config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() 93 | 94 | if config.UserAgent == "" { 95 | config.UserAgent = rest.DefaultKubernetesUserAgent() 96 | } 97 | } 98 | 99 | // RESTClient returns a RESTClient that is used to communicate 100 | // with API server by this client implementation. 101 | func (c *MetricsV1beta1Client) RESTClient() rest.Interface { 102 | if c == nil { 103 | return nil 104 | } 105 | return c.restClient 106 | } 107 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/nodemetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1beta1 20 | 21 | import ( 22 | context "context" 23 | 24 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | watch "k8s.io/apimachinery/pkg/watch" 26 | gentype "k8s.io/client-go/gentype" 27 | metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 28 | scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" 29 | ) 30 | 31 | // NodeMetricsesGetter has a method to return a NodeMetricsInterface. 32 | // A group's client should implement this interface. 33 | type NodeMetricsesGetter interface { 34 | NodeMetricses() NodeMetricsInterface 35 | } 36 | 37 | // NodeMetricsInterface has methods to work with NodeMetrics resources. 38 | type NodeMetricsInterface interface { 39 | Get(ctx context.Context, name string, opts v1.GetOptions) (*metricsv1beta1.NodeMetrics, error) 40 | List(ctx context.Context, opts v1.ListOptions) (*metricsv1beta1.NodeMetricsList, error) 41 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 42 | NodeMetricsExpansion 43 | } 44 | 45 | // nodeMetricses implements NodeMetricsInterface 46 | type nodeMetricses struct { 47 | *gentype.ClientWithList[*metricsv1beta1.NodeMetrics, *metricsv1beta1.NodeMetricsList] 48 | } 49 | 50 | // newNodeMetricses returns a NodeMetricses 51 | func newNodeMetricses(c *MetricsV1beta1Client) *nodeMetricses { 52 | return &nodeMetricses{ 53 | gentype.NewClientWithList[*metricsv1beta1.NodeMetrics, *metricsv1beta1.NodeMetricsList]( 54 | "nodes", 55 | c.RESTClient(), 56 | scheme.ParameterCodec, 57 | "", 58 | func() *metricsv1beta1.NodeMetrics { return &metricsv1beta1.NodeMetrics{} }, 59 | func() *metricsv1beta1.NodeMetricsList { return &metricsv1beta1.NodeMetricsList{} }, 60 | gentype.PrefersProtobuf[*metricsv1beta1.NodeMetrics](), 61 | ), 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/metrics/v1beta1/podmetrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1beta1 20 | 21 | import ( 22 | context "context" 23 | 24 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | watch "k8s.io/apimachinery/pkg/watch" 26 | gentype "k8s.io/client-go/gentype" 27 | metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" 28 | scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" 29 | ) 30 | 31 | // PodMetricsesGetter has a method to return a PodMetricsInterface. 32 | // A group's client should implement this interface. 33 | type PodMetricsesGetter interface { 34 | PodMetricses(namespace string) PodMetricsInterface 35 | } 36 | 37 | // PodMetricsInterface has methods to work with PodMetrics resources. 38 | type PodMetricsInterface interface { 39 | Get(ctx context.Context, name string, opts v1.GetOptions) (*metricsv1beta1.PodMetrics, error) 40 | List(ctx context.Context, opts v1.ListOptions) (*metricsv1beta1.PodMetricsList, error) 41 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 42 | PodMetricsExpansion 43 | } 44 | 45 | // podMetricses implements PodMetricsInterface 46 | type podMetricses struct { 47 | *gentype.ClientWithList[*metricsv1beta1.PodMetrics, *metricsv1beta1.PodMetricsList] 48 | } 49 | 50 | // newPodMetricses returns a PodMetricses 51 | func newPodMetricses(c *MetricsV1beta1Client, namespace string) *podMetricses { 52 | return &podMetricses{ 53 | gentype.NewClientWithList[*metricsv1beta1.PodMetrics, *metricsv1beta1.PodMetricsList]( 54 | "pods", 55 | c.RESTClient(), 56 | scheme.ParameterCodec, 57 | namespace, 58 | func() *metricsv1beta1.PodMetrics { return &metricsv1beta1.PodMetrics{} }, 59 | func() *metricsv1beta1.PodMetricsList { return &metricsv1beta1.PodMetricsList{} }, 60 | gentype.PrefersProtobuf[*metricsv1beta1.PodMetrics](), 61 | ), 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pkg/client/clientset_test/clientset_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package clientset_test 18 | 19 | import ( 20 | "context" 21 | "testing" 22 | 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/metrics/pkg/client/clientset/versioned/fake" 25 | ) 26 | 27 | // TestFakeList is a basic sanity check that makes sure the fake Clientset is working properly. 28 | func TestFakeList(t *testing.T) { 29 | client := fake.NewSimpleClientset() 30 | if _, err := client.MetricsV1alpha1().PodMetricses("").List(context.TODO(), metav1.ListOptions{}); err != nil { 31 | t.Errorf("Unexpected error: %v", err) 32 | } 33 | if _, err := client.MetricsV1alpha1().NodeMetricses().List(context.TODO(), metav1.ListOptions{}); err != nil { 34 | t.Errorf("Unexpected error: %v", err) 35 | } 36 | if _, err := client.MetricsV1beta1().PodMetricses("").List(context.TODO(), metav1.ListOptions{}); err != nil { 37 | t.Errorf("Unexpected error: %v", err) 38 | } 39 | if _, err := client.MetricsV1beta1().NodeMetricses().List(context.TODO(), metav1.ListOptions{}); err != nil { 40 | t.Errorf("Unexpected error: %v", err) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/converter.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "k8s.io/apimachinery/pkg/runtime/serializer" 25 | "k8s.io/client-go/rest" 26 | 27 | cmint "k8s.io/metrics/pkg/apis/custom_metrics" 28 | cmv1beta1 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1" 29 | cmv1beta2 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 30 | "k8s.io/metrics/pkg/client/custom_metrics/scheme" 31 | ) 32 | 33 | var ( 34 | // MetricVersions is the set of metric versions accepted by the converter. 35 | MetricVersions = []schema.GroupVersion{ 36 | cmv1beta2.SchemeGroupVersion, 37 | cmv1beta1.SchemeGroupVersion, 38 | cmint.SchemeGroupVersion, 39 | } 40 | ) 41 | 42 | // MetricConverter knows how to convert between external MetricValue versions. 43 | type MetricConverter struct { 44 | scheme *runtime.Scheme 45 | codecs serializer.CodecFactory 46 | internalVersioner runtime.GroupVersioner 47 | } 48 | 49 | // NewMetricConverter creates a MetricConverter which knows how to convert objects 50 | // between different versions of the custom metrics api. 51 | func NewMetricConverter() *MetricConverter { 52 | return &MetricConverter{ 53 | scheme: scheme.Scheme, 54 | codecs: serializer.NewCodecFactory(scheme.Scheme), 55 | internalVersioner: runtime.NewMultiGroupVersioner( 56 | scheme.SchemeGroupVersion, 57 | schema.GroupKind{Group: cmint.GroupName, Kind: ""}, 58 | schema.GroupKind{Group: cmv1beta1.GroupName, Kind: ""}, 59 | schema.GroupKind{Group: cmv1beta2.GroupName, Kind: ""}, 60 | ), 61 | } 62 | } 63 | 64 | // Scheme returns the scheme used by this metric converter. 65 | func (c *MetricConverter) Scheme() *runtime.Scheme { 66 | return c.scheme 67 | } 68 | 69 | // Codecs returns the codecs used by this metric converter 70 | func (c *MetricConverter) Codecs() serializer.CodecFactory { 71 | return c.codecs 72 | } 73 | 74 | // ConvertListOptionsToVersion converts converts a set of MetricListOptions 75 | // to the provided GroupVersion. 76 | func (c *MetricConverter) ConvertListOptionsToVersion(opts *cmint.MetricListOptions, version schema.GroupVersion) (runtime.Object, error) { 77 | paramObj, err := c.UnsafeConvertToVersionVia(opts, version) 78 | if err != nil { 79 | return nil, err 80 | } 81 | return paramObj, nil 82 | } 83 | 84 | // ConvertResultToVersion converts a Result to the provided GroupVersion 85 | func (c *MetricConverter) ConvertResultToVersion(res rest.Result, gv schema.GroupVersion) (runtime.Object, error) { 86 | if err := res.Error(); err != nil { 87 | return nil, err 88 | } 89 | 90 | metricBytes, err := res.Raw() 91 | if err != nil { 92 | return nil, err 93 | } 94 | 95 | decoder := c.codecs.UniversalDecoder(MetricVersions...) 96 | rawMetricObj, err := runtime.Decode(decoder, metricBytes) 97 | if err != nil { 98 | return nil, err 99 | } 100 | 101 | metricObj, err := c.UnsafeConvertToVersionVia(rawMetricObj, gv) 102 | if err != nil { 103 | return nil, err 104 | } 105 | return metricObj, nil 106 | } 107 | 108 | // UnsafeConvertToVersionVia is like Scheme.UnsafeConvertToVersion, but it does so via an internal version first. 109 | // We use it here to work with the v1beta2 client internally, while preserving backwards compatibility for existing custom metrics adapters 110 | func (c *MetricConverter) UnsafeConvertToVersionVia(obj runtime.Object, externalVersion schema.GroupVersion) (runtime.Object, error) { 111 | objInt, err := c.scheme.UnsafeConvertToVersion(obj, schema.GroupVersion{Group: externalVersion.Group, Version: runtime.APIVersionInternal}) 112 | if err != nil { 113 | return nil, fmt.Errorf("failed to convert the given object to the internal version: %v", err) 114 | } 115 | 116 | objExt, err := c.scheme.UnsafeConvertToVersion(objInt, externalVersion) 117 | if err != nil { 118 | return nil, fmt.Errorf("failed to convert the given object back to the external version: %v", err) 119 | } 120 | 121 | return objExt, err 122 | } 123 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/discovery.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "fmt" 21 | "sync" 22 | 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/apimachinery/pkg/runtime/schema" 25 | "k8s.io/client-go/discovery" 26 | 27 | cmint "k8s.io/metrics/pkg/apis/custom_metrics" 28 | ) 29 | 30 | var ( 31 | // metricVersionsToGV is the map of string group-versions 32 | // accepted by the converter to group-version objects (so 33 | // we don't have to re-parse) 34 | metricVersionsToGV map[string]schema.GroupVersion 35 | ) 36 | 37 | func init() { 38 | metricVersionsToGV = make(map[string]schema.GroupVersion) 39 | for _, ver := range MetricVersions { 40 | metricVersionsToGV[ver.String()] = ver 41 | } 42 | } 43 | 44 | // NewAvailableAPIsGetter creates an AvailableAPIsGetter that checks discovery 45 | // to find the available versions of the custom metrics api. 46 | func NewAvailableAPIsGetter(client discovery.DiscoveryInterface) AvailableAPIsGetter { 47 | return &apiVersionsFromDiscovery{ 48 | client: client, 49 | } 50 | } 51 | 52 | // apiVersionsFromDiscovery caches a preferred version of the custom metrics api. 53 | type apiVersionsFromDiscovery struct { 54 | client discovery.DiscoveryInterface 55 | 56 | // just cache the group directly since the discovery interface doesn't yet allow 57 | // asking for a single API group's versions. 58 | prefVersion *schema.GroupVersion 59 | mu sync.RWMutex 60 | } 61 | 62 | // fetchVersions fetches the versions, but doesn't try to invalidate on cache misses. 63 | func (d *apiVersionsFromDiscovery) fetchVersions() (*metav1.APIGroup, error) { 64 | // TODO(directxman12): amend the discovery interface to ask for a particular group (/apis/foo) 65 | groups, err := d.client.ServerGroups() 66 | if err != nil { 67 | return nil, err 68 | } 69 | 70 | // Determine the preferred version on the server by first finding the custom metrics group 71 | var apiGroup *metav1.APIGroup 72 | for _, group := range groups.Groups { 73 | if group.Name == cmint.GroupName { 74 | apiGroup = &group 75 | break 76 | } 77 | } 78 | 79 | if apiGroup == nil { 80 | return nil, fmt.Errorf("no custom metrics API (%s) registered", cmint.GroupName) 81 | } 82 | 83 | return apiGroup, nil 84 | } 85 | 86 | // chooseVersion sets a preferred version of the custom metrics api based on available versions. 87 | func (d *apiVersionsFromDiscovery) chooseVersion(apiGroup *metav1.APIGroup) (schema.GroupVersion, error) { 88 | var preferredVersion *schema.GroupVersion 89 | if gv, present := metricVersionsToGV[apiGroup.PreferredVersion.GroupVersion]; present && len(apiGroup.PreferredVersion.GroupVersion) != 0 { 90 | preferredVersion = &gv 91 | } else { 92 | for _, version := range apiGroup.Versions { 93 | if gv, present := metricVersionsToGV[version.GroupVersion]; present { 94 | preferredVersion = &gv 95 | break 96 | } 97 | } 98 | } 99 | 100 | if preferredVersion == nil { 101 | return schema.GroupVersion{}, fmt.Errorf("no known available metric versions found") 102 | } 103 | return *preferredVersion, nil 104 | } 105 | 106 | // PreferredVersion returns the current preferred version of the custom metrics api. 107 | // If none is specified, it will use the first known one. 108 | func (d *apiVersionsFromDiscovery) PreferredVersion() (schema.GroupVersion, error) { 109 | d.mu.RLock() 110 | if d.prefVersion != nil { 111 | // if we've already got one, proceed with that 112 | defer d.mu.RUnlock() 113 | return *d.prefVersion, nil 114 | } 115 | d.mu.RUnlock() 116 | 117 | d.mu.Lock() 118 | defer d.mu.Unlock() 119 | 120 | // double check, someone might have beaten us to it 121 | if d.prefVersion != nil { 122 | return *d.prefVersion, nil 123 | } 124 | 125 | // populate our cache 126 | groupInfo, err := d.fetchVersions() 127 | if err != nil { 128 | return schema.GroupVersion{}, err 129 | } 130 | prefVersion, err := d.chooseVersion(groupInfo) 131 | if err != nil { 132 | return schema.GroupVersion{}, err 133 | } 134 | 135 | d.prefVersion = &prefVersion 136 | return *d.prefVersion, nil 137 | } 138 | 139 | // Invalidate refreshes the preferred version information. 140 | func (d *apiVersionsFromDiscovery) Invalidate() { 141 | d.mu.Lock() 142 | defer d.mu.Unlock() 143 | 144 | d.prefVersion = nil 145 | } 146 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/fake/fake_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fake 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/api/meta" 23 | "k8s.io/apimachinery/pkg/labels" 24 | "k8s.io/apimachinery/pkg/runtime/schema" 25 | "k8s.io/client-go/testing" 26 | "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 27 | cmclient "k8s.io/metrics/pkg/client/custom_metrics" 28 | ) 29 | 30 | type GetForActionImpl struct { 31 | testing.GetAction 32 | MetricName string 33 | LabelSelector labels.Selector 34 | } 35 | 36 | type GetForAction interface { 37 | testing.GetAction 38 | GetMetricName() string 39 | GetLabelSelector() labels.Selector 40 | } 41 | 42 | func (i GetForActionImpl) GetMetricName() string { 43 | return i.MetricName 44 | } 45 | 46 | func (i GetForActionImpl) GetLabelSelector() labels.Selector { 47 | return i.LabelSelector 48 | } 49 | 50 | func (i GetForActionImpl) GetSubresource() string { 51 | return i.MetricName 52 | } 53 | 54 | func (i GetForActionImpl) DeepCopy() testing.Action { 55 | var labelSelector labels.Selector 56 | if i.LabelSelector != nil { 57 | labelSelector = i.LabelSelector.DeepCopySelector() 58 | } 59 | return GetForActionImpl{ 60 | GetAction: i.GetAction.DeepCopy().(testing.GetAction), 61 | MetricName: i.MetricName, 62 | LabelSelector: labelSelector, 63 | } 64 | } 65 | 66 | func NewGetForAction(groupKind schema.GroupKind, namespace, name string, metricName string, labelSelector labels.Selector) GetForActionImpl { 67 | // the version doesn't matter 68 | gvk := groupKind.WithVersion("") 69 | gvr, _ := meta.UnsafeGuessKindToResource(gvk) 70 | groupResourceForKind := schema.GroupResource{ 71 | Group: gvr.Group, 72 | Resource: gvr.Resource, 73 | } 74 | resource := schema.GroupResource{ 75 | Group: v1beta2.SchemeGroupVersion.Group, 76 | Resource: groupResourceForKind.String(), 77 | } 78 | return GetForActionImpl{ 79 | GetAction: testing.NewGetAction(resource.WithVersion(""), namespace, name), 80 | MetricName: metricName, 81 | LabelSelector: labelSelector, 82 | } 83 | } 84 | 85 | func NewRootGetForAction(groupKind schema.GroupKind, name string, metricName string, labelSelector labels.Selector) GetForActionImpl { 86 | // the version doesn't matter 87 | gvk := groupKind.WithVersion("") 88 | gvr, _ := meta.UnsafeGuessKindToResource(gvk) 89 | groupResourceForKind := schema.GroupResource{ 90 | Group: gvr.Group, 91 | Resource: gvr.Resource, 92 | } 93 | resource := schema.GroupResource{ 94 | Group: v1beta2.SchemeGroupVersion.Group, 95 | Resource: groupResourceForKind.String(), 96 | } 97 | return GetForActionImpl{ 98 | GetAction: testing.NewRootGetAction(resource.WithVersion(""), name), 99 | MetricName: metricName, 100 | LabelSelector: labelSelector, 101 | } 102 | } 103 | 104 | type FakeCustomMetricsClient struct { 105 | testing.Fake 106 | } 107 | 108 | func (c *FakeCustomMetricsClient) RootScopedMetrics() cmclient.MetricsInterface { 109 | return &fakeRootScopedMetrics{ 110 | Fake: c, 111 | } 112 | } 113 | 114 | func (c *FakeCustomMetricsClient) NamespacedMetrics(namespace string) cmclient.MetricsInterface { 115 | return &fakeNamespacedMetrics{ 116 | Fake: c, 117 | ns: namespace, 118 | } 119 | } 120 | 121 | type fakeNamespacedMetrics struct { 122 | Fake *FakeCustomMetricsClient 123 | ns string 124 | } 125 | 126 | func (m *fakeNamespacedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) { 127 | obj, err := m.Fake. 128 | Invokes(NewGetForAction(groupKind, m.ns, name, metricName, nil), &v1beta2.MetricValueList{}) 129 | 130 | if obj == nil { 131 | return nil, err 132 | } 133 | 134 | objList := obj.(*v1beta2.MetricValueList) 135 | if len(objList.Items) != 1 { 136 | return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(objList.Items)) 137 | } 138 | 139 | return &objList.Items[0], err 140 | } 141 | 142 | func (m *fakeNamespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) { 143 | obj, err := m.Fake. 144 | Invokes(NewGetForAction(groupKind, m.ns, "*", metricName, selector), &v1beta2.MetricValueList{}) 145 | 146 | if obj == nil { 147 | return nil, err 148 | } 149 | 150 | return obj.(*v1beta2.MetricValueList), err 151 | } 152 | 153 | type fakeRootScopedMetrics struct { 154 | Fake *FakeCustomMetricsClient 155 | } 156 | 157 | func (m *fakeRootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) { 158 | obj, err := m.Fake. 159 | Invokes(NewRootGetForAction(groupKind, name, metricName, nil), &v1beta2.MetricValueList{}) 160 | 161 | if obj == nil { 162 | return nil, err 163 | } 164 | 165 | objList := obj.(*v1beta2.MetricValueList) 166 | if len(objList.Items) != 1 { 167 | return nil, fmt.Errorf("the custom metrics API server returned %v results when we asked for exactly one", len(objList.Items)) 168 | } 169 | 170 | return &objList.Items[0], err 171 | } 172 | 173 | func (m *fakeRootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) { 174 | obj, err := m.Fake. 175 | Invokes(NewRootGetForAction(groupKind, "*", metricName, selector), &v1beta2.MetricValueList{}) 176 | 177 | if obj == nil { 178 | return nil, err 179 | } 180 | 181 | return obj.(*v1beta2.MetricValueList), err 182 | } 183 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/labels" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 23 | ) 24 | 25 | // CustomMetricsClient is a client for fetching metrics 26 | // describing both root-scoped and namespaced resources. 27 | type CustomMetricsClient interface { 28 | RootScopedMetricsGetter 29 | NamespacedMetricsGetter 30 | } 31 | 32 | // RootScopedMetricsGetter provides access to an interface for fetching 33 | // metrics describing root-scoped objects. Note that metrics describing 34 | // a namespace are simply considered a special case of root-scoped metrics. 35 | type RootScopedMetricsGetter interface { 36 | RootScopedMetrics() MetricsInterface 37 | } 38 | 39 | // NamespacedMetricsGetter provides access to an interface for fetching 40 | // metrics describing resources in a particular namespace. 41 | type NamespacedMetricsGetter interface { 42 | NamespacedMetrics(namespace string) MetricsInterface 43 | } 44 | 45 | // MetricsInterface provides access to metrics describing Kubernetes objects. 46 | type MetricsInterface interface { 47 | // GetForObject fetchs the given metric describing the given object. 48 | GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) 49 | 50 | // GetForObjects fetches the given metric describing all objects of the given 51 | // type matching the given label selector (or simply all objects of the given type 52 | // if the selector is nil). 53 | GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) 54 | } 55 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/multi_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "sync" 21 | "time" 22 | 23 | "k8s.io/apimachinery/pkg/api/meta" 24 | "k8s.io/apimachinery/pkg/labels" 25 | "k8s.io/apimachinery/pkg/runtime/schema" 26 | "k8s.io/client-go/rest" 27 | 28 | "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 29 | ) 30 | 31 | // AvailableAPIsGetter knows how to fetch and cache the preferred custom metrics API version, 32 | // and invalidate that cache when asked. 33 | type AvailableAPIsGetter interface { 34 | PreferredVersion() (schema.GroupVersion, error) 35 | Invalidate() 36 | } 37 | 38 | // PeriodicallyInvalidate periodically invalidates the preferred version cache until 39 | // told to stop. 40 | func PeriodicallyInvalidate(cache AvailableAPIsGetter, interval time.Duration, stopCh <-chan struct{}) { 41 | ticker := time.NewTicker(interval) 42 | defer ticker.Stop() 43 | 44 | for { 45 | select { 46 | case <-ticker.C: 47 | cache.Invalidate() 48 | case <-stopCh: 49 | return 50 | } 51 | } 52 | } 53 | 54 | // NewForConfig creates a new custom metrics client which delegates to a client which 55 | // uses the preferred api version. 56 | func NewForConfig(baseConfig *rest.Config, mapper meta.RESTMapper, availableAPIs AvailableAPIsGetter) CustomMetricsClient { 57 | return &multiClient{ 58 | clients: make(map[schema.GroupVersion]CustomMetricsClient), 59 | availableAPIs: availableAPIs, 60 | 61 | newClient: func(ver schema.GroupVersion) (CustomMetricsClient, error) { 62 | return NewForVersionForConfig(rest.CopyConfig(baseConfig), mapper, ver) 63 | }, 64 | } 65 | } 66 | 67 | // multiClient is a CustomMetricsClient that can work with *any* metrics API version. 68 | type multiClient struct { 69 | newClient func(schema.GroupVersion) (CustomMetricsClient, error) 70 | clients map[schema.GroupVersion]CustomMetricsClient 71 | availableAPIs AvailableAPIsGetter 72 | mu sync.RWMutex 73 | } 74 | 75 | // getPreferredClient returns a custom metrics client of the preferred api version. 76 | func (c *multiClient) getPreferredClient() (CustomMetricsClient, error) { 77 | pref, err := c.availableAPIs.PreferredVersion() 78 | if err != nil { 79 | return nil, err 80 | } 81 | 82 | c.mu.RLock() 83 | client, present := c.clients[pref] 84 | c.mu.RUnlock() 85 | if present { 86 | return client, nil 87 | } 88 | 89 | c.mu.Lock() 90 | defer c.mu.Unlock() 91 | client, err = c.newClient(pref) 92 | if err != nil { 93 | return nil, err 94 | } 95 | c.clients[pref] = client 96 | 97 | return client, nil 98 | } 99 | 100 | func (c *multiClient) RootScopedMetrics() MetricsInterface { 101 | return &multiClientInterface{clients: c} 102 | } 103 | 104 | func (c *multiClient) NamespacedMetrics(namespace string) MetricsInterface { 105 | return &multiClientInterface{ 106 | clients: c, 107 | namespace: &namespace, 108 | } 109 | } 110 | 111 | type multiClientInterface struct { 112 | clients *multiClient 113 | namespace *string 114 | } 115 | 116 | func (m *multiClientInterface) GetForObject(groupKind schema.GroupKind, name string, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValue, error) { 117 | client, err := m.clients.getPreferredClient() 118 | if err != nil { 119 | return nil, err 120 | } 121 | if m.namespace == nil { 122 | return client.RootScopedMetrics().GetForObject(groupKind, name, metricName, metricSelector) 123 | } else { 124 | return client.NamespacedMetrics(*m.namespace).GetForObject(groupKind, name, metricName, metricSelector) 125 | } 126 | } 127 | 128 | func (m *multiClientInterface) GetForObjects(groupKind schema.GroupKind, selector labels.Selector, metricName string, metricSelector labels.Selector) (*v1beta2.MetricValueList, error) { 129 | client, err := m.clients.getPreferredClient() 130 | if err != nil { 131 | return nil, err 132 | } 133 | if m.namespace == nil { 134 | return client.RootScopedMetrics().GetForObjects(groupKind, selector, metricName, metricSelector) 135 | } else { 136 | return client.NamespacedMetrics(*m.namespace).GetForObjects(groupKind, selector, metricName, metricSelector) 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/scheme/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package scheme 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | runtime "k8s.io/apimachinery/pkg/runtime" 22 | schema "k8s.io/apimachinery/pkg/runtime/schema" 23 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 24 | cmint "k8s.io/metrics/pkg/apis/custom_metrics" 25 | cmv1beta1 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1" 26 | cmv1beta2 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 27 | ) 28 | 29 | // GroupName is the group name use in this package. 30 | const GroupName = cmv1beta1.GroupName 31 | 32 | // SchemeGroupVersion is group version used to register these objects. 33 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} 34 | 35 | // Scheme is the runtime.Scheme to which all custom metrics api types are registered. 36 | var Scheme = runtime.NewScheme() 37 | 38 | // Codecs provides access to encoding and decoding for the scheme. 39 | var Codecs = serializer.NewCodecFactory(Scheme) 40 | 41 | // ParameterCodec handles versioning of objects that are converted to query parameters. 42 | var ParameterCodec = runtime.NewParameterCodec(Scheme) 43 | 44 | func init() { 45 | metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) 46 | AddToScheme(Scheme) 47 | } 48 | 49 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 50 | // of clientsets, like in: 51 | // 52 | // import ( 53 | // "k8s.io/client-go/kubernetes" 54 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 55 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 56 | // ) 57 | // 58 | // kclientset, _ := kubernetes.NewForConfig(c) 59 | // aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 60 | // 61 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 62 | // correctly. 63 | func AddToScheme(scheme *runtime.Scheme) { 64 | cmint.AddToScheme(scheme) 65 | cmv1beta1.AddToScheme(scheme) 66 | cmv1beta2.AddToScheme(scheme) 67 | } 68 | -------------------------------------------------------------------------------- /pkg/client/custom_metrics/util_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package custom_metrics 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/require" 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | "k8s.io/apimachinery/pkg/runtime/schema" 26 | 27 | cmint "k8s.io/metrics/pkg/apis/custom_metrics" 28 | cmv1beta1 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1" 29 | cmv1beta2 "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2" 30 | ) 31 | 32 | func TestMetricConverter(t *testing.T) { 33 | testCases := []struct { 34 | name string 35 | group schema.GroupVersion 36 | expected runtime.Object 37 | }{ 38 | { 39 | name: "Use custom metrics v1beta2", 40 | group: cmv1beta2.SchemeGroupVersion, 41 | expected: &cmv1beta2.MetricListOptions{ 42 | TypeMeta: metav1.TypeMeta{Kind: "MetricListOptions", APIVersion: cmv1beta2.SchemeGroupVersion.String()}, 43 | MetricLabelSelector: "foo", 44 | }, 45 | }, 46 | { 47 | name: "Use custom metrics v1beta1", 48 | group: cmv1beta1.SchemeGroupVersion, 49 | expected: &cmv1beta1.MetricListOptions{ 50 | TypeMeta: metav1.TypeMeta{Kind: "MetricListOptions", APIVersion: cmv1beta1.SchemeGroupVersion.String()}, 51 | MetricLabelSelector: "foo", 52 | }, 53 | }, 54 | } 55 | 56 | for _, test := range testCases { 57 | t.Run(test.name, func(t *testing.T) { 58 | metricConverter := NewMetricConverter() 59 | opts := &cmint.MetricListOptions{MetricLabelSelector: "foo"} 60 | res, err := metricConverter.ConvertListOptionsToVersion(opts, test.group) 61 | require.NoError(t, err) 62 | require.Equal(t, test.expected, res) 63 | }) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pkg/client/external_metrics/client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package external_metrics 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/apimachinery/pkg/labels" 25 | "k8s.io/client-go/kubernetes/scheme" 26 | "k8s.io/client-go/rest" 27 | "k8s.io/client-go/util/flowcontrol" 28 | "k8s.io/metrics/pkg/apis/external_metrics/v1beta1" 29 | ) 30 | 31 | type externalMetricsClient struct { 32 | client rest.Interface 33 | } 34 | 35 | func New(client rest.Interface) ExternalMetricsClient { 36 | return &externalMetricsClient{ 37 | client: client, 38 | } 39 | } 40 | 41 | func NewForConfig(c *rest.Config) (ExternalMetricsClient, error) { 42 | configShallowCopy := *c 43 | if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 44 | if configShallowCopy.Burst <= 0 { 45 | 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") 46 | } 47 | configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 48 | } 49 | configShallowCopy.APIPath = "/apis" 50 | if configShallowCopy.UserAgent == "" { 51 | configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() 52 | } 53 | configShallowCopy.GroupVersion = &v1beta1.SchemeGroupVersion 54 | configShallowCopy.NegotiatedSerializer = scheme.Codecs.WithoutConversion() 55 | 56 | client, err := rest.RESTClientFor(&configShallowCopy) 57 | if err != nil { 58 | return nil, err 59 | } 60 | 61 | return New(client), nil 62 | } 63 | 64 | func NewForConfigOrDie(c *rest.Config) ExternalMetricsClient { 65 | client, err := NewForConfig(c) 66 | if err != nil { 67 | panic(err) 68 | } 69 | return client 70 | } 71 | 72 | func (c *externalMetricsClient) NamespacedMetrics(namespace string) MetricsInterface { 73 | return &namespacedMetrics{ 74 | client: c, 75 | namespace: namespace, 76 | } 77 | } 78 | 79 | type namespacedMetrics struct { 80 | client *externalMetricsClient 81 | namespace string 82 | } 83 | 84 | func (m *namespacedMetrics) List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error) { 85 | res := &v1beta1.ExternalMetricValueList{} 86 | err := m.client.client.Get(). 87 | Namespace(m.namespace). 88 | Resource(metricName). 89 | VersionedParams(&metav1.ListOptions{ 90 | LabelSelector: metricSelector.String(), 91 | }, metav1.ParameterCodec). 92 | Do(context.TODO()). 93 | Into(res) 94 | 95 | if err != nil { 96 | return nil, err 97 | } 98 | 99 | return res, nil 100 | } 101 | -------------------------------------------------------------------------------- /pkg/client/external_metrics/fake/fake_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fake 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/labels" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | "k8s.io/client-go/testing" 24 | "k8s.io/metrics/pkg/apis/external_metrics/v1beta1" 25 | eclient "k8s.io/metrics/pkg/client/external_metrics" 26 | ) 27 | 28 | type FakeExternalMetricsClient struct { 29 | testing.Fake 30 | } 31 | 32 | func (c *FakeExternalMetricsClient) NamespacedMetrics(namespace string) eclient.MetricsInterface { 33 | return &fakeNamespacedMetrics{ 34 | Fake: c, 35 | ns: namespace, 36 | } 37 | } 38 | 39 | type fakeNamespacedMetrics struct { 40 | Fake *FakeExternalMetricsClient 41 | ns string 42 | } 43 | 44 | func (m *fakeNamespacedMetrics) List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error) { 45 | resource := schema.GroupResource{ 46 | Group: v1beta1.SchemeGroupVersion.Group, 47 | Resource: metricName, 48 | } 49 | kind := schema.GroupKind{ 50 | Group: v1beta1.SchemeGroupVersion.Group, 51 | Kind: "ExternalMetricValue", 52 | } 53 | action := testing.NewListAction(resource.WithVersion(""), kind.WithVersion(""), m.ns, metav1.ListOptions{LabelSelector: metricSelector.String()}) 54 | obj, err := m.Fake. 55 | Invokes(action, &v1beta1.ExternalMetricValueList{}) 56 | 57 | if obj == nil { 58 | return nil, err 59 | } 60 | 61 | return obj.(*v1beta1.ExternalMetricValueList), err 62 | } 63 | -------------------------------------------------------------------------------- /pkg/client/external_metrics/interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package external_metrics 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/labels" 21 | "k8s.io/metrics/pkg/apis/external_metrics/v1beta1" 22 | ) 23 | 24 | // ExternalMetricsClient is a client for fetching external metrics. 25 | type ExternalMetricsClient interface { 26 | NamespacedMetricsGetter 27 | } 28 | 29 | // NamespacedMetricsGetter provides access to an interface for fetching 30 | // metrics in a particular namespace. 31 | type NamespacedMetricsGetter interface { 32 | NamespacedMetrics(namespace string) MetricsInterface 33 | } 34 | 35 | // MetricsInterface provides access to external metrics. 36 | type MetricsInterface interface { 37 | // List fetches the metric for the given namespace that maches the given 38 | // metricSelector. 39 | List(metricName string, metricSelector labels.Selector) (*v1beta1.ExternalMetricValueList, error) 40 | } 41 | --------------------------------------------------------------------------------