blob: c1a077178bfb58402da3c78fa313f411b2f9d6da [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2Copyright 2014 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 v1
18
19import (
20 "k8s.io/apimachinery/pkg/runtime"
21 "k8s.io/apimachinery/pkg/runtime/schema"
22 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
23)
24
25// GroupName is the group name for this API.
26const GroupName = "meta.k8s.io"
27
28var (
29 // localSchemeBuilder is used to make compiler happy for autogenerated
30 // conversions. However, it's not used.
31 schemeBuilder runtime.SchemeBuilder
32 localSchemeBuilder = &schemeBuilder
33)
34
35// SchemeGroupVersion is group version used to register these objects
36var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
37
38// Unversioned is group version for unversioned API objects
39// TODO: this should be v1 probably
40var Unversioned = schema.GroupVersion{Group: "", Version: "v1"}
41
42// WatchEventKind is name reserved for serializing watch events.
43const WatchEventKind = "WatchEvent"
44
45// Kind takes an unqualified kind and returns a Group qualified GroupKind
46func Kind(kind string) schema.GroupKind {
47 return SchemeGroupVersion.WithKind(kind).GroupKind()
48}
49
50// scheme is the registry for the common types that adhere to the meta v1 API spec.
51var scheme = runtime.NewScheme()
52
53// ParameterCodec knows about query parameters used with the meta v1 API spec.
54var ParameterCodec = runtime.NewParameterCodec(scheme)
55
56var optionsTypes = []runtime.Object{
57 &ListOptions{},
58 &ExportOptions{},
59 &GetOptions{},
60 &DeleteOptions{},
61 &CreateOptions{},
62 &UpdateOptions{},
63 &PatchOptions{},
64}
65
66// AddToGroupVersion registers common meta types into schemas.
67func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion) {
68 scheme.AddKnownTypeWithName(groupVersion.WithKind(WatchEventKind), &WatchEvent{})
69 scheme.AddKnownTypeWithName(
70 schema.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}.WithKind(WatchEventKind),
71 &InternalEvent{},
72 )
73 // Supports legacy code paths, most callers should use metav1.ParameterCodec for now
74 scheme.AddKnownTypes(groupVersion, optionsTypes...)
75 // Register Unversioned types under their own special group
76 scheme.AddUnversionedTypes(Unversioned,
77 &Status{},
78 &APIVersions{},
79 &APIGroupList{},
80 &APIGroup{},
81 &APIResourceList{},
82 )
83
84 // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
85 utilruntime.Must(RegisterConversions(scheme))
86 utilruntime.Must(RegisterDefaults(scheme))
87}
88
89// AddMetaToScheme registers base meta types into schemas.
90func AddMetaToScheme(scheme *runtime.Scheme) error {
91 scheme.AddKnownTypes(SchemeGroupVersion,
92 &Table{},
93 &TableOptions{},
94 &PartialObjectMetadata{},
95 &PartialObjectMetadataList{},
96 )
97
98 return nil
99}
100
101func init() {
102 scheme.AddUnversionedTypes(SchemeGroupVersion, optionsTypes...)
103
104 utilruntime.Must(AddMetaToScheme(scheme))
105
106 // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
107 utilruntime.Must(RegisterDefaults(scheme))
108}