agones.dev/agones@v1.53.0/pkg/apis/allocation/v1/register.go (about) 1 // Copyright 2019 Google LLC All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package v1 16 17 import ( 18 "agones.dev/agones/pkg/apis/allocation" 19 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 k8sruntime "k8s.io/apimachinery/pkg/runtime" 21 "k8s.io/apimachinery/pkg/runtime/schema" 22 "k8s.io/client-go/kubernetes/scheme" 23 ) 24 25 // SchemeGroupVersion is group version used to register these objects 26 var SchemeGroupVersion = schema.GroupVersion{Group: allocation.GroupName, Version: "v1"} 27 28 // Kind takes an unqualified kind and returns back a Group qualified GroupKind 29 func Kind(kind string) schema.GroupKind { 30 return SchemeGroupVersion.WithKind(kind).GroupKind() 31 } 32 33 // Resource takes an unqualified resource and returns a Group qualified GroupResource 34 func Resource(resource string) schema.GroupResource { 35 return SchemeGroupVersion.WithResource(resource).GroupResource() 36 } 37 38 var ( 39 // SchemeBuilder registers our types 40 SchemeBuilder = k8sruntime.NewSchemeBuilder(addKnownTypes) 41 // AddToScheme local alias for SchemeBuilder.AddToScheme 42 AddToScheme = SchemeBuilder.AddToScheme 43 ) 44 45 func init() { 46 if err := AddToScheme(scheme.Scheme); err != nil { 47 panic(err) 48 } 49 } 50 51 // Adds the list of known types to api.Scheme. 52 func addKnownTypes(apiScheme *k8sruntime.Scheme) error { 53 apiScheme.AddKnownTypes(SchemeGroupVersion, 54 &GameServerAllocation{}, 55 &GameServerAllocationList{}, 56 ) 57 metav1.AddToGroupVersion(apiScheme, SchemeGroupVersion) 58 return nil 59 }