k8s.io/kubernetes@v1.29.3/pkg/scheduler/apis/config/types.go (about) 1 /* 2 Copyright 2018 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 config 18 19 import ( 20 "math" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 "k8s.io/apimachinery/pkg/runtime" 24 "k8s.io/apimachinery/pkg/util/sets" 25 componentbaseconfig "k8s.io/component-base/config" 26 ) 27 28 const ( 29 // DefaultKubeSchedulerPort is the default port for the scheduler status server. 30 // May be overridden by a flag at startup. 31 DefaultKubeSchedulerPort = 10259 32 ) 33 34 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 35 36 // KubeSchedulerConfiguration configures a scheduler 37 type KubeSchedulerConfiguration struct { 38 // TypeMeta contains the API version and kind. In kube-scheduler, after 39 // conversion from the versioned KubeSchedulerConfiguration type to this 40 // internal type, we set the APIVersion field to the scheme group/version of 41 // the type we converted from. This is done in cmd/kube-scheduler in two 42 // places: (1) when loading config from a file, (2) generating the default 43 // config. Based on the versioned type set in this field, we make decisions; 44 // for example (1) during validation to check for usage of removed plugins, 45 // (2) writing config to a file, (3) initialising the scheduler. 46 metav1.TypeMeta 47 48 // Parallelism defines the amount of parallelism in algorithms for scheduling a Pods. Must be greater than 0. Defaults to 16 49 Parallelism int32 50 51 // LeaderElection defines the configuration of leader election client. 52 LeaderElection componentbaseconfig.LeaderElectionConfiguration 53 54 // ClientConnection specifies the kubeconfig file and client connection 55 // settings for the proxy server to use when communicating with the apiserver. 56 ClientConnection componentbaseconfig.ClientConnectionConfiguration 57 // HealthzBindAddress is the IP address and port for the health check server to serve on. 58 HealthzBindAddress string 59 // MetricsBindAddress is the IP address and port for the metrics server to serve on. 60 MetricsBindAddress string 61 62 // DebuggingConfiguration holds configuration for Debugging related features 63 // TODO: We might wanna make this a substruct like Debugging componentbaseconfig.DebuggingConfiguration 64 componentbaseconfig.DebuggingConfiguration 65 66 // PercentageOfNodesToScore is the percentage of all nodes that once found feasible 67 // for running a pod, the scheduler stops its search for more feasible nodes in 68 // the cluster. This helps improve scheduler's performance. Scheduler always tries to find 69 // at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. 70 // Example: if the cluster size is 500 nodes and the value of this flag is 30, 71 // then scheduler stops finding further feasible nodes once it finds 150 feasible ones. 72 // When the value is 0, default percentage (5%--50% based on the size of the cluster) of the 73 // nodes will be scored. It is overridden by profile level PercentageOfNodesToScore. 74 PercentageOfNodesToScore *int32 75 76 // PodInitialBackoffSeconds is the initial backoff for unschedulable pods. 77 // If specified, it must be greater than 0. If this value is null, the default value (1s) 78 // will be used. 79 PodInitialBackoffSeconds int64 80 81 // PodMaxBackoffSeconds is the max backoff for unschedulable pods. 82 // If specified, it must be greater than or equal to podInitialBackoffSeconds. If this value is null, 83 // the default value (10s) will be used. 84 PodMaxBackoffSeconds int64 85 86 // Profiles are scheduling profiles that kube-scheduler supports. Pods can 87 // choose to be scheduled under a particular profile by setting its associated 88 // scheduler name. Pods that don't specify any scheduler name are scheduled 89 // with the "default-scheduler" profile, if present here. 90 Profiles []KubeSchedulerProfile 91 92 // Extenders are the list of scheduler extenders, each holding the values of how to communicate 93 // with the extender. These extenders are shared by all scheduler profiles. 94 Extenders []Extender 95 96 // DelayCacheUntilActive specifies when to start caching. If this is true and leader election is enabled, 97 // the scheduler will wait to fill informer caches until it is the leader. Doing so will have slower 98 // failover with the benefit of lower memory overhead while waiting to become leader. 99 // Defaults to false. 100 DelayCacheUntilActive bool 101 } 102 103 // KubeSchedulerProfile is a scheduling profile. 104 type KubeSchedulerProfile struct { 105 // SchedulerName is the name of the scheduler associated to this profile. 106 // If SchedulerName matches with the pod's "spec.schedulerName", then the pod 107 // is scheduled with this profile. 108 SchedulerName string 109 110 // PercentageOfNodesToScore is the percentage of all nodes that once found feasible 111 // for running a pod, the scheduler stops its search for more feasible nodes in 112 // the cluster. This helps improve scheduler's performance. Scheduler always tries to find 113 // at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. 114 // Example: if the cluster size is 500 nodes and the value of this flag is 30, 115 // then scheduler stops finding further feasible nodes once it finds 150 feasible ones. 116 // When the value is 0, default percentage (5%--50% based on the size of the cluster) of the 117 // nodes will be scored. It will override global PercentageOfNodesToScore. If it is empty, 118 // global PercentageOfNodesToScore will be used. 119 PercentageOfNodesToScore *int32 120 121 // Plugins specify the set of plugins that should be enabled or disabled. 122 // Enabled plugins are the ones that should be enabled in addition to the 123 // default plugins. Disabled plugins are any of the default plugins that 124 // should be disabled. 125 // When no enabled or disabled plugin is specified for an extension point, 126 // default plugins for that extension point will be used if there is any. 127 // If a QueueSort plugin is specified, the same QueueSort Plugin and 128 // PluginConfig must be specified for all profiles. 129 Plugins *Plugins 130 131 // PluginConfig is an optional set of custom plugin arguments for each plugin. 132 // Omitting config args for a plugin is equivalent to using the default config 133 // for that plugin. 134 PluginConfig []PluginConfig 135 } 136 137 // Plugins include multiple extension points. When specified, the list of plugins for 138 // a particular extension point are the only ones enabled. If an extension point is 139 // omitted from the config, then the default set of plugins is used for that extension point. 140 // Enabled plugins are called in the order specified here, after default plugins. If they need to 141 // be invoked before default plugins, default plugins must be disabled and re-enabled here in desired order. 142 type Plugins struct { 143 // PreEnqueue is a list of plugins that should be invoked before adding pods to the scheduling queue. 144 PreEnqueue PluginSet 145 146 // QueueSort is a list of plugins that should be invoked when sorting pods in the scheduling queue. 147 QueueSort PluginSet 148 149 // PreFilter is a list of plugins that should be invoked at "PreFilter" extension point of the scheduling framework. 150 PreFilter PluginSet 151 152 // Filter is a list of plugins that should be invoked when filtering out nodes that cannot run the Pod. 153 Filter PluginSet 154 155 // PostFilter is a list of plugins that are invoked after filtering phase, but only when no feasible nodes were found for the pod. 156 PostFilter PluginSet 157 158 // PreScore is a list of plugins that are invoked before scoring. 159 PreScore PluginSet 160 161 // Score is a list of plugins that should be invoked when ranking nodes that have passed the filtering phase. 162 Score PluginSet 163 164 // Reserve is a list of plugins invoked when reserving/unreserving resources 165 // after a node is assigned to run the pod. 166 Reserve PluginSet 167 168 // Permit is a list of plugins that control binding of a Pod. These plugins can prevent or delay binding of a Pod. 169 Permit PluginSet 170 171 // PreBind is a list of plugins that should be invoked before a pod is bound. 172 PreBind PluginSet 173 174 // Bind is a list of plugins that should be invoked at "Bind" extension point of the scheduling framework. 175 // The scheduler call these plugins in order. Scheduler skips the rest of these plugins as soon as one returns success. 176 Bind PluginSet 177 178 // PostBind is a list of plugins that should be invoked after a pod is successfully bound. 179 PostBind PluginSet 180 181 // MultiPoint is a simplified config field for enabling plugins for all valid extension points 182 MultiPoint PluginSet 183 } 184 185 // PluginSet specifies enabled and disabled plugins for an extension point. 186 // If an array is empty, missing, or nil, default plugins at that extension point will be used. 187 type PluginSet struct { 188 // Enabled specifies plugins that should be enabled in addition to default plugins. 189 // These are called after default plugins and in the same order specified here. 190 Enabled []Plugin 191 // Disabled specifies default plugins that should be disabled. 192 // When all default plugins need to be disabled, an array containing only one "*" should be provided. 193 Disabled []Plugin 194 } 195 196 // Plugin specifies a plugin name and its weight when applicable. Weight is used only for Score plugins. 197 type Plugin struct { 198 // Name defines the name of plugin 199 Name string 200 // Weight defines the weight of plugin, only used for Score plugins. 201 Weight int32 202 } 203 204 // PluginConfig specifies arguments that should be passed to a plugin at the time of initialization. 205 // A plugin that is invoked at multiple extension points is initialized once. Args can have arbitrary structure. 206 // It is up to the plugin to process these Args. 207 type PluginConfig struct { 208 // Name defines the name of plugin being configured 209 Name string 210 // Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure. 211 Args runtime.Object 212 } 213 214 /* 215 * NOTE: The following variables and methods are intentionally left out of the staging mirror. 216 */ 217 const ( 218 // DefaultPercentageOfNodesToScore defines the percentage of nodes of all nodes 219 // that once found feasible, the scheduler stops looking for more nodes. 220 // A value of 0 means adaptive, meaning the scheduler figures out a proper default. 221 DefaultPercentageOfNodesToScore = 0 222 223 // MaxCustomPriorityScore is the max score UtilizationShapePoint expects. 224 MaxCustomPriorityScore int64 = 10 225 226 // MaxTotalScore is the maximum total score. 227 MaxTotalScore int64 = math.MaxInt64 228 229 // MaxWeight defines the max weight value allowed for custom PriorityPolicy 230 MaxWeight = MaxTotalScore / MaxCustomPriorityScore 231 ) 232 233 // Names returns the list of enabled plugin names. 234 func (p *Plugins) Names() []string { 235 if p == nil { 236 return nil 237 } 238 extensions := []PluginSet{ 239 p.PreEnqueue, 240 p.PreFilter, 241 p.Filter, 242 p.PostFilter, 243 p.Reserve, 244 p.PreScore, 245 p.Score, 246 p.PreBind, 247 p.Bind, 248 p.PostBind, 249 p.Permit, 250 p.QueueSort, 251 } 252 n := sets.New[string]() 253 for _, e := range extensions { 254 for _, pg := range e.Enabled { 255 n.Insert(pg.Name) 256 } 257 } 258 return sets.List(n) 259 } 260 261 // Extender holds the parameters used to communicate with the extender. If a verb is unspecified/empty, 262 // it is assumed that the extender chose not to provide that extension. 263 type Extender struct { 264 // URLPrefix at which the extender is available 265 URLPrefix string 266 // Verb for the filter call, empty if not supported. This verb is appended to the URLPrefix when issuing the filter call to extender. 267 FilterVerb string 268 // Verb for the preempt call, empty if not supported. This verb is appended to the URLPrefix when issuing the preempt call to extender. 269 PreemptVerb string 270 // Verb for the prioritize call, empty if not supported. This verb is appended to the URLPrefix when issuing the prioritize call to extender. 271 PrioritizeVerb string 272 // The numeric multiplier for the node scores that the prioritize call generates. 273 // The weight should be a positive integer 274 Weight int64 275 // Verb for the bind call, empty if not supported. This verb is appended to the URLPrefix when issuing the bind call to extender. 276 // If this method is implemented by the extender, it is the extender's responsibility to bind the pod to apiserver. Only one extender 277 // can implement this function. 278 BindVerb string 279 // EnableHTTPS specifies whether https should be used to communicate with the extender 280 EnableHTTPS bool 281 // TLSConfig specifies the transport layer security config 282 TLSConfig *ExtenderTLSConfig 283 // HTTPTimeout specifies the timeout duration for a call to the extender. Filter timeout fails the scheduling of the pod. Prioritize 284 // timeout is ignored, k8s/other extenders priorities are used to select the node. 285 HTTPTimeout metav1.Duration 286 // NodeCacheCapable specifies that the extender is capable of caching node information, 287 // so the scheduler should only send minimal information about the eligible nodes 288 // assuming that the extender already cached full details of all nodes in the cluster 289 NodeCacheCapable bool 290 // ManagedResources is a list of extended resources that are managed by 291 // this extender. 292 // - A pod will be sent to the extender on the Filter, Prioritize and Bind 293 // (if the extender is the binder) phases iff the pod requests at least 294 // one of the extended resources in this list. If empty or unspecified, 295 // all pods will be sent to this extender. 296 // - If IgnoredByScheduler is set to true for a resource, kube-scheduler 297 // will skip checking the resource in predicates. 298 // +optional 299 ManagedResources []ExtenderManagedResource 300 // Ignorable specifies if the extender is ignorable, i.e. scheduling should not 301 // fail when the extender returns an error or is not reachable. 302 Ignorable bool 303 } 304 305 // ExtenderManagedResource describes the arguments of extended resources 306 // managed by an extender. 307 type ExtenderManagedResource struct { 308 // Name is the extended resource name. 309 Name string 310 // IgnoredByScheduler indicates whether kube-scheduler should ignore this 311 // resource when applying predicates. 312 IgnoredByScheduler bool 313 } 314 315 // ExtenderTLSConfig contains settings to enable TLS with extender 316 type ExtenderTLSConfig struct { 317 // Server should be accessed without verifying the TLS certificate. For testing only. 318 Insecure bool 319 // ServerName is passed to the server for SNI and is used in the client to check server 320 // certificates against. If ServerName is empty, the hostname used to contact the 321 // server is used. 322 ServerName string 323 324 // Server requires TLS client certificate authentication 325 CertFile string 326 // Server requires TLS client certificate authentication 327 KeyFile string 328 // Trusted root certificates for server 329 CAFile string 330 331 // CertData holds PEM-encoded bytes (typically read from a client certificate file). 332 // CertData takes precedence over CertFile 333 CertData []byte 334 // KeyData holds PEM-encoded bytes (typically read from a client certificate key file). 335 // KeyData takes precedence over KeyFile 336 KeyData []byte `datapolicy:"security-key"` 337 // CAData holds PEM-encoded bytes (typically read from a root certificates bundle). 338 // CAData takes precedence over CAFile 339 CAData []byte 340 }