1/*
2Copyright 2018 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package scheme
18
19import (
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.
30const GroupName = cmv1beta1.GroupName
31
32// SchemeGroupVersion is group version used to register these objects.
33var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}
34
35// Scheme is the runtime.Scheme to which all custom metrics api types are registered.
36var Scheme = runtime.NewScheme()
37
38// Codecs provides access to encoding and decoding for the scheme.
39var Codecs = serializer.NewCodecFactory(Scheme)
40
41// ParameterCodec handles versioning of objects that are converted to query parameters.
42var ParameterCodec = runtime.NewParameterCodec(Scheme)
43
44func 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.
63func AddToScheme(scheme *runtime.Scheme) {
64	cmint.AddToScheme(scheme)
65	cmv1beta1.AddToScheme(scheme)
66	cmv1beta2.AddToScheme(scheme)
67}
68