feat: make loadConfig and loadConfigFile public functions

- so that users who import kube-scheduler libraries can use these functions to read kube scheduler config
This commit is contained in:
vadasambar
2023-07-04 10:32:14 +05:30
parent 406d2dfe61
commit 8e284389a5
2 changed files with 4 additions and 4 deletions

View File

@@ -30,16 +30,16 @@ import (
configv1beta3 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1beta3"
)
func loadConfigFromFile(logger klog.Logger, file string) (*config.KubeSchedulerConfiguration, error) {
func LoadConfigFromFile(logger klog.Logger, file string) (*config.KubeSchedulerConfiguration, error) {
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}
return loadConfig(logger, data)
return LoadConfig(logger, data)
}
func loadConfig(logger klog.Logger, data []byte) (*config.KubeSchedulerConfiguration, error) {
func LoadConfig(logger klog.Logger, data []byte) (*config.KubeSchedulerConfiguration, error) {
// The UniversalDecoder runs defaulting and returns the internal type by default.
obj, gvk, err := scheme.Codecs.UniversalDecoder().Decode(data, nil, nil)
if err != nil {

View File

@@ -204,7 +204,7 @@ func (o *Options) ApplyTo(logger klog.Logger, c *schedulerappconfig.Config) erro
o.ApplyLeaderElectionTo(o.ComponentConfig)
c.ComponentConfig = *o.ComponentConfig
} else {
cfg, err := loadConfigFromFile(logger, o.ConfigFile)
cfg, err := LoadConfigFromFile(logger, o.ConfigFile)
if err != nil {
return err
}