Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [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 | var ( |
| 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 |
| 36 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} |
| 37 | |
| 38 | // Unversioned is group version for unversioned API objects |
| 39 | // TODO: this should be v1 probably |
| 40 | var Unversioned = schema.GroupVersion{Group: "", Version: "v1"} |
| 41 | |
| 42 | // WatchEventKind is name reserved for serializing watch events. |
| 43 | const WatchEventKind = "WatchEvent" |
| 44 | |
| 45 | // Kind takes an unqualified kind and returns a Group qualified GroupKind |
| 46 | func 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. |
| 51 | var scheme = runtime.NewScheme() |
| 52 | |
| 53 | // ParameterCodec knows about query parameters used with the meta v1 API spec. |
| 54 | var ParameterCodec = runtime.NewParameterCodec(scheme) |
| 55 | |
| 56 | var 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. |
| 67 | func 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. |
| 90 | func AddMetaToScheme(scheme *runtime.Scheme) error { |
| 91 | scheme.AddKnownTypes(SchemeGroupVersion, |
| 92 | &Table{}, |
| 93 | &TableOptions{}, |
| 94 | &PartialObjectMetadata{}, |
| 95 | &PartialObjectMetadataList{}, |
| 96 | ) |
| 97 | |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | func 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 | } |