Change:
I want to be exported as a public function imports scheduler code and runs scheduler simulations for pods to decide which nodegroup should be scaled up. consider this case: a user is running a scheduler with custom scheduler config the user wants cluster-autoscaler to run scheduler simulations based on the custom scheduler config For ii default scheduler config is used in cluster-autoscaler scheduler simulations. Right now, it is not possible to use custom scheduler config for cluster-autoscaler scheduler simulations but I am working on a PR () to support this feature. For this feature, I need to parse scheduler config. . It would help if we can have exported as (just like ) so that programs which need to parse scheduler config can use the exported function directly instead of writing custom code.
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the label and provide further guidance. The label can be by org members by writing in a comment. <detailsInstructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/sig scheduling
PR:
/assign vadasambar
wdyt?
/sig autoscaling
LGTM, thanks.

Discussion:
configv1beta3 "k8s.io/kubernetes/pkg/scheduler/apis/config/v1beta3" ) <del> func loadConfigFromFile(logger klog.Logger, file string) (*config.KubeSchedulerConfiguration, error) { </del> <ins> // LoadConfigFromFile loads scheduler config from the specified file path func LoadConfigFromFile(logger klog.Logger, file string) (*config.KubeSchedulerConfiguration, error) { </ins> data, err := os.ReadFile(file) if err != nil { return nil, err

<ins> /* Copyright 2023 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package options import ( "context" "fmt" "os" "path/filepath" "testing" "github.com/stretchr/testify/assert" "k8s.io/klog/v2" "k8s.io/kubernetes/pkg/scheduler/apis/config" ) const ( apiVersionMissing = "'apiVersion' is missing" apiVersionTooOld  = "no kind "KubeSchedulerConfiguration" is registered for" + " version "kubescheduler.config.k8s.io/v1alpha1"" fileNotFound = "no such file or directory" // schedulerConfigMinimalCorrect is the minimal // correct scheduler config schedulerConfigMinimalCorrect = ` apiVersion: kubescheduler.config.k8s.io/v1 kind: KubeSchedulerConfiguration` // schedulerConfigDecodeErr is the scheduler config // which throws decoding error when we try to load it schedulerConfigDecodeErr = ` kind: KubeSchedulerConfiguration` // schedulerConfigVersionTooOld is the scheduler config // which throws error because the config version 'v1alpha1' // is too old schedulerConfigVersionTooOld = ` apiVersion: kubescheduler.config.k8s.io/v1alpha1 kind: KubeSchedulerConfiguration ` ) func TestLoadConfigFromFile(t *testing.T) { tmpDir, err := os.MkdirTemp("", "scheduler-configs") if err != nil { t.Fatal(err) } defer os.RemoveAll(tmpDir) correctConfigFile := filepath.Join(tmpDir, "correct_config.yaml") if err := os.WriteFile(correctConfigFile, []byte(schedulerConfigMinimalCorrect), os.FileMode(0600)); err != nil { t.Fatal(err) } decodeErrConfigFile := filepath.Join(tmpDir, "decode_err_no_version_config.yaml") if err := os.WriteFile(decodeErrConfigFile, []byte(schedulerConfigDecodeErr), os.FileMode(0600)); err != nil { t.Fatal(err) } versionTooOldConfigFile := filepath.Join(tmpDir, "version_too_old_config.yaml") if err := os.WriteFile(versionTooOldConfigFile, []byte(schedulerConfigVersionTooOld), os.FileMode(0600)); err != nil { t.Fatal(err) } tests := []struct { name           string path           string expectedErr    error expectedConfig *config.KubeSchedulerConfiguration }{ { name:           "Empty scheduler config file path", path:           "", expectedErr:    fmt.Errorf(fileNotFound), expectedConfig: nil, }, { name:           "Correct scheduler config", path:           correctConfigFile, expectedErr:    nil, expectedConfig: &config.KubeSchedulerConfiguration{}, }, { name:           "Scheduler config with decode error", path:           decodeErrConfigFile, expectedErr:    fmt.Errorf(apiVersionMissing), expectedConfig: nil, }, { name:           "Scheduler config version too old", path:           versionTooOldConfigFile, expectedErr:    fmt.Errorf(apiVersionTooOld), expectedConfig: nil, }, } logger := klog.FromContext(context.Background()) for i, test := range tests { t.Run(fmt.Sprintf("case_%d: %s", i, test.name), func(t *testing.T) { cfg, err := LoadConfigFromFile(logger, test.path) if test.expectedConfig == nil { assert.Nil(t, cfg) } else { assert.NotNil(t, cfg) } if test.expectedErr == nil { assert.NoError(t, err) } else { assert.ErrorContains(t, err, test.expectedErr.Error()) } }) } } </ins>

o.ApplyLeaderElectionTo(o.ComponentConfig) c.ComponentConfig = *o.ComponentConfig } else { <del> cfg, err := loadConfigFromFile(logger, o.ConfigFile) </del> <ins> cfg, err := LoadConfigFromFile(logger, o.ConfigFile) </ins> if err != nil { return err }