github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/apis/meta/internalversion/register.go (about) 1 /* 2 Copyright 2017 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 internalversion 18 19 import ( 20 metav1 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/meta/v1" 21 metav1beta1 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/meta/v1beta1" 22 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime" 23 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime/schema" 24 ) 25 26 // GroupName is the group name for this API. 27 const GroupName = "meta.k8s.io" 28 29 var ( 30 // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. 31 // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. 32 SchemeBuilder runtime.SchemeBuilder 33 localSchemeBuilder = &SchemeBuilder 34 AddToScheme = localSchemeBuilder.AddToScheme 35 ) 36 37 // SchemeGroupVersion is group version used to register these objects 38 var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} 39 40 // Kind takes an unqualified kind and returns a Group qualified GroupKind 41 func Kind(kind string) schema.GroupKind { 42 return SchemeGroupVersion.WithKind(kind).GroupKind() 43 } 44 45 // addToGroupVersion registers common meta types into schemas. 46 func addToGroupVersion(scheme *runtime.Scheme) error { 47 if err := scheme.AddIgnoredConversionType(&metav1.TypeMeta{}, &metav1.TypeMeta{}); err != nil { 48 return err 49 } 50 // ListOptions is the only options struct which needs conversion (it exposes labels and fields 51 // as selectors for convenience). The other types have only a single representation today. 52 scheme.AddKnownTypes(SchemeGroupVersion, 53 &ListOptions{}, 54 &metav1.GetOptions{}, 55 &metav1.DeleteOptions{}, 56 &metav1.CreateOptions{}, 57 &metav1.UpdateOptions{}, 58 ) 59 scheme.AddKnownTypes(SchemeGroupVersion, 60 &metav1.Table{}, 61 &metav1.TableOptions{}, 62 &metav1beta1.PartialObjectMetadata{}, 63 &metav1beta1.PartialObjectMetadataList{}, 64 ) 65 if err := metav1beta1.AddMetaToScheme(scheme); err != nil { 66 return err 67 } 68 if err := metav1.AddMetaToScheme(scheme); err != nil { 69 return err 70 } 71 // Allow delete options to be decoded across all version in this scheme (we may want to be more clever than this) 72 scheme.AddUnversionedTypes(SchemeGroupVersion, 73 &metav1.DeleteOptions{}, 74 &metav1.CreateOptions{}, 75 &metav1.UpdateOptions{}) 76 77 metav1.AddToGroupVersion(scheme, metav1.SchemeGroupVersion) 78 if err := metav1beta1.RegisterConversions(scheme); err != nil { 79 return err 80 } 81 return nil 82 } 83 84 // Unlike other API groups, meta internal knows about all meta external versions, but keeps 85 // the logic for conversion private. 86 func init() { 87 localSchemeBuilder.Register(addToGroupVersion) 88 }