github.com/kubewharf/katalyst-core@v0.5.3/pkg/controller/lifecycle/agent-healthz/handler/handler.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 handler
    18  
    19  import (
    20  	"context"
    21  	"sync"
    22  
    23  	"k8s.io/apimachinery/pkg/labels"
    24  	corelisters "k8s.io/client-go/listers/core/v1"
    25  	"k8s.io/client-go/tools/cache"
    26  
    27  	listers "github.com/kubewharf/katalyst-api/pkg/client/listers/node/v1alpha1"
    28  	"github.com/kubewharf/katalyst-core/pkg/config/controller"
    29  	"github.com/kubewharf/katalyst-core/pkg/config/generic"
    30  	"github.com/kubewharf/katalyst-core/pkg/controller/lifecycle/agent-healthz/helper"
    31  	"github.com/kubewharf/katalyst-core/pkg/metrics"
    32  )
    33  
    34  // AgentHandler defines the standard interface to handle
    35  // unhealthy states for each individual agent
    36  type AgentHandler interface {
    37  	// GetEvictionInfo returns eviction item for the given node-name
    38  	GetEvictionInfo(node string) (*helper.EvictItem, bool)
    39  
    40  	// GetCNRTaintInfo returns a map mapping for the given node-name
    41  	GetCNRTaintInfo(node string) (*helper.CNRTaintItem, bool)
    42  }
    43  
    44  type InitFunc func(ctx context.Context, agent string, emitter metrics.MetricEmitter,
    45  	_ *generic.GenericConfiguration, _ *controller.LifeCycleConfig, nodeSelector labels.Selector,
    46  	podIndexer cache.Indexer, nodeLister corelisters.NodeLister,
    47  	cnrLister listers.CustomNodeResourceLister,
    48  	checker *helper.HealthzHelper) AgentHandler
    49  
    50  var handlerMap sync.Map
    51  
    52  func RegisterAgentHandlerFunc(name string, f InitFunc) {
    53  	handlerMap.Store(name, f)
    54  }
    55  
    56  func GetRegisterAgentHandlerFuncs() map[string]InitFunc {
    57  	handlers := make(map[string]InitFunc)
    58  	handlerMap.Range(func(key, value interface{}) bool {
    59  		handlers[key.(string)] = value.(InitFunc)
    60  		return true
    61  	})
    62  	return handlers
    63  }