github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/apis/meta/v1/register.go (about)

     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  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime"
    21  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime/schema"
    22  	utilruntime "github.com/spotmaxtech/k8s-apimachinery-v0260/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  	&GetOptions{},
    59  	&DeleteOptions{},
    60  	&CreateOptions{},
    61  	&UpdateOptions{},
    62  	&PatchOptions{},
    63  }
    64  
    65  // AddToGroupVersion registers common meta types into schemas.
    66  func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion) {
    67  	scheme.AddKnownTypeWithName(groupVersion.WithKind(WatchEventKind), &WatchEvent{})
    68  	scheme.AddKnownTypeWithName(
    69  		schema.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}.WithKind(WatchEventKind),
    70  		&InternalEvent{},
    71  	)
    72  	// Supports legacy code paths, most callers should use metav1.ParameterCodec for now
    73  	scheme.AddKnownTypes(groupVersion, optionsTypes...)
    74  	// Register Unversioned types under their own special group
    75  	scheme.AddUnversionedTypes(Unversioned,
    76  		&Status{},
    77  		&APIVersions{},
    78  		&APIGroupList{},
    79  		&APIGroup{},
    80  		&APIResourceList{},
    81  	)
    82  
    83  	// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
    84  	utilruntime.Must(RegisterConversions(scheme))
    85  	utilruntime.Must(RegisterDefaults(scheme))
    86  }
    87  
    88  // AddMetaToScheme registers base meta types into schemas.
    89  func AddMetaToScheme(scheme *runtime.Scheme) error {
    90  	scheme.AddKnownTypes(SchemeGroupVersion,
    91  		&Table{},
    92  		&TableOptions{},
    93  		&PartialObjectMetadata{},
    94  		&PartialObjectMetadataList{},
    95  	)
    96  
    97  	return nil
    98  }
    99  
   100  func init() {
   101  	scheme.AddUnversionedTypes(SchemeGroupVersion, optionsTypes...)
   102  
   103  	utilruntime.Must(AddMetaToScheme(scheme))
   104  
   105  	// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
   106  	utilruntime.Must(RegisterDefaults(scheme))
   107  }