sslobodr | d046be8 | 2019-01-16 10:02:22 -0500 | [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 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" |
| 23 | ) |
| 24 | |
| 25 | // GroupName is the group name for this API. |
| 26 | const GroupName = "meta.k8s.io" |
| 27 | |
| 28 | // SchemeGroupVersion is group version used to register these objects |
| 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} |
| 30 | |
| 31 | // Unversioned is group version for unversioned API objects |
| 32 | // TODO: this should be v1 probably |
| 33 | var Unversioned = schema.GroupVersion{Group: "", Version: "v1"} |
| 34 | |
| 35 | // WatchEventKind is name reserved for serializing watch events. |
| 36 | const WatchEventKind = "WatchEvent" |
| 37 | |
| 38 | // Kind takes an unqualified kind and returns a Group qualified GroupKind |
| 39 | func Kind(kind string) schema.GroupKind { |
| 40 | return SchemeGroupVersion.WithKind(kind).GroupKind() |
| 41 | } |
| 42 | |
| 43 | // AddToGroupVersion registers common meta types into schemas. |
| 44 | func 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{}, |
Stephane Barbarie | 260a563 | 2019-02-26 16:12:49 -0500 | [diff] [blame^] | 58 | &PatchOptions{}, |
sslobodr | d046be8 | 2019-01-16 10:02:22 -0500 | [diff] [blame] | 59 | ) |
| 60 | utilruntime.Must(scheme.AddConversionFuncs( |
| 61 | Convert_v1_WatchEvent_To_watch_Event, |
| 62 | Convert_v1_InternalEvent_To_v1_WatchEvent, |
| 63 | Convert_watch_Event_To_v1_WatchEvent, |
| 64 | Convert_v1_WatchEvent_To_v1_InternalEvent, |
| 65 | )) |
| 66 | // Register Unversioned types under their own special group |
| 67 | scheme.AddUnversionedTypes(Unversioned, |
| 68 | &Status{}, |
| 69 | &APIVersions{}, |
| 70 | &APIGroupList{}, |
| 71 | &APIGroup{}, |
| 72 | &APIResourceList{}, |
| 73 | ) |
| 74 | |
| 75 | // register manually. This usually goes through the SchemeBuilder, which we cannot use here. |
| 76 | utilruntime.Must(AddConversionFuncs(scheme)) |
| 77 | utilruntime.Must(RegisterDefaults(scheme)) |
| 78 | } |
| 79 | |
| 80 | // scheme is the registry for the common types that adhere to the meta v1 API spec. |
| 81 | var scheme = runtime.NewScheme() |
| 82 | |
| 83 | // ParameterCodec knows about query parameters used with the meta v1 API spec. |
| 84 | var ParameterCodec = runtime.NewParameterCodec(scheme) |
| 85 | |
| 86 | func init() { |
| 87 | scheme.AddUnversionedTypes(SchemeGroupVersion, |
| 88 | &ListOptions{}, |
| 89 | &ExportOptions{}, |
| 90 | &GetOptions{}, |
| 91 | &DeleteOptions{}, |
| 92 | &CreateOptions{}, |
| 93 | &UpdateOptions{}, |
Stephane Barbarie | 260a563 | 2019-02-26 16:12:49 -0500 | [diff] [blame^] | 94 | &PatchOptions{}, |
sslobodr | d046be8 | 2019-01-16 10:02:22 -0500 | [diff] [blame] | 95 | ) |
| 96 | |
| 97 | // register manually. This usually goes through the SchemeBuilder, which we cannot use here. |
| 98 | utilruntime.Must(RegisterDefaults(scheme)) |
| 99 | } |