github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/reporter/kubelet_plugin.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 reporter
    18  
    19  import (
    20  	v1 "k8s.io/api/core/v1"
    21  	cliflag "k8s.io/component-base/cli/flag"
    22  	pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1"
    23  
    24  	"github.com/kubewharf/katalyst-core/pkg/config/agent/reporter"
    25  )
    26  
    27  type KubeletPluginOptions struct {
    28  	PodResourcesServerEndpoints []string
    29  	KubeletResourcePluginPaths  []string
    30  	EnableReportTopologyPolicy  bool
    31  	ResourceNameToZoneTypeMap   map[string]string
    32  	NeedValidationResources     []string
    33  }
    34  
    35  func NewKubeletPluginOptions() *KubeletPluginOptions {
    36  	return &KubeletPluginOptions{
    37  		PodResourcesServerEndpoints: []string{
    38  			pluginapi.KubeletSocket,
    39  		},
    40  		KubeletResourcePluginPaths: []string{
    41  			pluginapi.ResourcePluginPath,
    42  		},
    43  		EnableReportTopologyPolicy: false,
    44  		ResourceNameToZoneTypeMap:  make(map[string]string),
    45  		NeedValidationResources: []string{
    46  			string(v1.ResourceCPU),
    47  			string(v1.ResourceMemory),
    48  		},
    49  	}
    50  }
    51  
    52  func (o *KubeletPluginOptions) AddFlags(fss *cliflag.NamedFlagSets) {
    53  	fs := fss.FlagSet("reporter-kubelet")
    54  
    55  	fs.StringSliceVar(&o.PodResourcesServerEndpoints, "pod-resources-server-endpoint", o.PodResourcesServerEndpoints,
    56  		"the endpoint of pod resource api server")
    57  	fs.StringSliceVar(&o.KubeletResourcePluginPaths, "kubelet-resource-plugin-path", o.KubeletResourcePluginPaths,
    58  		"the path of kubelet resource plugin")
    59  	fs.BoolVar(&o.EnableReportTopologyPolicy, "enable-report-topology-policy", o.EnableReportTopologyPolicy,
    60  		"whether to report topology policy")
    61  	fs.StringToStringVar(&o.ResourceNameToZoneTypeMap, "resource-name-to-zone-type-map", o.ResourceNameToZoneTypeMap,
    62  		"a map that stores the mapping relationship between resource names to zone types in KCNR (e.g. nvidia.com/gpu=GPU,...)")
    63  	fs.StringSliceVar(&o.NeedValidationResources, "need-validation-resources", o.NeedValidationResources,
    64  		"resources need to be validated")
    65  }
    66  
    67  func (o *KubeletPluginOptions) ApplyTo(c *reporter.KubeletPluginConfiguration) error {
    68  	c.PodResourcesServerEndpoints = o.PodResourcesServerEndpoints
    69  	c.KubeletResourcePluginPaths = o.KubeletResourcePluginPaths
    70  	c.EnableReportTopologyPolicy = o.EnableReportTopologyPolicy
    71  	c.ResourceNameToZoneTypeMap = o.ResourceNameToZoneTypeMap
    72  	c.NeedValidationResources = o.NeedValidationResources
    73  
    74  	return nil
    75  }