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