volcano.sh/volcano@v1.9.0/cmd/scheduler/app/options/options.go (about) 1 /* 2 Copyright 2017 The Kubernetes 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 options 18 19 import ( 20 "fmt" 21 "os" 22 "time" 23 24 "github.com/spf13/pflag" 25 26 "volcano.sh/volcano/pkg/kube" 27 ) 28 29 const ( 30 defaultSchedulerName = "volcano" 31 defaultSchedulerPeriod = time.Second 32 defaultQueue = "default" 33 defaultListenAddress = ":8080" 34 defaultHealthzAddress = ":11251" 35 defaultPluginsDir = "" 36 37 defaultQPS = 2000.0 38 defaultBurst = 2000 39 40 // Default parameters to control the number of feasible nodes to find and score 41 defaultMinPercentageOfNodesToFind = 5 42 defaultMinNodesToFind = 100 43 defaultPercentageOfNodesToFind = 0 44 defaultLockObjectNamespace = "volcano-system" 45 defaultNodeWorkers = 20 46 ) 47 48 // ServerOption is the main context object for the controller manager. 49 type ServerOption struct { 50 KubeClientOptions kube.ClientOptions 51 CertFile string 52 KeyFile string 53 CaCertFile string 54 CertData []byte 55 KeyData []byte 56 CaCertData []byte 57 SchedulerNames []string 58 SchedulerConf string 59 SchedulePeriod time.Duration 60 EnableLeaderElection bool 61 LockObjectNamespace string 62 DefaultQueue string 63 PrintVersion bool 64 EnableMetrics bool 65 ListenAddress string 66 EnablePriorityClass bool 67 EnableCSIStorage bool 68 // vc-scheduler will load (not activate) custom plugins which are in this directory 69 PluginsDir string 70 EnableHealthz bool 71 // HealthzBindAddress is the IP address and port for the health check server to serve on 72 // defaulting to :11251 73 HealthzBindAddress string 74 // Parameters for scheduling tuning: the number of feasible nodes to find and score 75 MinNodesToFind int32 76 MinPercentageOfNodesToFind int32 77 PercentageOfNodesToFind int32 78 79 NodeSelector []string 80 CacheDumpFileDir string 81 EnableCacheDumper bool 82 NodeWorkerThreads uint32 83 84 // IgnoredCSIProvisioners contains a list of provisioners, and pod request pvc with these provisioners will 85 // not be counted in pod pvc resource request and node.Allocatable, because the spec.drivers of csinode resource 86 // is always null, these provisioners usually are host path csi controllers like rancher.io/local-path and hostpath.csi.k8s.io. 87 IgnoredCSIProvisioners []string 88 } 89 90 // DecryptFunc is custom function to parse ca file 91 type DecryptFunc func(c *ServerOption) error 92 93 // ServerOpts server options. 94 var ServerOpts *ServerOption 95 96 // NewServerOption creates a new CMServer with a default config. 97 func NewServerOption() *ServerOption { 98 return &ServerOption{} 99 } 100 101 // AddFlags adds flags for a specific CMServer to the specified FlagSet. 102 func (s *ServerOption) AddFlags(fs *pflag.FlagSet) { 103 fs.StringVar(&s.KubeClientOptions.Master, "master", s.KubeClientOptions.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)") 104 fs.StringVar(&s.KubeClientOptions.KubeConfig, "kubeconfig", s.KubeClientOptions.KubeConfig, "Path to kubeconfig file with authorization and master location information") 105 fs.StringVar(&s.CaCertFile, "ca-cert-file", s.CaCertFile, "File containing the x509 Certificate for HTTPS.") 106 fs.StringVar(&s.CertFile, "tls-cert-file", s.CertFile, ""+ 107 "File containing the default x509 Certificate for HTTPS. (CA cert, if any, concatenated "+ 108 "after server cert).") 109 fs.StringVar(&s.KeyFile, "tls-private-key-file", s.KeyFile, "File containing the default x509 private key matching --tls-cert-file.") 110 // volcano scheduler will ignore pods with scheduler names other than specified with the option 111 fs.StringArrayVar(&s.SchedulerNames, "scheduler-name", []string{defaultSchedulerName}, "vc-scheduler will handle pods whose .spec.SchedulerName is same as scheduler-name") 112 fs.StringVar(&s.SchedulerConf, "scheduler-conf", "", "The absolute path of scheduler configuration file") 113 fs.DurationVar(&s.SchedulePeriod, "schedule-period", defaultSchedulerPeriod, "The period between each scheduling cycle") 114 fs.StringVar(&s.DefaultQueue, "default-queue", defaultQueue, "The default queue name of the job") 115 fs.BoolVar(&s.EnableLeaderElection, "leader-elect", true, 116 "Start a leader election client and gain leadership before "+ 117 "executing the main loop. Enable this when running replicated vc-scheduler for high availability; it is enabled by default") 118 fs.BoolVar(&s.PrintVersion, "version", false, "Show version and quit") 119 fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", defaultLockObjectNamespace, "Define the namespace of the lock object that is used for leader election; it is volcano-system by default") 120 fs.StringVar(&s.ListenAddress, "listen-address", defaultListenAddress, "The address to listen on for HTTP requests.") 121 fs.StringVar(&s.HealthzBindAddress, "healthz-address", defaultHealthzAddress, "The address to listen on for the health check server.") 122 fs.BoolVar(&s.EnablePriorityClass, "priority-class", true, 123 "Enable PriorityClass to provide the capacity of preemption at pod group level; to disable it, set it false") 124 fs.Float32Var(&s.KubeClientOptions.QPS, "kube-api-qps", defaultQPS, "QPS to use while talking with kubernetes apiserver") 125 fs.IntVar(&s.KubeClientOptions.Burst, "kube-api-burst", defaultBurst, "Burst to use while talking with kubernetes apiserver") 126 127 // Minimum number of feasible nodes to find and score 128 fs.Int32Var(&s.MinNodesToFind, "minimum-feasible-nodes", defaultMinNodesToFind, "The minimum number of feasible nodes to find and score") 129 130 // Minimum percentage of nodes to find and score 131 fs.Int32Var(&s.MinPercentageOfNodesToFind, "minimum-percentage-nodes-to-find", defaultMinPercentageOfNodesToFind, "The minimum percentage of nodes to find and score") 132 133 // The percentage of nodes that would be scored in each scheduling cycle; if <= 0, an adpative percentage will be calcuated 134 fs.Int32Var(&s.PercentageOfNodesToFind, "percentage-nodes-to-find", defaultPercentageOfNodesToFind, "The percentage of nodes to find and score, if <=0 will be calcuated based on the cluster size") 135 136 fs.StringVar(&s.PluginsDir, "plugins-dir", defaultPluginsDir, "vc-scheduler will load custom plugins which are in this directory") 137 fs.BoolVar(&s.EnableCSIStorage, "csi-storage", false, 138 "Enable tracking of available storage capacity that CSI drivers provide; it is false by default") 139 fs.BoolVar(&s.EnableHealthz, "enable-healthz", false, "Enable the health check; it is false by default") 140 fs.BoolVar(&s.EnableMetrics, "enable-metrics", false, "Enable the metrics function; it is false by default") 141 fs.StringSliceVar(&s.NodeSelector, "node-selector", nil, "volcano only work with the labeled node, like: --node-selector=volcano.sh/role:train --node-selector=volcano.sh/role:serving") 142 fs.BoolVar(&s.EnableCacheDumper, "cache-dumper", true, "Enable the cache dumper, it's true by default") 143 fs.StringVar(&s.CacheDumpFileDir, "cache-dump-dir", "/tmp", "The target dir where the json file put at when dump cache info to json file") 144 fs.Uint32Var(&s.NodeWorkerThreads, "node-worker-threads", defaultNodeWorkers, "The number of threads syncing node operations.") 145 fs.StringSliceVar(&s.IgnoredCSIProvisioners, "ignored-provisioners", nil, "The provisioners that will be ignored during pod pvc request computation and preemption.") 146 } 147 148 // CheckOptionOrDie check lock-object-namespace when LeaderElection is enabled. 149 func (s *ServerOption) CheckOptionOrDie() error { 150 if s.EnableLeaderElection && s.LockObjectNamespace == "" { 151 return fmt.Errorf("lock-object-namespace must not be nil when LeaderElection is enabled") 152 } 153 154 return nil 155 } 156 157 // RegisterOptions registers options. 158 func (s *ServerOption) RegisterOptions() { 159 ServerOpts = s 160 } 161 162 // readCAFiles read data from ca file path 163 func (s *ServerOption) readCAFiles() error { 164 var err error 165 166 s.CaCertData, err = os.ReadFile(s.CaCertFile) 167 if err != nil { 168 return fmt.Errorf("failed to read cacert file (%s): %v", s.CaCertFile, err) 169 } 170 171 s.CertData, err = os.ReadFile(s.CertFile) 172 if err != nil { 173 return fmt.Errorf("failed to read cert file (%s): %v", s.CertFile, err) 174 } 175 176 s.KeyData, err = os.ReadFile(s.KeyFile) 177 if err != nil { 178 return fmt.Errorf("failed to read key file (%s): %v", s.KeyFile, err) 179 } 180 181 return nil 182 } 183 184 // ParseCAFiles parse ca file by decryptFunc 185 func (s *ServerOption) ParseCAFiles(decryptFunc DecryptFunc) error { 186 if err := s.readCAFiles(); err != nil { 187 return err 188 } 189 190 // users can add one function to decrypt tha data by their own way if CA data is encrypted 191 if decryptFunc != nil { 192 return decryptFunc(s) 193 } 194 195 return nil 196 } 197 198 // Default new and registry a default one 199 func Default() *ServerOption { 200 s := NewServerOption() 201 s.AddFlags(pflag.CommandLine) 202 s.RegisterOptions() 203 return s 204 }