mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 19:23:40 +00:00
Merge pull request #115754 from linxiulei/sched
Start informers after leader election
This commit is contained in:
commit
ffb4172ff1
@ -399,6 +399,7 @@ profiles:
|
||||
APIVersion: v1.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -470,6 +471,7 @@ profiles:
|
||||
APIVersion: v1beta3.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -572,6 +574,7 @@ profiles:
|
||||
APIVersion: v1.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -642,6 +645,7 @@ profiles:
|
||||
APIVersion: v1.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -686,6 +690,7 @@ profiles:
|
||||
APIVersion: v1.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -805,6 +810,7 @@ profiles:
|
||||
APIVersion: v1beta3.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -927,6 +933,7 @@ profiles:
|
||||
APIVersion: v1.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -1041,6 +1048,7 @@ profiles:
|
||||
APIVersion: v1beta3.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
@ -1180,6 +1188,7 @@ profiles:
|
||||
APIVersion: v1.SchemeGroupVersion.String(),
|
||||
},
|
||||
Parallelism: 16,
|
||||
DelayCacheUntilActive: false,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
|
@ -194,6 +194,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
||||
}
|
||||
}
|
||||
|
||||
startInformersAndWaitForSync := func(ctx context.Context) {
|
||||
// Start all informers.
|
||||
cc.InformerFactory.Start(ctx.Done())
|
||||
// DynInformerFactory can be nil in tests.
|
||||
@ -207,12 +208,21 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
||||
if cc.DynInformerFactory != nil {
|
||||
cc.DynInformerFactory.WaitForCacheSync(ctx.Done())
|
||||
}
|
||||
}
|
||||
if !cc.ComponentConfig.DelayCacheUntilActive || cc.LeaderElection == nil {
|
||||
startInformersAndWaitForSync(ctx)
|
||||
}
|
||||
|
||||
// If leader election is enabled, runCommand via LeaderElector until done and exit.
|
||||
if cc.LeaderElection != nil {
|
||||
cc.LeaderElection.Callbacks = leaderelection.LeaderCallbacks{
|
||||
OnStartedLeading: func(ctx context.Context) {
|
||||
close(waitingForLeader)
|
||||
if cc.ComponentConfig.DelayCacheUntilActive {
|
||||
logger.Info("Starting informers and waiting for sync...")
|
||||
startInformersAndWaitForSync(ctx)
|
||||
logger.Info("Sync completed")
|
||||
}
|
||||
sched.Run(ctx)
|
||||
},
|
||||
OnStoppedLeading: func() {
|
||||
|
7
pkg/generated/openapi/zz_generated.openapi.go
generated
7
pkg/generated/openapi/zz_generated.openapi.go
generated
@ -54521,6 +54521,13 @@ func schema_k8sio_kube_scheduler_config_v1_KubeSchedulerConfiguration(ref common
|
||||
},
|
||||
},
|
||||
},
|
||||
"delayCacheUntilActive": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "DelayCacheUntilActive specifies when to start caching. If this is true and leader election is enabled, the scheduler will wait to fill informer caches until it is the leader. Doing so will have slower failover with the benefit of lower memory overhead while waiting to become leader. Defaults to false.",
|
||||
Type: []string{"boolean"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
Required: []string{"leaderElection", "clientConnection"},
|
||||
},
|
||||
|
@ -1000,6 +1000,7 @@ profiles:
|
||||
version: v1beta3.SchemeGroupVersion,
|
||||
obj: &config.KubeSchedulerConfiguration{
|
||||
Parallelism: 8,
|
||||
DelayCacheUntilActive: true,
|
||||
Profiles: []config.KubeSchedulerProfile{
|
||||
{
|
||||
PluginConfig: []config.PluginConfig{
|
||||
@ -1220,6 +1221,7 @@ profiles:
|
||||
version: v1.SchemeGroupVersion,
|
||||
obj: &config.KubeSchedulerConfiguration{
|
||||
Parallelism: 8,
|
||||
DelayCacheUntilActive: true,
|
||||
Profiles: []config.KubeSchedulerProfile{
|
||||
{
|
||||
PluginConfig: []config.PluginConfig{
|
||||
@ -1265,6 +1267,7 @@ clientConnection:
|
||||
contentType: ""
|
||||
kubeconfig: ""
|
||||
qps: 0
|
||||
delayCacheUntilActive: true
|
||||
enableContentionProfiling: false
|
||||
enableProfiling: false
|
||||
kind: KubeSchedulerConfiguration
|
||||
@ -1316,6 +1319,7 @@ profiles:
|
||||
version: v1.SchemeGroupVersion,
|
||||
obj: &config.KubeSchedulerConfiguration{
|
||||
Parallelism: 8,
|
||||
DelayCacheUntilActive: true,
|
||||
Profiles: []config.KubeSchedulerProfile{
|
||||
{
|
||||
PluginConfig: []config.PluginConfig{
|
||||
@ -1337,6 +1341,7 @@ clientConnection:
|
||||
contentType: ""
|
||||
kubeconfig: ""
|
||||
qps: 0
|
||||
delayCacheUntilActive: true
|
||||
enableContentionProfiling: false
|
||||
enableProfiling: false
|
||||
kind: KubeSchedulerConfiguration
|
||||
|
@ -96,6 +96,12 @@ type KubeSchedulerConfiguration struct {
|
||||
// Extenders are the list of scheduler extenders, each holding the values of how to communicate
|
||||
// with the extender. These extenders are shared by all scheduler profiles.
|
||||
Extenders []Extender
|
||||
|
||||
// DelayCacheUntilActive specifies when to start caching. If this is true and leader election is enabled,
|
||||
// the scheduler will wait to fill informer caches until it is the leader. Doing so will have slower
|
||||
// failover with the benefit of lower memory overhead while waiting to become leader.
|
||||
// Defaults to false.
|
||||
DelayCacheUntilActive bool
|
||||
}
|
||||
|
||||
// KubeSchedulerProfile is a scheduling profile.
|
||||
|
@ -439,6 +439,44 @@ func TestSchedulerDefaults(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set non default delayCacheUntilActive",
|
||||
config: &configv1.KubeSchedulerConfiguration{
|
||||
DelayCacheUntilActive: true,
|
||||
},
|
||||
expected: &configv1.KubeSchedulerConfiguration{
|
||||
Parallelism: pointer.Int32(16),
|
||||
DelayCacheUntilActive: true,
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: &enable,
|
||||
EnableContentionProfiling: &enable,
|
||||
},
|
||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||
LeaderElect: pointer.Bool(true),
|
||||
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
||||
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
||||
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||
ResourceLock: "leases",
|
||||
ResourceNamespace: "kube-system",
|
||||
ResourceName: "kube-scheduler",
|
||||
},
|
||||
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
|
||||
QPS: 50,
|
||||
Burst: 100,
|
||||
ContentType: "application/vnd.kubernetes.protobuf",
|
||||
},
|
||||
PercentageOfNodesToScore: pointer.Int32(config.DefaultPercentageOfNodesToScore),
|
||||
PodInitialBackoffSeconds: pointer.Int64(1),
|
||||
PodMaxBackoffSeconds: pointer.Int64(10),
|
||||
Profiles: []configv1.KubeSchedulerProfile{
|
||||
{
|
||||
Plugins: getDefaultPlugins(),
|
||||
PluginConfig: pluginConfigs,
|
||||
SchedulerName: pointer.String("default-scheduler"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "set non default global percentageOfNodesToScore",
|
||||
config: &configv1.KubeSchedulerConfiguration{
|
||||
|
@ -429,6 +429,7 @@ func autoConvert_v1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigurat
|
||||
out.Profiles = nil
|
||||
}
|
||||
out.Extenders = *(*[]config.Extender)(unsafe.Pointer(&in.Extenders))
|
||||
out.DelayCacheUntilActive = in.DelayCacheUntilActive
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -466,6 +467,7 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1_KubeSchedulerConfigurat
|
||||
out.Profiles = nil
|
||||
}
|
||||
out.Extenders = *(*[]v1.Extender)(unsafe.Pointer(&in.Extenders))
|
||||
out.DelayCacheUntilActive = in.DelayCacheUntilActive
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -466,6 +466,7 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1beta3_KubeSchedulerConfi
|
||||
out.Profiles = nil
|
||||
}
|
||||
out.Extenders = *(*[]v1beta3.Extender)(unsafe.Pointer(&in.Extenders))
|
||||
// WARNING: in.DelayCacheUntilActive requires manual conversion: does not exist in peer-type
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,12 @@ type KubeSchedulerConfiguration struct {
|
||||
// with the extender. These extenders are shared by all scheduler profiles.
|
||||
// +listType=set
|
||||
Extenders []Extender `json:"extenders,omitempty"`
|
||||
|
||||
// DelayCacheUntilActive specifies when to start caching. If this is true and leader election is enabled,
|
||||
// the scheduler will wait to fill informer caches until it is the leader. Doing so will have slower
|
||||
// failover with the benefit of lower memory overhead while waiting to become leader.
|
||||
// Defaults to false.
|
||||
DelayCacheUntilActive bool `json:"delayCacheUntilActive,omitempty"`
|
||||
}
|
||||
|
||||
// DecodeNestedObjects decodes plugin args for known types.
|
||||
|
Loading…
Reference in New Issue
Block a user