Skip to content

Commit

Permalink
Merge pull request kubernetes#4674 from abhgupta/abhgupta-dev
Browse files Browse the repository at this point in the history
Configuring scheduler via json configuration file
  • Loading branch information
davidopp committed Mar 2, 2015
2 parents f278fba + 5e096fe commit 32523f8
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 73 deletions.
7 changes: 7 additions & 0 deletions pkg/scheduler/generic_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ func findNodesThatFit(pod api.Pod, podLister PodLister, predicates map[string]Fi
// All scores are finally combined (added) to get the total weighted scores of all minions
func prioritizeNodes(pod api.Pod, podLister PodLister, priorityConfigs []PriorityConfig, minionLister MinionLister) (HostPriorityList, error) {
result := HostPriorityList{}

// If no priority configs are provided, then the EqualPriority function is applied
// This is required to generate the priority list in the required format
if len(priorityConfigs) == 0 {
return EqualPriority(pod, podLister, minionLister)
}

combinedScores := map[string]int{}
for _, priorityConfig := range priorityConfigs {
weight := priorityConfig.Weight
Expand Down
26 changes: 26 additions & 0 deletions plugin/cmd/kube-scheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ limitations under the License.
package app

import (
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"strconv"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand All @@ -30,6 +33,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider"
schedulerapi "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api"
latestschedulerapi "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"

"github.com/golang/glog"
Expand All @@ -42,6 +47,7 @@ type SchedulerServer struct {
Address util.IP
ClientConfig client.Config
AlgorithmProvider string
PolicyConfigFile string
}

// NewSchedulerServer creates a new SchedulerServer with default parameters
Expand All @@ -60,6 +66,7 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) {
fs.Var(&s.Address, "address", "The IP address to serve on (set to 0.0.0.0 for all interfaces)")
client.BindClientConfigFlags(fs, &s.ClientConfig)
fs.StringVar(&s.AlgorithmProvider, "algorithm_provider", s.AlgorithmProvider, "The scheduling algorithm provider to use")
fs.StringVar(&s.PolicyConfigFile, "policy_config_file", s.PolicyConfigFile, "File with scheduler policy configuration")
}

// Run runs the specified SchedulerServer. This should never exit.
Expand All @@ -78,17 +85,36 @@ func (s *SchedulerServer) Run(_ []string) error {
if err != nil {
glog.Fatalf("Failed to create scheduler configuration: %v", err)
}

sched := scheduler.New(config)
sched.Run()

select {}
}

func (s *SchedulerServer) createConfig(configFactory *factory.ConfigFactory) (*scheduler.Config, error) {
var policy schedulerapi.Policy
var configData []byte

if _, err := os.Stat(s.PolicyConfigFile); err == nil {
configData, err = ioutil.ReadFile(s.PolicyConfigFile)
if err != nil {
return nil, fmt.Errorf("Unable to read policy config: %v", err)
}
err = latestschedulerapi.Codec.DecodeInto(configData, &policy)
if err != nil {
return nil, fmt.Errorf("Invalid configuration: %v", err)
}

return configFactory.CreateFromConfig(policy)
}

// if the config file isn't provided, use the specified (or default) provider
// check of algorithm provider is registered and fail fast
_, err := factory.GetAlgorithmProvider(s.AlgorithmProvider)
if err != nil {
return nil, err
}

return configFactory.CreateFromProvider(s.AlgorithmProvider)
}
55 changes: 0 additions & 55 deletions plugin/pkg/scheduler/algorithmprovider/affinity/affinity.go

This file was deleted.

1 change: 0 additions & 1 deletion plugin/pkg/scheduler/algorithmprovider/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ limitations under the License.
package algorithmprovider

import (
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/affinity"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults"
)
2 changes: 0 additions & 2 deletions plugin/pkg/scheduler/algorithmprovider/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ package algorithmprovider
import (
"testing"

"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/affinity"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
)

var (
algorithmProviderNames = []string{
factory.DefaultProvider,
affinity.AffinityProvider,
}
)

Expand Down
38 changes: 38 additions & 0 deletions plugin/pkg/scheduler/api/latest/latest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 latest

import (
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api/v1"
)

// Version is the string that represents the current external default version.
const Version = "v1"

// OldestVersion is the string that represents the oldest server version supported.
const OldestVersion = "v1"

// Versions is the list of versions that are recognized in code. The order provided
// may be assumed to be least feature rich to most feature rich, and clients may
// choose to prefer the latter items in the list over the former items when presented
// with a set of versions to choose.
var Versions = []string{"v1"}

// Codec is the default codec for serializing input that should use
// the latest supported version.
// This codec can decode any object that Kubernetes is aware of.
var Codec = v1.Codec
32 changes: 32 additions & 0 deletions plugin/pkg/scheduler/api/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 api

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)

// Scheme is the default instance of runtime.Scheme to which types in the Kubernetes API are already registered.
var Scheme = runtime.NewScheme()

func init() {
Scheme.AddKnownTypes("",
&Policy{},
)
}

func (*Policy) IsAnAPIObject() {}
103 changes: 103 additions & 0 deletions plugin/pkg/scheduler/api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 api

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)

type Policy struct {
api.TypeMeta `json:",inline"`
// Holds the information to configure the fit predicate functions
Predicates []PredicatePolicy `json:"predicates"`
// Holds the information to configure the priority functions
Priorities []PriorityPolicy `json:"priorities"`
}

type PredicatePolicy struct {
// Identifier of the predicate policy
// For a custom predicate, the name can be user-defined
// For the Kubernetes provided predicates, the name is the identifier of the pre-defined predicate
Name string `json:"name"`
// Holds the parameters to configure the given predicate
Argument *PredicateArgument `json:"argument"`
}

type PriorityPolicy struct {
// Identifier of the priority policy
// For a custom priority, the name can be user-defined
// For the Kubernetes provided priority functions, the name is the identifier of the pre-defined priority function
Name string `json:"name"`
// The numeric multiplier for the minion scores that the priority function generates
Weight int `json:"weight"`
// Holds the parameters to configure the given priority function
Argument *PriorityArgument `json:"argument"`
}

// Represents the arguments that the different types of predicates take
// Only one of its members may be specified
type PredicateArgument struct {
// The predicate that provides affinity for pods belonging to a service
// It uses a label to identify minions that belong to the same "group"
ServiceAffinity *ServiceAffinity `json:"serviceAffinity"`
// The predicate that checks whether a particular minion has a certain label
// defined or not, regardless of value
LabelsPresence *LabelsPresence `json:"labelsPresence"`
}

// Represents the arguments that the different types of priorities take.
// Only one of its members may be specified
type PriorityArgument struct {
// The priority function that ensures a good spread (anti-affinity) for pods belonging to a service
// It uses a label to identify minions that belong to the same "group"
ServiceAntiAffinity *ServiceAntiAffinity `json:"serviceAntiAffinity"`
// The priority function that checks whether a particular minion has a certain label
// defined or not, regardless of value
LabelPreference *LabelPreference `json:"labelPreference"`
}

// Holds the parameters that are used to configure the corresponding predicate
type ServiceAffinity struct {
// The list of labels that identify minion "groups"
// All of the labels should match for the minion to be considered a fit for hosting the pod
Labels []string `json:"labels"`
}

// Holds the parameters that are used to configure the corresponding predicate
type LabelsPresence struct {
// The list of labels that identify minion "groups"
// All of the labels should be either present (or absent) for the minion to be considered a fit for hosting the pod
Labels []string `json:"labels"`
// The boolean flag that indicates whether the labels should be present or absent from the minion
Presence bool `json:"presence"`
}

// Holds the parameters that are used to configure the corresponding priority function
type ServiceAntiAffinity struct {
// Used to identify minion "groups"
Label string `json:"label"`
}

// Holds the parameters that are used to configure the corresponding priority function
type LabelPreference struct {
// Used to identify minion "groups"
Label string `json:"label"`
// This is a boolean flag
// If true, higher priority is given to minions that have the label
// If false, higher priority is given to minions that do not have the label
Presence bool `json:"presence"`
}
33 changes: 33 additions & 0 deletions plugin/pkg/scheduler/api/v1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 v1

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api"
)

// Codec encodes internal objects to the v1 scheme
var Codec = runtime.CodecFor(api.Scheme, "v1")

func init() {
api.Scheme.AddKnownTypes("v1",
&Policy{},
)
}

func (*Policy) IsAnAPIObject() {}
Loading

0 comments on commit 32523f8

Please sign in to comment.