github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-controller/app/controller/kcc.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 controller 18 19 import ( 20 "context" 21 22 "k8s.io/klog/v2" 23 24 katalystbase "github.com/kubewharf/katalyst-core/cmd/base" 25 "github.com/kubewharf/katalyst-core/pkg/config" 26 "github.com/kubewharf/katalyst-core/pkg/controller/kcc" 27 kcctarget "github.com/kubewharf/katalyst-core/pkg/controller/kcc/target" 28 ) 29 30 const ( 31 KCCControllerName = "kcc" 32 ) 33 34 func StartKCCController(ctx context.Context, controlCtx *katalystbase.GenericContext, 35 conf *config.Configuration, _ interface{}, _ string, 36 ) (bool, error) { 37 // targetHandler is initialized once and shared by multiple controllers 38 targetHandler := kcctarget.NewKatalystCustomConfigTargetHandler( 39 ctx, 40 controlCtx.Client, 41 conf.ControllersConfiguration.KCCConfig, 42 controlCtx.InternalInformerFactory.Config().V1alpha1().KatalystCustomConfigs(), 43 ) 44 45 kccController, err := kcc.NewKatalystCustomConfigController( 46 ctx, 47 conf.GenericConfiguration, 48 conf.GenericControllerConfiguration, 49 conf.ControllersConfiguration.KCCConfig, 50 controlCtx.Client, 51 controlCtx.InternalInformerFactory.Config().V1alpha1().KatalystCustomConfigs(), 52 controlCtx.EmitterPool.GetDefaultMetricsEmitter(), 53 targetHandler, 54 ) 55 if err != nil { 56 klog.Errorf("failed to new kcc controller") 57 return false, err 58 } 59 60 kccTargetController, err := kcc.NewKatalystCustomConfigTargetController( 61 ctx, 62 conf.GenericConfiguration, 63 conf.GenericControllerConfiguration, 64 conf.ControllersConfiguration.KCCConfig, 65 controlCtx.Client, 66 controlCtx.InternalInformerFactory.Config().V1alpha1().KatalystCustomConfigs(), 67 controlCtx.EmitterPool.GetDefaultMetricsEmitter(), 68 targetHandler, 69 ) 70 if err != nil { 71 klog.Errorf("failed to new kcc target controller") 72 return false, err 73 } 74 75 cncController, err := kcc.NewCustomNodeConfigController( 76 ctx, 77 conf.GenericConfiguration, 78 conf.GenericControllerConfiguration, 79 conf.ControllersConfiguration.KCCConfig, 80 controlCtx.Client, 81 controlCtx.InternalInformerFactory.Config().V1alpha1().CustomNodeConfigs(), 82 controlCtx.EmitterPool.GetDefaultMetricsEmitter(), 83 targetHandler, 84 ) 85 if err != nil { 86 klog.Errorf("failed to new cnc controller") 87 return false, err 88 } 89 90 go targetHandler.Run() 91 go kccController.Run() 92 go kccTargetController.Run() 93 go cncController.Run() 94 return true, nil 95 }