Get the App
SLTechnology News&Howtos  ›  Servers  › 

Parse how the default configuration of kube-scheduler is done from the source code level

Shulou Source: shulou.com Published: 2022-05-31 21:49:03 09月19日 Update

This article will explain in detail how to analyze the default configuration of kube-scheduler from the source code level. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

From the beginning, in kube-scheduler 's main function, s: = options.NewSchedulerServer () creates the SchedulerServer according to the default parameters.

-plugin/cmd/kube-scheduler/scheduler.go:30-func main () {s: = options.NewSchedulerServer () s.AddFlags (pflag.CommandLine) flag.InitFlags () logs.InitLogs () defer logs.FlushLogs () verflag.PrintAndExitIfRequested () if err: = app.Run (s) Err! = nil {glog.Fatalf ("scheduler app failed to run:% v", err)}}-plugin/cmd/kube-scheduler/app/options/options.go:44-/ NewSchedulerServer creates a new SchedulerServer with default parametersfunc NewSchedulerServer () * SchedulerServer {versioned: = & v1alpha1.KubeSchedulerConfiguration {} api.Scheme.Default (versioned) cfg: = componentconfig.KubeSchedulerConfiguration {} api.Scheme.Convert (versioned, & cfg) Nil) cfg.LeaderElection.LeaderElect = true s: = SchedulerServer {KubeSchedulerConfiguration: cfg,} return & s}

The api.Scheme.Default (versioned) in NewSchedulerServer above is the operation to set the default parameters. Look at Default (...) Code of:

-pkg/runtime/scheme.go:439-- / Default sets defaults on the provided Object.func (s * Scheme) Default (src Object) {if fn, ok: = s.defaulterFunctions [reflect.TypeOf (src)]; ok {fn (src)}}

The original Default (...) All you have to do is get the defaultFunc fn corresponding to the type & v1alpha1.KubeSchedulerConfiguration {} from the Scheme.defaulterFuncs Map and execute fn (& v1alpha1.KubeSchedulerConfiguration {}) to complete the configuration of the default parameters.

OK, so here's the problem. How did the defaultFunc corresponding to these type be register into the Map of Scheme.defaulterFuncs?

The answer lies in the global variable SchemeBuilder defined in pkg/apis/componentconfig/v1alpha1/register.go. SchemeBuilder = runtime.NewSchemeBuilder (addKnownTypes, addDefaultingFuncs) calls the addDefaultFuncs function when the SchemeBuilder is created. The work of registering defaultFunc should be done in the addDefaultingFuncs method.

Look at the implementation of addDefaultingFuncs, sure enough. SetDefaults_KubeSchedulerConfiguration is the defaultFuncs of & v1alpha1.KubeSchedulerConfiguration {}.

-pkg/apis/componentconfig/v1alpha1/register.go-var (SchemeBuilder = runtime.NewSchemeBuilder (addKnownTypes, addDefaultingFuncs) AddToScheme = SchemeBuilder.AddToScheme)-pkg/apis/componentconfig/v1alpha1/defaults.go-func addDefaultingFuncs (scheme * kruntime.Scheme) error {RegisterDefaults (scheme) return scheme.AddDefaultingFuncs (SetDefaults_KubeProxyConfiguration, SetDefaults_KubeSchedulerConfiguration, SetDefaults_LeaderElectionConfiguration) SetDefaults_KubeletConfiguration )} func SetDefaults_KubeSchedulerConfiguration (obj * KubeSchedulerConfiguration) {if obj.Port = = 0 {obj.Port = ports.SchedulerPort} if obj.Address = "" {obj.Address = "0.0.0.0"} if obj.AlgorithmProvider = = "" {obj.AlgorithmProvider = "DefaultProvider"} If obj.ContentType = "" {obj.ContentType = "application/vnd.kubernetes.protobuf"} if obj.KubeAPIQPS = = 0 {obj.KubeAPIQPS = 50.0} if obj.KubeAPIBurst = 0 {obj.KubeAPIBurst = 100} if obj.SchedulerName = "" { Obj.SchedulerName = api.DefaultSchedulerName} if obj.HardPodAffinitySymmetricWeight = = 0 {obj.HardPodAffinitySymmetricWeight = api.DefaultHardPodAffinitySymmetricWeight} if obj.FailureDomains = "" {obj.FailureDomains = api.DefaultFailureDomains}}

Combined with the AddFlags defined by plugin/cmd/kube-scheduler/app/options/options.go:57, the default configuration of kube-scheduler is as follows:

Port = 10251

Address = "0.0.0.0"

Algorithm-provider = "DefaultProvider"

Content-type = "application/vnd.kubernetes.protobuf"

Kube-api-qps = 50

Kube-api-burst = 100

Scheduler-name = "default-scheduler"

Hard-pod-affinity-symmetric-weight = 1

Failure-domains = "kubernetes.io/hostname,failure-domain.beta.kubernetes.io/zone,failure-domain.beta.kubernetes.io/region"

On "from the source level to analyze how the default configuration of kube-scheduler is done" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Configuration parameters that is articles layers source code functions more work good practical sure enough from scratch code global content variables articles methods knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Apple vpn MariaDB