github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/qrm/qrm_base.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 qrm
    18  
    19  import (
    20  	cliflag "k8s.io/component-base/cli/flag"
    21  
    22  	qrmconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/qrm"
    23  )
    24  
    25  type GenericQRMPluginOptions struct {
    26  	QRMPluginSocketDirs      []string
    27  	StateFileDirectory       string
    28  	ExtraStateFileAbsPath    string
    29  	PodDebugAnnoKeys         []string
    30  	UseKubeletReservedConfig bool
    31  }
    32  
    33  func NewGenericQRMPluginOptions() *GenericQRMPluginOptions {
    34  	return &GenericQRMPluginOptions{
    35  		QRMPluginSocketDirs: []string{"/var/lib/kubelet/plugins_registry"},
    36  		StateFileDirectory:  "/var/lib/katalyst/qrm_advisor",
    37  		PodDebugAnnoKeys:    []string{},
    38  	}
    39  }
    40  
    41  func (o *GenericQRMPluginOptions) AddFlags(fss *cliflag.NamedFlagSets) {
    42  	fs := fss.FlagSet("qrm")
    43  
    44  	fs.StringSliceVar(&o.QRMPluginSocketDirs, "qrm-socket-dirs",
    45  		o.QRMPluginSocketDirs, "socket file directories that qrm plugins communicate witch other components")
    46  	fs.StringVar(&o.StateFileDirectory, "qrm-state-dir", o.StateFileDirectory, "Directory that qrm plugins are using")
    47  	fs.StringVar(&o.ExtraStateFileAbsPath, "qrm-extra-state-file", o.ExtraStateFileAbsPath, "The absolute path to an extra state file to specify cpuset.mems for specific pods")
    48  	fs.StringSliceVar(&o.PodDebugAnnoKeys, "qrm-pod-debug-anno-keys",
    49  		o.PodDebugAnnoKeys, "pod annotations keys to identify the pod is a debug pod, and qrm plugins will apply specific strategy to it")
    50  	fs.BoolVar(&o.UseKubeletReservedConfig, "use-kubelet-reserved-config",
    51  		o.UseKubeletReservedConfig, "if set true, we will prefer to use kubelet reserved config to reserved resource configuration in katalyst")
    52  }
    53  
    54  func (o *GenericQRMPluginOptions) ApplyTo(conf *qrmconfig.GenericQRMPluginConfiguration) error {
    55  	conf.QRMPluginSocketDirs = o.QRMPluginSocketDirs
    56  	conf.StateFileDirectory = o.StateFileDirectory
    57  	conf.ExtraStateFileAbsPath = o.ExtraStateFileAbsPath
    58  	conf.PodDebugAnnoKeys = o.PodDebugAnnoKeys
    59  	conf.UseKubeletReservedConfig = o.UseKubeletReservedConfig
    60  	return nil
    61  }
    62  
    63  type QRMPluginsOptions struct {
    64  	CPUOptions     *CPUOptions
    65  	MemoryOptions  *MemoryOptions
    66  	NetworkOptions *NetworkOptions
    67  	IOOptions      *IOOptions
    68  }
    69  
    70  func NewQRMPluginsOptions() *QRMPluginsOptions {
    71  	return &QRMPluginsOptions{
    72  		CPUOptions:     NewCPUOptions(),
    73  		MemoryOptions:  NewMemoryOptions(),
    74  		NetworkOptions: NewNetworkOptions(),
    75  		IOOptions:      NewIOOptions(),
    76  	}
    77  }
    78  
    79  func (o *QRMPluginsOptions) AddFlags(fss *cliflag.NamedFlagSets) {
    80  	o.CPUOptions.AddFlags(fss)
    81  	o.MemoryOptions.AddFlags(fss)
    82  	o.NetworkOptions.AddFlags(fss)
    83  	o.IOOptions.AddFlags(fss)
    84  }
    85  
    86  func (o *QRMPluginsOptions) ApplyTo(conf *qrmconfig.QRMPluginsConfiguration) error {
    87  	if err := o.CPUOptions.ApplyTo(conf.CPUQRMPluginConfig); err != nil {
    88  		return err
    89  	}
    90  	if err := o.MemoryOptions.ApplyTo(conf.MemoryQRMPluginConfig); err != nil {
    91  		return err
    92  	}
    93  	if err := o.NetworkOptions.ApplyTo(conf.NetworkQRMPluginConfig); err != nil {
    94  		return err
    95  	}
    96  	if err := o.IOOptions.ApplyTo(conf.IOQRMPluginConfig); err != nil {
    97  		return err
    98  	}
    99  	return nil
   100  }