sigs.k8s.io/kueue@v0.6.2/pkg/visibility/api/install.go (about) 1 // Copyright 2023 The Kubernetes Authors. 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 api 16 17 import ( 18 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 19 "k8s.io/apimachinery/pkg/runtime" 20 "k8s.io/apimachinery/pkg/runtime/schema" 21 "k8s.io/apimachinery/pkg/runtime/serializer" 22 utilruntime "k8s.io/apimachinery/pkg/util/runtime" 23 "k8s.io/apiserver/pkg/registry/rest" 24 genericapiserver "k8s.io/apiserver/pkg/server" 25 26 v1alpha1 "sigs.k8s.io/kueue/apis/visibility/v1alpha1" 27 "sigs.k8s.io/kueue/pkg/queue" 28 apirest "sigs.k8s.io/kueue/pkg/visibility/api/rest" 29 ) 30 31 var ( 32 Scheme = runtime.NewScheme() 33 34 Codecs = serializer.NewCodecFactory(Scheme) 35 36 ParameterCodec = runtime.NewParameterCodec(Scheme) 37 ) 38 39 func init() { 40 utilruntime.Must(v1alpha1.AddToScheme(Scheme)) 41 utilruntime.Must(Scheme.SetVersionPriority(v1alpha1.GroupVersion)) 42 metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) 43 } 44 45 // Install installs API scheme defined in apis/v1alpha1 and registers storage 46 func Install(server *genericapiserver.GenericAPIServer, kueueMgr *queue.Manager) error { 47 apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(v1alpha1.GroupVersion.Group, Scheme, ParameterCodec, Codecs) 48 pendingWorkloadsInCqREST := apirest.NewPendingWorkloadsInCqREST(kueueMgr) 49 cqREST := apirest.NewCqREST() 50 pendingWorkloadsInLqREST := apirest.NewPendingWorkloadsInLqREST(kueueMgr) 51 lqREST := apirest.NewLqREST() 52 53 visibilityServerResources := map[string]rest.Storage{ 54 "clusterqueues": cqREST, 55 "clusterqueues/pendingworkloads": pendingWorkloadsInCqREST, 56 "localqueues": lqREST, 57 "localqueues/pendingworkloads": pendingWorkloadsInLqREST, 58 } 59 apiGroupInfo.VersionedResourcesStorageMap[v1alpha1.GroupVersion.Version] = visibilityServerResources 60 return server.InstallAPIGroups(&apiGroupInfo) 61 }