sigs.k8s.io/kueue@v0.6.2/pkg/controller/admissionchecks/multikueue/controllers.go (about) 1 /* 2 Copyright 2024 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 multikueue 18 19 import ( 20 "time" 21 22 ctrl "sigs.k8s.io/controller-runtime" 23 ) 24 25 const ( 26 defaultGCInterval = time.Minute 27 defaultOrigin = "multikueue" 28 ) 29 30 type SetupOptions struct { 31 gcInterval time.Duration 32 origin string 33 } 34 35 type SetupOption func(o *SetupOptions) 36 37 // WithGCInterval - sets the interval between two garbage collection runs. 38 // If 0 the garbage collection is disabled. 39 func WithGCInterval(i time.Duration) SetupOption { 40 return func(o *SetupOptions) { 41 o.gcInterval = i 42 } 43 } 44 45 // WithOrigin - sets the multikueue-origin label value used by this manager 46 func WithOrigin(origin string) SetupOption { 47 return func(o *SetupOptions) { 48 o.origin = origin 49 } 50 } 51 52 func SetupControllers(mgr ctrl.Manager, namespace string, opts ...SetupOption) error { 53 options := &SetupOptions{ 54 gcInterval: defaultGCInterval, 55 origin: defaultOrigin, 56 } 57 58 for _, o := range opts { 59 o(options) 60 } 61 62 helper, err := newMultiKueueStoreHelper(mgr.GetClient()) 63 if err != nil { 64 return err 65 } 66 67 cRec := newClustersReconciler(mgr.GetClient(), namespace, options.gcInterval, options.origin) 68 err = cRec.setupWithManager(mgr) 69 if err != nil { 70 return err 71 } 72 73 acRec := newACReconciler(mgr.GetClient(), helper) 74 err = acRec.setupWithManager(mgr) 75 if err != nil { 76 return err 77 } 78 79 wlRec := newWlReconciler(mgr.GetClient(), helper, cRec, options.origin) 80 return wlRec.setupWithManager(mgr) 81 }