mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Log defaulted kube-scheduler component config at startup
This commit is contained in:
parent
d6ef6d6e43
commit
14fa76d92f
@ -19,6 +19,7 @@ package options
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"k8s.io/klog/v2"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -48,8 +49,13 @@ func loadConfig(data []byte) (*kubeschedulerconfig.KubeSchedulerConfiguration, e
|
|||||||
return nil, fmt.Errorf("couldn't decode as KubeSchedulerConfiguration, got %s: ", gvk)
|
return nil, fmt.Errorf("couldn't decode as KubeSchedulerConfiguration, got %s: ", gvk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteConfigFile writes the config into the given file name as YAML.
|
// LogOrWriteConfig logs the completed component config and writes it into the given file name as YAML, if either is enabled
|
||||||
func WriteConfigFile(fileName string, cfg *kubeschedulerconfig.KubeSchedulerConfiguration) error {
|
func LogOrWriteConfig(fileName string, cfg *kubeschedulerconfig.KubeSchedulerConfiguration, completedProfiles []kubeschedulerconfig.KubeSchedulerProfile) error {
|
||||||
|
if !(klog.V(2).Enabled() || len(fileName) > 0) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cfg.Profiles = completedProfiles
|
||||||
|
|
||||||
const mediaType = runtime.ContentTypeYAML
|
const mediaType = runtime.ContentTypeYAML
|
||||||
info, ok := runtime.SerializerInfoForMediaType(kubeschedulerscheme.Codecs.SupportedMediaTypes(), mediaType)
|
info, ok := runtime.SerializerInfoForMediaType(kubeschedulerscheme.Codecs.SupportedMediaTypes(), mediaType)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -57,15 +63,26 @@ func WriteConfigFile(fileName string, cfg *kubeschedulerconfig.KubeSchedulerConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
encoder := kubeschedulerscheme.Codecs.EncoderForVersion(info.Serializer, kubeschedulerconfigv1beta1.SchemeGroupVersion)
|
encoder := kubeschedulerscheme.Codecs.EncoderForVersion(info.Serializer, kubeschedulerconfigv1beta1.SchemeGroupVersion)
|
||||||
|
if klog.V(2).Enabled() {
|
||||||
configFile, err := os.Create(fileName)
|
bytes, err := runtime.Encode(encoder, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer configFile.Close()
|
configString := string(bytes)
|
||||||
if err := encoder.Encode(cfg, configFile); err != nil {
|
klog.Infof("Using component config:\n%+v\n", configString)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(fileName) > 0 {
|
||||||
|
configFile, err := os.Create(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer configFile.Close()
|
||||||
|
if err := encoder.Encode(cfg, configFile); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
klog.Infof("Wrote configuration to: %s\n", fileName)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -128,14 +128,6 @@ func runCommand(cmd *cobra.Command, opts *options.Options, registryOptions ...Op
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.WriteConfigTo) > 0 {
|
|
||||||
if err := options.WriteConfigFile(opts.WriteConfigTo, &cc.ComponentConfig); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
klog.Infof("Wrote configuration to: %s\n", opts.WriteConfigTo)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return Run(ctx, cc, sched)
|
return Run(ctx, cc, sched)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,6 +302,7 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
|
|||||||
}
|
}
|
||||||
|
|
||||||
recorderFactory := getRecorderFactory(&cc)
|
recorderFactory := getRecorderFactory(&cc)
|
||||||
|
completedProfiles := make([]kubeschedulerconfig.KubeSchedulerProfile, 0)
|
||||||
// Create the scheduler.
|
// Create the scheduler.
|
||||||
sched, err := scheduler.New(cc.Client,
|
sched, err := scheduler.New(cc.Client,
|
||||||
cc.InformerFactory,
|
cc.InformerFactory,
|
||||||
@ -323,10 +316,17 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
|
|||||||
scheduler.WithPodInitialBackoffSeconds(cc.ComponentConfig.PodInitialBackoffSeconds),
|
scheduler.WithPodInitialBackoffSeconds(cc.ComponentConfig.PodInitialBackoffSeconds),
|
||||||
scheduler.WithExtenders(cc.ComponentConfig.Extenders...),
|
scheduler.WithExtenders(cc.ComponentConfig.Extenders...),
|
||||||
scheduler.WithParallelism(cc.ComponentConfig.Parallelism),
|
scheduler.WithParallelism(cc.ComponentConfig.Parallelism),
|
||||||
|
scheduler.WithBuildFrameworkCapturer(func(profile kubeschedulerconfig.KubeSchedulerProfile) {
|
||||||
|
// Profiles are processed during Framework instantiation to set default plugins and configurations. Capturing them for logging
|
||||||
|
completedProfiles = append(completedProfiles, profile)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
if err := options.LogOrWriteConfig(opts.WriteConfigTo, &cc.ComponentConfig, completedProfiles); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &cc, sched, nil
|
return &cc, sched, nil
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ go_test(
|
|||||||
"//pkg/scheduler/framework:go_default_library",
|
"//pkg/scheduler/framework:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins:go_default_library",
|
"//pkg/scheduler/framework/plugins:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins/defaultbinder:go_default_library",
|
"//pkg/scheduler/framework/plugins/defaultbinder:go_default_library",
|
||||||
|
"//pkg/scheduler/framework/plugins/defaultpreemption:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
|
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
|
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins/nodelabel:go_default_library",
|
"//pkg/scheduler/framework/plugins/nodelabel:go_default_library",
|
||||||
|
@ -38,6 +38,7 @@ import (
|
|||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||||
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel"
|
||||||
@ -107,6 +108,13 @@ func TestCreateFromConfig(t *testing.T) {
|
|||||||
"apiVersion" : "v1"
|
"apiVersion" : "v1"
|
||||||
}`),
|
}`),
|
||||||
wantPluginConfig: []schedulerapi.PluginConfig{
|
wantPluginConfig: []schedulerapi.PluginConfig{
|
||||||
|
{
|
||||||
|
Name: defaultpreemption.Name,
|
||||||
|
Args: &schedulerapi.DefaultPreemptionArgs{
|
||||||
|
MinCandidateNodesPercentage: 10,
|
||||||
|
MinCandidateNodesAbsolute: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: interpodaffinity.Name,
|
Name: interpodaffinity.Name,
|
||||||
Args: &schedulerapi.InterPodAffinityArgs{
|
Args: &schedulerapi.InterPodAffinityArgs{
|
||||||
@ -231,6 +239,13 @@ func TestCreateFromConfig(t *testing.T) {
|
|||||||
]
|
]
|
||||||
}`),
|
}`),
|
||||||
wantPluginConfig: []schedulerapi.PluginConfig{
|
wantPluginConfig: []schedulerapi.PluginConfig{
|
||||||
|
{
|
||||||
|
Name: defaultpreemption.Name,
|
||||||
|
Args: &schedulerapi.DefaultPreemptionArgs{
|
||||||
|
MinCandidateNodesPercentage: 10,
|
||||||
|
MinCandidateNodesAbsolute: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: interpodaffinity.Name,
|
Name: interpodaffinity.Name,
|
||||||
Args: &schedulerapi.InterPodAffinityArgs{
|
Args: &schedulerapi.InterPodAffinityArgs{
|
||||||
@ -312,6 +327,13 @@ func TestCreateFromConfig(t *testing.T) {
|
|||||||
"hardPodAffinitySymmetricWeight" : 10
|
"hardPodAffinitySymmetricWeight" : 10
|
||||||
}`),
|
}`),
|
||||||
wantPluginConfig: []schedulerapi.PluginConfig{
|
wantPluginConfig: []schedulerapi.PluginConfig{
|
||||||
|
{
|
||||||
|
Name: defaultpreemption.Name,
|
||||||
|
Args: &schedulerapi.DefaultPreemptionArgs{
|
||||||
|
MinCandidateNodesPercentage: 10,
|
||||||
|
MinCandidateNodesAbsolute: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: interpodaffinity.Name,
|
Name: interpodaffinity.Name,
|
||||||
Args: &schedulerapi.InterPodAffinityArgs{
|
Args: &schedulerapi.InterPodAffinityArgs{
|
||||||
|
Loading…
Reference in New Issue
Block a user