github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/enableagents.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  	"sync"
    21  
    22  	"k8s.io/apimachinery/pkg/util/sets"
    23  
    24  	"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/agent"
    25  	"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/agent/qrm"
    26  	_ "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu"
    27  	_ "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/io"
    28  	_ "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory"
    29  	_ "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/network"
    30  	"github.com/kubewharf/katalyst-core/pkg/agent/utilcomponent/periodicalhandler"
    31  	phconsts "github.com/kubewharf/katalyst-core/pkg/agent/utilcomponent/periodicalhandler/consts"
    32  )
    33  
    34  // AgentStarter is used to start katalyst agents
    35  type AgentStarter struct {
    36  	Init      agent.InitFunc
    37  	ExtraConf interface{}
    38  }
    39  
    40  // AgentsDisabledByDefault is the set of controllers which is disabled by default
    41  var AgentsDisabledByDefault = sets.NewString()
    42  
    43  // agentInitializers is used to store the initializing function for each agent
    44  var agentInitializers sync.Map
    45  
    46  func init() {
    47  	agentInitializers.Store(agent.ReporterManagerAgent, AgentStarter{Init: agent.InitReporterManager})
    48  	agentInitializers.Store(agent.EvictionManagerAgent, AgentStarter{Init: agent.InitEvictionManager})
    49  	agentInitializers.Store(agent.QoSSysAdvisor, AgentStarter{Init: agent.InitSysAdvisor})
    50  	agentInitializers.Store(phconsts.PeriodicalHandlerManagerName, AgentStarter{Init: periodicalhandler.NewPeriodicalHandlerManager})
    51  
    52  	agentInitializers.Store(agent.ORMAgent, AgentStarter{Init: agent.InitORM})
    53  
    54  	// qrm plugins are registered at top level of agent
    55  	agentInitializers.Store(qrm.QRMPluginNameCPU, AgentStarter{Init: qrm.InitQRMCPUPlugins})
    56  	agentInitializers.Store(qrm.QRMPluginNameMemory, AgentStarter{Init: qrm.InitQRMMemoryPlugins})
    57  	agentInitializers.Store(qrm.QRMPluginNameNetwork, AgentStarter{Init: qrm.InitQRMNetworkPlugins})
    58  	agentInitializers.Store(qrm.QRMPluginNameIO, AgentStarter{Init: qrm.InitQRMIOPlugins})
    59  }
    60  
    61  // RegisterAgentInitializer is used to register user-defined agents
    62  func RegisterAgentInitializer(name string, starter AgentStarter) {
    63  	agentInitializers.Store(name, starter)
    64  }
    65  
    66  // GetAgentInitializers returns those agents with initialized functions
    67  func GetAgentInitializers() map[string]AgentStarter {
    68  	agents := make(map[string]AgentStarter)
    69  	agentInitializers.Range(func(key, value interface{}) bool {
    70  		agents[key.(string)] = value.(AgentStarter)
    71  		return true
    72  	})
    73  	return agents
    74  }