github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-controller/app/enablecontrollers.go (about) 1 /* 2 Copyright 2022 The Katalyst 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 app 18 19 import ( 20 "context" 21 "sync" 22 23 "k8s.io/apimachinery/pkg/util/sets" 24 25 katalystbase "github.com/kubewharf/katalyst-core/cmd/base" 26 "github.com/kubewharf/katalyst-core/cmd/katalyst-controller/app/controller" 27 "github.com/kubewharf/katalyst-core/pkg/config" 28 ) 29 30 // StartFunc is used to launch a particular controller. 31 // It may run additional "should I activate checks". 32 // Any error returned will cause the controller process to `Fatal` 33 // The bool indicates whether the controller was enabled. 34 type StartFunc func(ctx context.Context, controlCtx *katalystbase.GenericContext, conf *config.Configuration, 35 extraControllerConf interface{}, controllerName string) (bool, error) 36 37 // ControllerStarter is used to start katalyst controllers 38 type ControllerStarter struct { 39 Starter StartFunc 40 ExtraConf interface{} 41 } 42 43 // ControllersDisabledByDefault is the set of controllers which is disabled by default 44 var ControllersDisabledByDefault = sets.NewString() 45 46 // ControllerInitializers is used to store the initializing function for each controller 47 var controllerInitializers sync.Map 48 49 func init() { 50 controllerInitializers.Store(controller.VPAControllerName, ControllerStarter{Starter: controller.StartVPAController}) 51 controllerInitializers.Store(controller.KCCControllerName, ControllerStarter{Starter: controller.StartKCCController}) 52 controllerInitializers.Store(controller.SPDControllerName, ControllerStarter{Starter: controller.StartSPDController}) 53 controllerInitializers.Store(controller.LifeCycleControllerName, ControllerStarter{Starter: controller.StartLifeCycleController}) 54 controllerInitializers.Store(controller.MonitorControllerName, ControllerStarter{Starter: controller.StartMonitorController}) 55 controllerInitializers.Store(controller.OvercommitControllerName, ControllerStarter{Starter: controller.StartOvercommitController}) 56 controllerInitializers.Store(controller.TideControllerName, ControllerStarter{Starter: controller.StartTideController}) 57 controllerInitializers.Store(controller.ResourceRecommenderControllerName, ControllerStarter{Starter: controller.StartResourceRecommenderController}) 58 } 59 60 // RegisterControllerInitializer is used to register user-defined controllers 61 func RegisterControllerInitializer(name string, starter ControllerStarter) { 62 controllerInitializers.Store(name, starter) 63 } 64 65 // GetControllerInitializers returns those controllers with initialized functions 66 func GetControllerInitializers() map[string]ControllerStarter { 67 controllers := make(map[string]ControllerStarter) 68 controllerInitializers.Range(func(key, value interface{}) bool { 69 controllers[key.(string)] = value.(ControllerStarter) 70 return true 71 }) 72 return controllers 73 }