diff --git a/plugin/cmd/kube-scheduler/app/configurator.go b/plugin/cmd/kube-scheduler/app/configurator.go index 1d0d9e08eb7..f5f23c3f280 100644 --- a/plugin/cmd/kube-scheduler/app/configurator.go +++ b/plugin/cmd/kube-scheduler/app/configurator.go @@ -139,17 +139,13 @@ func (sc schedulerConfigurator) getSchedulerPolicyConfig() (*schedulerapi.Policy return nil, fmt.Errorf("Error getting scheduler policy ConfigMap: %v.", err) } if policyConfigMap != nil { - // We expect the first element in the Data member of the ConfigMap to - // contain the policy config. - if len(policyConfigMap.Data) != 1 { - return nil, fmt.Errorf("ConfigMap %v has %v entries in its 'Data'. It must have only one.", sc.policyConfigMap, len(policyConfigMap.Data)) - } - policyConfigMapFound = true - // This loop should iterate only once, as we have already checked the length of Data. - for _, val := range policyConfigMap.Data { - glog.V(5).Infof("Scheduler policy ConfigMap: %v", val) - configData = []byte(val) + var configString string + configString, policyConfigMapFound = policyConfigMap.Data[options.SchedulerPolicyConfigMapKey] + if !policyConfigMapFound { + return nil, fmt.Errorf("No element with key = '%v' is found in the ConfigMap 'Data'.", options.SchedulerPolicyConfigMapKey) } + glog.V(5).Infof("Scheduler policy ConfigMap: %v", configString) + configData = []byte(configString) } } diff --git a/plugin/cmd/kube-scheduler/app/options/options.go b/plugin/cmd/kube-scheduler/app/options/options.go index 535c2696df0..6db57db802b 100644 --- a/plugin/cmd/kube-scheduler/app/options/options.go +++ b/plugin/cmd/kube-scheduler/app/options/options.go @@ -18,6 +18,8 @@ limitations under the License. package options import ( + "fmt" + utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/apis/componentconfig" @@ -33,6 +35,10 @@ import ( "github.com/spf13/pflag" ) +// SchedulerPolicyConfigMapKey defines the key of the element in the +// scheduler's policy ConfigMap that contains scheduler's policy config. +const SchedulerPolicyConfigMapKey string = "policy.cfg" + // SchedulerServer has all the context and params needed to run a Scheduler type SchedulerServer struct { componentconfig.KubeSchedulerConfiguration @@ -64,7 +70,8 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.Address, "address", s.Address, "The IP address to serve on (set to 0.0.0.0 for all interfaces)") fs.StringVar(&s.AlgorithmProvider, "algorithm-provider", s.AlgorithmProvider, "The scheduling algorithm provider to use, one of: "+factory.ListAlgorithmProviders()) fs.StringVar(&s.PolicyConfigFile, "policy-config-file", s.PolicyConfigFile, "File with scheduler policy configuration. This file is used if policy ConfigMap is not provided or --use-legacy-policy-config==true") - fs.StringVar(&s.PolicyConfigMapName, "policy-configmap", s.PolicyConfigMapName, "Name of the ConfigMap object that contains scheduler's policy configuration. It must exist in the system namespace before scheduler initialization if --use-legacy-policy-config==false") + usage := fmt.Sprintf("Name of the ConfigMap object that contains scheduler's policy configuration. It must exist in the system namespace before scheduler initialization if --use-legacy-policy-config==false. The config must be provided as the value of an element in 'Data' map with the key='%v'", SchedulerPolicyConfigMapKey) + fs.StringVar(&s.PolicyConfigMapName, "policy-configmap", s.PolicyConfigMapName, usage) fs.StringVar(&s.PolicyConfigMapNamespace, "policy-configmap-namespace", s.PolicyConfigMapNamespace, "The namespace where policy ConfigMap is located. The system namespace will be used if this is not provided or is empty.") fs.BoolVar(&s.UseLegacyPolicyConfig, "use-legacy-policy-config", false, "When set to true, scheduler will ignore policy ConfigMap and uses policy config file") fs.BoolVar(&s.EnableProfiling, "profiling", true, "Enable profiling via web interface host:port/debug/pprof/") diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 1fb14935f1b..9d86e9832cf 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -99,7 +99,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { policyConfigMap := v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceSystem, Name: configPolicyName}, Data: map[string]string{ - "scheduler-policy-config.json": `{ + options.SchedulerPolicyConfigMapKey: `{ "kind" : "Policy", "apiVersion" : "v1", "predicates" : [