github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/global/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 global 18 19 import ( 20 "k8s.io/apimachinery/pkg/api/resource" 21 cliflag "k8s.io/component-base/cli/flag" 22 23 "github.com/kubewharf/katalyst-core/pkg/config/agent/global" 24 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" 25 ) 26 27 const ( 28 defaultKubeletReadOnlyPort = 10255 29 defaultKubeletSecurePort = 10250 30 defaultKubeletSecurePortEnabled = false 31 defaultKubeletConfigURI = "/configz" 32 defaultKubeletPodsEndpoint = "/pods" 33 defaultKubeletSummaryEndpoint = "/stats/summary" 34 defaultAPIAuthTokenFile = "/var/run/secrets/kubernetes.io/serviceaccount/token" 35 ) 36 37 const defaultRemoteRuntimeEndpoint = "unix:///run/containerd/containerd.sock" 38 39 // BaseOptions holds all the configurations for agent-base. 40 // we will not try to separate this structure into several individual 41 // structures since it will not be used directly by other components; instead, 42 // we will only separate them with blanks in a single structure. 43 type BaseOptions struct { 44 Agents []string 45 NodeName string 46 NodeAddress string 47 LockFileName string 48 LockWaitingEnabled bool 49 50 CgroupType string 51 AdditionalCgroupPaths []string 52 53 ReclaimRelativeRootCgroupPath string 54 GeneralRelativeCgroupPaths []string 55 OptionalRelativeCgroupPaths []string 56 57 // configurations for kubelet 58 KubeletReadOnlyPort int 59 KubeletSecurePort int 60 KubeletSecurePortEnabled bool 61 KubeletConfigEndpoint string 62 KubeletPodsEndpoint string 63 KubeletSummaryEndpoint string 64 APIAuthTokenFile string 65 66 // configurations for runtime 67 RuntimeEndpoint string 68 69 // configurations for machine-info 70 MachineNetMultipleNS bool 71 MachineNetNSDirAbsPath string 72 MachineSiblingNumaMemoryBandwidthCapacity resource.QuantityValue 73 MachineSiblingNumaMemoryBandwidthAllocatableRate float64 74 } 75 76 func NewBaseOptions() *BaseOptions { 77 return &BaseOptions{ 78 LockFileName: "/tmp/katalyst_agent_lock", 79 LockWaitingEnabled: false, 80 81 CgroupType: "cgroupfs", 82 83 ReclaimRelativeRootCgroupPath: "/kubepods/besteffort", 84 85 KubeletReadOnlyPort: defaultKubeletReadOnlyPort, 86 KubeletSecurePort: defaultKubeletSecurePort, 87 KubeletSecurePortEnabled: defaultKubeletSecurePortEnabled, 88 KubeletConfigEndpoint: defaultKubeletConfigURI, 89 KubeletPodsEndpoint: defaultKubeletPodsEndpoint, 90 KubeletSummaryEndpoint: defaultKubeletSummaryEndpoint, 91 APIAuthTokenFile: defaultAPIAuthTokenFile, 92 93 RuntimeEndpoint: defaultRemoteRuntimeEndpoint, 94 95 MachineNetMultipleNS: false, 96 MachineSiblingNumaMemoryBandwidthAllocatableRate: 1.0, 97 } 98 } 99 100 // AddFlags adds flags to the specified FlagSet. 101 func (o *BaseOptions) AddFlags(fss *cliflag.NamedFlagSets) { 102 fs := fss.FlagSet("base") 103 104 fs.StringSliceVar(&o.Agents, "agents", o.Agents, "The agents need to be started") 105 fs.StringVar(&o.NodeName, "node-name", o.NodeName, "the name of this node") 106 fs.StringVar(&o.NodeAddress, "node-address", o.NodeAddress, "the address of this node") 107 108 fs.StringVar(&o.LockFileName, "locking-file", o.LockFileName, "The filename used as unique lock") 109 fs.BoolVar(&o.LockWaitingEnabled, "locking-waiting", o.LockWaitingEnabled, 110 "If failed to acquire locking files, still mark agent as healthy") 111 112 fs.StringVar(&o.CgroupType, "cgroup-type", o.CgroupType, "The cgroup type") 113 fs.StringSliceVar(&o.AdditionalCgroupPaths, "addition-cgroup-paths", o.AdditionalCgroupPaths, 114 "The additional cgroup paths to be added for legacy configurations") 115 116 fs.StringVar(&o.ReclaimRelativeRootCgroupPath, "reclaim-relative-root-cgroup-path", o.ReclaimRelativeRootCgroupPath, 117 "top level cgroup path for reclaimed_cores qos level") 118 fs.StringSliceVar(&o.GeneralRelativeCgroupPaths, "malachite-general-relative-cgroup-paths", o.GeneralRelativeCgroupPaths, 119 "The cgroup paths of standalone services which not managed by kubernetes, errors will occur if these paths not existed") 120 fs.StringSliceVar(&o.OptionalRelativeCgroupPaths, "malachite-optional-relative-cgroup-paths", o.OptionalRelativeCgroupPaths, 121 "The cgroup paths of standalone services which not managed by kubernetes") 122 123 fs.IntVar(&o.KubeletReadOnlyPort, "kubelet-read-only-port", o.KubeletReadOnlyPort, 124 "The read-only port for the kubelet to serve") 125 fs.IntVar(&o.KubeletSecurePort, "kubelet-secure-port", o.KubeletSecurePort, 126 "The secure port for the kubelet to serve") 127 fs.BoolVar(&o.KubeletSecurePortEnabled, "enable-kubelet-secure-port", o.KubeletSecurePortEnabled, 128 "Whether to enable get contents from kubelet secure port") 129 fs.StringVar(&o.KubeletConfigEndpoint, "kubelet-config-endpoint", o.KubeletConfigEndpoint, 130 "The URI of kubelet config endpoint") 131 fs.StringVar(&o.KubeletPodsEndpoint, "kubelet-pods-endpoint", o.KubeletPodsEndpoint, 132 "The URI of kubelet pods endpoint") 133 fs.StringVar(&o.KubeletSummaryEndpoint, "kubelet-summary-endpoint", o.KubeletSummaryEndpoint, 134 "The URI of kubelet summary endpoint") 135 fs.StringVar(&o.APIAuthTokenFile, "api-auth-token-file", o.APIAuthTokenFile, 136 "The path of the API auth token file") 137 138 fs.StringVar(&o.RuntimeEndpoint, "remote-runtime-endpoint", o.RuntimeEndpoint, 139 "The endpoint of remote runtime service") 140 141 fs.BoolVar(&o.MachineNetMultipleNS, "machine-net-multi-ns", o.MachineNetMultipleNS, 142 "if set as true, we should collect network interfaces from multiple ns") 143 fs.StringVar(&o.MachineNetNSDirAbsPath, "machine-net-ns-dir", o.MachineNetNSDirAbsPath, 144 "if set as true, we should collect network interfaces from multiple ns") 145 146 fs.Var(&o.MachineSiblingNumaMemoryBandwidthCapacity, "machine-sibling-numa-memory-bandwidth-capacity", 147 "if set the sibling numa memory bandwidth capacity, the per memory bandwidth capacity and allocatable will be reported to numa zone of cnr") 148 fs.Float64Var(&o.MachineSiblingNumaMemoryBandwidthAllocatableRate, "machine-sibling-numa-memory-bandwidth-allocatable-rate", o.MachineSiblingNumaMemoryBandwidthAllocatableRate, 149 "the rate between sibling numa memory bandwidth allocatable to its capacity") 150 } 151 152 // ApplyTo fills up config with options 153 func (o *BaseOptions) ApplyTo(c *global.BaseConfiguration) error { 154 c.Agents = o.Agents 155 c.NodeName = o.NodeName 156 c.NodeAddress = o.NodeAddress 157 c.LockFileName = o.LockFileName 158 c.LockWaitingEnabled = o.LockWaitingEnabled 159 160 c.ReclaimRelativeRootCgroupPath = o.ReclaimRelativeRootCgroupPath 161 c.GeneralRelativeCgroupPaths = o.GeneralRelativeCgroupPaths 162 c.OptionalRelativeCgroupPaths = o.OptionalRelativeCgroupPaths 163 164 c.NetMultipleNS = o.MachineNetMultipleNS 165 c.NetNSDirAbsPath = o.MachineNetNSDirAbsPath 166 c.SiblingNumaMemoryBandwidthCapacity = o.MachineSiblingNumaMemoryBandwidthCapacity.Quantity.Value() 167 c.SiblingNumaMemoryBandwidthAllocatableRate = o.MachineSiblingNumaMemoryBandwidthAllocatableRate 168 169 c.KubeletReadOnlyPort = o.KubeletReadOnlyPort 170 c.KubeletSecurePortEnabled = o.KubeletSecurePortEnabled 171 c.KubeletSecurePort = o.KubeletSecurePort 172 c.KubeletConfigEndpoint = o.KubeletConfigEndpoint 173 c.KubeletPodsEndpoint = o.KubeletPodsEndpoint 174 c.KubeletSummaryEndpoint = o.KubeletSummaryEndpoint 175 c.APIAuthTokenFile = o.APIAuthTokenFile 176 177 c.RuntimeEndpoint = o.RuntimeEndpoint 178 179 common.InitKubernetesCGroupPath(common.CgroupType(o.CgroupType), o.AdditionalCgroupPaths) 180 return nil 181 }