github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/global/qrmadvisor.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 global
    18  
    19  import (
    20  	cliflag "k8s.io/component-base/cli/flag"
    21  
    22  	"github.com/kubewharf/katalyst-core/pkg/config/agent/global"
    23  )
    24  
    25  // QRMAdvisorOptions holds the configurations for both qrm plugins and sys advisor qrm servers
    26  type QRMAdvisorOptions struct {
    27  	CPUAdvisorSocketAbsPath string
    28  	CPUPluginSocketAbsPath  string
    29  
    30  	MemoryAdvisorSocketAbsPath string
    31  	MemoryPluginSocketAbsPath  string
    32  }
    33  
    34  // NewQRMAdvisorOptions creates a new options with a default config
    35  func NewQRMAdvisorOptions() *QRMAdvisorOptions {
    36  	return &QRMAdvisorOptions{
    37  		CPUAdvisorSocketAbsPath:    "/var/lib/katalyst/qrm_advisor/cpu_advisor.sock",
    38  		CPUPluginSocketAbsPath:     "/var/lib/katalyst/qrm_advisor/cpu_plugin.sock",
    39  		MemoryAdvisorSocketAbsPath: "/var/lib/katalyst/qrm_advisor/memory_advisor.sock",
    40  		MemoryPluginSocketAbsPath:  "/var/lib/katalyst/qrm_advisor/memory_plugin.sock",
    41  	}
    42  }
    43  
    44  // AddFlags adds flags to the specified FlagSet.
    45  func (o *QRMAdvisorOptions) AddFlags(fss *cliflag.NamedFlagSets) {
    46  	fs := fss.FlagSet("qrm-advisor")
    47  
    48  	fs.StringVar(&o.CPUAdvisorSocketAbsPath, "cpu-advisor-sock-abs-path", o.CPUAdvisorSocketAbsPath, "absolute path of socket file for cpu advisor served in sys-advisor")
    49  	fs.StringVar(&o.CPUPluginSocketAbsPath, "cpu-plugin-sock-abs-path", o.CPUPluginSocketAbsPath, "absolute path of socket file for cpu plugin to communicate with cpu advisor")
    50  	fs.StringVar(&o.MemoryAdvisorSocketAbsPath, "memory-advisor-sock-abs-path", o.MemoryAdvisorSocketAbsPath, "absolute path of socket file for memory advisor served in sys-advisor")
    51  	fs.StringVar(&o.MemoryPluginSocketAbsPath, "memory-plugin-sock-abs-path", o.MemoryPluginSocketAbsPath, "absolute path of socket file for cpu plugin to communicate with memory advisor")
    52  }
    53  
    54  // ApplyTo fills up config with options
    55  func (o *QRMAdvisorOptions) ApplyTo(c *global.QRMAdvisorConfiguration) error {
    56  	c.CPUAdvisorSocketAbsPath = o.CPUAdvisorSocketAbsPath
    57  	c.CPUPluginSocketAbsPath = o.CPUPluginSocketAbsPath
    58  	c.MemoryAdvisorSocketAbsPath = o.MemoryAdvisorSocketAbsPath
    59  	c.MemoryPluginSocketAbsPath = o.MemoryPluginSocketAbsPath
    60  	return nil
    61  }