blob: b300d37015a9a40bb9e1612cc867a1fa39d6a412 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
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)
23
24// GroupName is the group name for this API.
25const GroupName = "meta.k8s.io"
26
27// SchemeGroupVersion is group version used to register these objects
28var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
29
30// Unversioned is group version for unversioned API objects
31// TODO: this should be v1 probably
32var Unversioned = schema.GroupVersion{Group: "", Version: "v1"}
33
34// WatchEventKind is name reserved for serializing watch events.
35const WatchEventKind = "WatchEvent"
36
37// Kind takes an unqualified kind and returns a Group qualified GroupKind
38func Kind(kind string) schema.GroupKind {
39 return SchemeGroupVersion.WithKind(kind).GroupKind()
40}
41
42// AddToGroupVersion registers common meta types into schemas.
43func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion) {
44 scheme.AddKnownTypeWithName(groupVersion.WithKind(WatchEventKind), &WatchEvent{})
45 scheme.AddKnownTypeWithName(
46 schema.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}.WithKind(WatchEventKind),
47 &InternalEvent{},
48 )
49 // Supports legacy code paths, most callers should use metav1.ParameterCodec for now
50 scheme.AddKnownTypes(groupVersion,
51 &ListOptions{},
52 &ExportOptions{},
53 &GetOptions{},
54 &DeleteOptions{},
55 )
56 scheme.AddConversionFuncs(
57 Convert_versioned_Event_to_watch_Event,
58 Convert_versioned_InternalEvent_to_versioned_Event,
59 Convert_watch_Event_to_versioned_Event,
60 Convert_versioned_Event_to_versioned_InternalEvent,
61 )
62
63 // Register Unversioned types under their own special group
64 scheme.AddUnversionedTypes(Unversioned,
65 &Status{},
66 &APIVersions{},
67 &APIGroupList{},
68 &APIGroup{},
69 &APIResourceList{},
70 )
71
72 // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
73 AddConversionFuncs(scheme)
74 RegisterDefaults(scheme)
75}
76
77// scheme is the registry for the common types that adhere to the meta v1 API spec.
78var scheme = runtime.NewScheme()
79
80// ParameterCodec knows about query parameters used with the meta v1 API spec.
81var ParameterCodec = runtime.NewParameterCodec(scheme)
82
83func init() {
84 scheme.AddUnversionedTypes(SchemeGroupVersion,
85 &ListOptions{},
86 &ExportOptions{},
87 &GetOptions{},
88 &DeleteOptions{},
89 )
90
91 // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
92 RegisterDefaults(scheme)
93}