Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2014 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 v1 |
| 18 | |
| 19 | import ( |
| 20 | "k8s.io/apimachinery/pkg/runtime" |
| 21 | "k8s.io/apimachinery/pkg/runtime/schema" |
| 22 | ) |
| 23 | |
| 24 | // GroupName is the group name for this API. |
| 25 | const GroupName = "meta.k8s.io" |
| 26 | |
| 27 | // SchemeGroupVersion is group version used to register these objects |
| 28 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} |
| 29 | |
| 30 | // Unversioned is group version for unversioned API objects |
| 31 | // TODO: this should be v1 probably |
| 32 | var Unversioned = schema.GroupVersion{Group: "", Version: "v1"} |
| 33 | |
| 34 | // WatchEventKind is name reserved for serializing watch events. |
| 35 | const WatchEventKind = "WatchEvent" |
| 36 | |
| 37 | // Kind takes an unqualified kind and returns a Group qualified GroupKind |
| 38 | func Kind(kind string) schema.GroupKind { |
| 39 | return SchemeGroupVersion.WithKind(kind).GroupKind() |
| 40 | } |
| 41 | |
| 42 | // AddToGroupVersion registers common meta types into schemas. |
| 43 | func 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. |
| 78 | var scheme = runtime.NewScheme() |
| 79 | |
| 80 | // ParameterCodec knows about query parameters used with the meta v1 API spec. |
| 81 | var ParameterCodec = runtime.NewParameterCodec(scheme) |
| 82 | |
| 83 | func 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 | } |