关于Kubernetes调度器插件

huangapple go评论119阅读模式
英文:

Regarding the Kubernetes scheduler plugin

问题

我想知道如何确定已注册的插件有哪些。

英文:

The version of Kubernetes in use is v1.26.3.

I have cloned the Kubernetes source code to peruse the scheduler logic.

Upon inspection of the framework.go file, I have observed the existence of a frameworkImpl struct. I am curious as to how I can ascertain which plugins have been registered.

  1. I am curious as to how I can ascertain which plugins have been registered
  2. // NewFramework initializes plugins given the configuration and the registry.
  3. func NewFramework(r Registry, profile *config.KubeSchedulerProfile, stopCh <-chan struct{}, opts ...Option) (framework.Framework, error) {
  4. options := defaultFrameworkOptions(stopCh)
  5. for _, opt := range opts {
  6. opt(&options)
  7. }
  8. f := &frameworkImpl{
  9. registry: r,
  10. snapshotSharedLister: options.snapshotSharedLister,
  11. scorePluginWeight: make(map[string]int),
  12. waitingPods: newWaitingPodsMap(),
  13. clientSet: options.clientSet,
  14. kubeConfig: options.kubeConfig,
  15. eventRecorder: options.eventRecorder,
  16. informerFactory: options.informerFactory,
  17. metricsRecorder: options.metricsRecorder,
  18. extenders: options.extenders,
  19. PodNominator: options.podNominator,
  20. parallelizer: options.parallelizer,
  21. }
  22. if profile == nil {
  23. return f, nil
  24. }
  25. f.profileName = profile.SchedulerName
  26. f.percentageOfNodesToScore = profile.PercentageOfNodesToScore
  27. if profile.Plugins == nil {
  28. return f, nil
  29. }
  30. // get needed plugins from config
  31. pg := f.pluginsNeeded(profile.Plugins)
  32. pluginConfig := make(map[string]runtime.Object, len(profile.PluginConfig))
  33. for i := range profile.PluginConfig {
  34. name := profile.PluginConfig[i].Name
  35. if _, ok := pluginConfig[name]; ok {
  36. return nil, fmt.Errorf("repeated config for plugin %s", name)
  37. }
  38. pluginConfig[name] = profile.PluginConfig[i].Args
  39. }
  40. outputProfile := config.KubeSchedulerProfile{
  41. SchedulerName: f.profileName,
  42. PercentageOfNodesToScore: f.percentageOfNodesToScore,
  43. Plugins: profile.Plugins,
  44. PluginConfig: make([]config.PluginConfig, 0, len(pg)),
  45. }
  46. pluginsMap := make(map[string]framework.Plugin)
  47. for name, factory := range r {
  48. // initialize only needed plugins.
  49. if !pg.Has(name) {
  50. continue
  51. }
  52. args := pluginConfig[name]
  53. if args != nil {
  54. outputProfile.PluginConfig = append(outputProfile.PluginConfig, config.PluginConfig{
  55. Name: name,
  56. Args: args,
  57. })
  58. }
  59. p, err := factory(args, f)
  60. if err != nil {
  61. return nil, fmt.Errorf("initializing plugin %q: %w", name, err)
  62. }
  63. pluginsMap[name] = p
  64. // Update ClusterEventMap in place.
  65. fillEventToPluginMap(p, options.clusterEventMap)
  66. }
  67. // initialize plugins per individual extension points
  68. for _, e := range f.getExtensionPoints(profile.Plugins) {
  69. if err := updatePluginList(e.slicePtr, *e.plugins, pluginsMap); err != nil {
  70. return nil, err
  71. }
  72. }
  73. // initialize multiPoint plugins to their expanded extension points
  74. if len(profile.Plugins.MultiPoint.Enabled) > 0 {
  75. if err := f.expandMultiPointPlugins(profile, pluginsMap); err != nil {
  76. return nil, err
  77. }
  78. }
  79. if len(f.queueSortPlugins) != 1 {
  80. return nil, fmt.Errorf("only one queue sort plugin required for profile with scheduler name %q, but got %d", profile.SchedulerName, len(f.queueSortPlugins))
  81. }
  82. if len(f.bindPlugins) == 0 {
  83. return nil, fmt.Errorf("at least one bind plugin is needed for profile with scheduler name %q", profile.SchedulerName)
  84. }
  85. if err := getScoreWeights(f, pluginsMap, append(profile.Plugins.Score.Enabled, profile.Plugins.MultiPoint.Enabled...)); err != nil {
  86. return nil, err
  87. }
  88. // Verifying the score weights again since Plugin.Name() could return a different
  89. // value from the one used in the configuration.
  90. for _, scorePlugin := range f.scorePlugins {
  91. if f.scorePluginWeight[scorePlugin.Name()] == 0 {
  92. return nil, fmt.Errorf("score plugin %q is not configured with weight", scorePlugin.Name())
  93. }
  94. }
  95. if options.captureProfile != nil {
  96. if len(outputProfile.PluginConfig) != 0 {
  97. sort.Slice(outputProfile.PluginConfig, func(i, j int) bool {
  98. return outputProfile.PluginConfig[i].Name < outputProfile.PluginConfig[j].Name
  99. })
  100. } else {
  101. outputProfile.PluginConfig = nil
  102. }
  103. options.captureProfile(outputProfile)
  104. }
  105. return f, nil
  106. }

I am curious as to how I can ascertain which plugins have been registered

答案1

得分: 1

实际上,我正在尝试找出默认使用的插件。

我正在使用的Kubernetes版本是1.20.6。

我发现从源代码中获取答案非常困难。

但是你可以通过向kube-scheduler.yaml添加一个参数来导出调度器实例使用的配置:

  • --write-config-to=/path/to/hostpath/config/file

注意事项:

  • --v 应该大于等于2
  • 如果write-config-to成功,调度器将以退出码0退出,因此在导出配置文件后请删除此参数。
英文:

actual, i'm trying to find out what plugins are used by default too.

the kubernetes version i'm using is 1.20.6.

i found pretty hard to get the answer from source code.

but you can export the configuration used by scheduler isntance by adding an arugument to kube-scheduler.yaml:

  • --write-config-to=/path/to/hostpath/config/file

ATTENTIONS:

  • --v should >= 2
  • if write-config-to success, scheduler will exit 0, so remove this argument after you export config file

huangapple
  • 本文由 发表于 2023年4月4日 15:50:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定