github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-controller/app/controller/monitor.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/monitor"
    27  )
    28  
    29  const (
    30  	MonitorControllerName = "monitor"
    31  )
    32  
    33  func StartMonitorController(ctx context.Context, controlCtx *katalystbase.GenericContext,
    34  	conf *config.Configuration, _ interface{}, _ string,
    35  ) (bool, error) {
    36  	var (
    37  		cnrMonitorController *monitor.CNRMonitorController
    38  		err                  error
    39  	)
    40  
    41  	if conf.MonitorConfig.EnableCNRMonitor {
    42  		cnrMonitorController, err = monitor.NewCNRMonitorController(ctx,
    43  			conf.GenericConfiguration,
    44  			conf.GenericControllerConfiguration,
    45  			conf.CNRMonitorConfig,
    46  			controlCtx.Client,
    47  			controlCtx.KubeInformerFactory.Core().V1().Nodes(),
    48  			controlCtx.KubeInformerFactory.Core().V1().Pods(),
    49  			controlCtx.InternalInformerFactory.Node().V1alpha1().CustomNodeResources(),
    50  			controlCtx.EmitterPool.GetDefaultMetricsEmitter(),
    51  		)
    52  		if err != nil {
    53  			klog.Errorf("failed to new CNR monitor controller")
    54  			return false, err
    55  		}
    56  	}
    57  
    58  	if cnrMonitorController != nil {
    59  		go cnrMonitorController.Run()
    60  	}
    61  
    62  	return true, nil
    63  }