sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/apis/prowjobs/v1/register.go (about) 1 /* 2 Copyright 2018 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 "fmt" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 "k8s.io/apimachinery/pkg/runtime" 24 "k8s.io/apimachinery/pkg/runtime/schema" 25 "k8s.io/client-go/kubernetes/scheme" 26 27 "sigs.k8s.io/prow/pkg/apis/prowjobs" 28 ) 29 30 func init() { 31 if err := AddToScheme(scheme.Scheme); err != nil { 32 panic(fmt.Sprintf("failed to add prowjob api to scheme: %v", err)) 33 } 34 } 35 36 // SchemeGroupVersion is group version used to register these objects 37 var SchemeGroupVersion = schema.GroupVersion{Group: prowjobs.GroupName, Version: "v1"} 38 39 // Kind takes an unqualified kind and returns back a Group qualified GroupKind 40 func Kind(kind string) schema.GroupKind { 41 return SchemeGroupVersion.WithKind(kind).GroupKind() 42 } 43 44 // Resource takes an unqualified resource and returns a Group qualified GroupResource 45 func Resource(resource string) schema.GroupResource { 46 return SchemeGroupVersion.WithResource(resource).GroupResource() 47 } 48 49 var ( 50 // SchemeBuilder collects functions that add things to a scheme. 51 SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 52 // AddToScheme applies all the stored functions to the scheme. 53 AddToScheme = SchemeBuilder.AddToScheme 54 ) 55 56 // Adds the list of known types to the Scheme. 57 func addKnownTypes(scheme *runtime.Scheme) error { 58 scheme.AddKnownTypes(SchemeGroupVersion, 59 &ProwJob{}, 60 &ProwJobList{}, 61 ) 62 metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 63 return nil 64 }