Skip to content

Commit

Permalink
Merge pull request #3581 from wongnai/master
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

UsePolicyConfigMap for kube-scheduler

Continued from #3546 

In this version, a single option `usePolicyConfigMap` is added that will install scheduler.addons.k8s.io, which contains a default configmap.
  • Loading branch information
Kubernetes Submit Queue authored Oct 27, 2017
2 parents 1f4224b + 170bf52 commit 66f7400
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 27 deletions.
7 changes: 3 additions & 4 deletions docs/cluster_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,12 @@ This block contains configurations for `kube-scheduler`. See https://kubernetes
```yaml
spec:
kubeScheduler:
policyConfigMap: scheduler-policy
policyConfigMapNamespace: default
usePolicyConfigMap: true
```

Will resulting to running kube-scheduler with the arguments `--policy-configmap=scheduler-policy --policy-configmap-namespace=default`.
Will make kube-scheduler use the scheduler policy from configmap "scheduler-policy" in namespace kube-system.

Note that as of Kubernetes 1.8.0 kube-scheduler does not reload its configuration from configmap automatically. You will need to ssh into the master instance and restart the Docker container manually. Also, this option is not supported during cluster creation, only during updates.
Note that as of Kubernetes 1.8.0 kube-scheduler does not reload its configuration from configmap automatically. You will need to ssh into the master instance and restart the Docker container manually.

### kubeControllerManager
This block contains configurations for the `controller-manager`.
Expand Down
4 changes: 4 additions & 0 deletions nodeup/pkg/model/kube_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (b *KubeSchedulerBuilder) buildPod() (*v1.Pod, error) {
// Add kubeconfig flag
flags = append(flags, "--kubeconfig="+"/var/lib/kube-scheduler/kubeconfig")

if c.UsePolicyConfigMap != nil {
flags = append(flags, "--policy-configmap=scheduler-policy")
}

pod := &v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,8 @@ type KubeSchedulerConfig struct {
Image string `json:"image,omitempty"`
// LeaderElection defines the configuration of leader election client.
LeaderElection *LeaderElectionConfiguration `json:"leaderElection,omitempty"`
// PolicyConfigMap is the name of configmap to use for scheduler policy
PolicyConfigMap string `json:"policyConfigMap,omitempty" flag:"policy-configmap"`
// PolicyConfigMapNamespace is the namespace containing the configmap
PolicyConfigMapNamespace string `json:"policyConfigMapNamespace,omitempty" flag:"policy-configmap-namespace"`
// UsePolicyConfigMap enable setting the scheduler policy from a configmap
UsePolicyConfigMap *bool `json:"usePolicyConfigMap,omitempty"`
}

// LeaderElectionConfiguration defines the configuration of leader election
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/kops/v1alpha1/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,8 @@ type KubeSchedulerConfig struct {
Image string `json:"image,omitempty"`
// LeaderElection defines the configuration of leader election client.
LeaderElection *LeaderElectionConfiguration `json:"leaderElection,omitempty"`
// PolicyConfigMap is the name of configmap to use for scheduler policy
PolicyConfigMap string `json:"policyConfigMap,omitempty" flag:"policy-configmap"`
// PolicyConfigMapNamespace is the namespace containing the configmap
PolicyConfigMapNamespace string `json:"policyConfigMapNamespace,omitempty" flag:"policy-configmap-namespace"`
// UsePolicyConfigMap enable setting the scheduler policy from a configmap
UsePolicyConfigMap *bool `json:"usePolicyConfigMap,omitempty"`
}

// LeaderElectionConfiguration defines the configuration of leader election
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/kops/v1alpha1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2021,8 +2021,7 @@ func autoConvert_v1alpha1_KubeSchedulerConfig_To_kops_KubeSchedulerConfig(in *Ku
} else {
out.LeaderElection = nil
}
out.PolicyConfigMap = in.PolicyConfigMap
out.PolicyConfigMapNamespace = in.PolicyConfigMapNamespace
out.UsePolicyConfigMap = in.UsePolicyConfigMap
return nil
}

Expand All @@ -2044,8 +2043,7 @@ func autoConvert_kops_KubeSchedulerConfig_To_v1alpha1_KubeSchedulerConfig(in *ko
} else {
out.LeaderElection = nil
}
out.PolicyConfigMap = in.PolicyConfigMap
out.PolicyConfigMapNamespace = in.PolicyConfigMapNamespace
out.UsePolicyConfigMap = in.UsePolicyConfigMap
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kops/v1alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,15 @@ func (in *KubeSchedulerConfig) DeepCopyInto(out *KubeSchedulerConfig) {
(*in).DeepCopyInto(*out)
}
}
if in.UsePolicyConfigMap != nil {
in, out := &in.UsePolicyConfigMap, &out.UsePolicyConfigMap
if *in == nil {
*out = nil
} else {
*out = new(bool)
**out = **in
}
}
return
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,8 @@ type KubeSchedulerConfig struct {
Image string `json:"image,omitempty"`
// LeaderElection defines the configuration of leader election client.
LeaderElection *LeaderElectionConfiguration `json:"leaderElection,omitempty"`
// PolicyConfigMap is the name of configmap to use for scheduler policy
PolicyConfigMap string `json:"policyConfigMap,omitempty" flag:"policy-configmap"`
// PolicyConfigMapNamespace is the namespace containing the configmap
PolicyConfigMapNamespace string `json:"policyConfigMapNamespace,omitempty" flag:"policy-configmap-namespace"`
// UsePolicyConfigMap enable setting the scheduler policy from a configmap
UsePolicyConfigMap *bool `json:"usePolicyConfigMap,omitempty"`
}

// LeaderElectionConfiguration defines the configuration of leader election
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2283,8 +2283,7 @@ func autoConvert_v1alpha2_KubeSchedulerConfig_To_kops_KubeSchedulerConfig(in *Ku
} else {
out.LeaderElection = nil
}
out.PolicyConfigMap = in.PolicyConfigMap
out.PolicyConfigMapNamespace = in.PolicyConfigMapNamespace
out.UsePolicyConfigMap = in.UsePolicyConfigMap
return nil
}

Expand All @@ -2306,8 +2305,7 @@ func autoConvert_kops_KubeSchedulerConfig_To_v1alpha2_KubeSchedulerConfig(in *ko
} else {
out.LeaderElection = nil
}
out.PolicyConfigMap = in.PolicyConfigMap
out.PolicyConfigMapNamespace = in.PolicyConfigMapNamespace
out.UsePolicyConfigMap = in.UsePolicyConfigMap
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,15 @@ func (in *KubeSchedulerConfig) DeepCopyInto(out *KubeSchedulerConfig) {
(*in).DeepCopyInto(*out)
}
}
if in.UsePolicyConfigMap != nil {
in, out := &in.UsePolicyConfigMap, &out.UsePolicyConfigMap
if *in == nil {
*out = nil
} else {
*out = new(bool)
**out = **in
}
}
return
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kops/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,15 @@ func (in *KubeSchedulerConfig) DeepCopyInto(out *KubeSchedulerConfig) {
(*in).DeepCopyInto(*out)
}
}
if in.UsePolicyConfigMap != nil {
in, out := &in.UsePolicyConfigMap, &out.UsePolicyConfigMap
if *in == nil {
*out = nil
} else {
*out = new(bool)
**out = **in
}
}
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/model/components/kubescheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (b *KubeSchedulerOptionsBuilder) BuildOptions(o interface{}) error {

config := clusterSpec.KubeScheduler

if config.PolicyConfigMap != "" && b.IsKubernetesLT("v1.7.0") {
return fmt.Errorf("policyConfigMap is only supported in Kubernetes 1.7.0 or later")
if config.UsePolicyConfigMap != nil && b.IsKubernetesLT("v1.7.0") {
return fmt.Errorf("usePolicyConfigMap is only supported in Kubernetes 1.7.0 or later")
}

if config.LogLevel == 0 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/model/components/kubescheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import (
)

func buildSchedulerConfigMapCluster() *api.Cluster {
usePolicyConfigMap := true

return &api.Cluster{
Spec: api.ClusterSpec{
CloudProvider: "aws",
KubernetesVersion: "v1.4.0",
KubeScheduler: &api.KubeSchedulerConfig{
PolicyConfigMap: "scheduler-config",
UsePolicyConfigMap: &usePolicyConfigMap,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: scheduler-policy
namespace: kube-system
labels:
k8s-addon: scheduler.addons.k8s.io
data:
policy.cfg: |
{
"kind" : "Policy",
"apiVersion" : "v1",
"predicates" : [
{"name": "NoDiskConflict"},
{"name": "NoVolumeZoneConflict"},
{"name": "MaxEBSVolumeCount"},
{"name": "MaxGCEPDVolumeCount"},
{"name": "MaxAzureDiskVolumeCount"},
{"name": "MatchInterPodAffinity"},
{"name": "NoDiskConflict"},
{"name": "GeneralPredicates"},
{"name": "CheckNodeMemoryPressure"},
{"name": "CheckNodeDiskPressure"},
{"name": "CheckNodeCondition"},
{"name": "PodToleratesNodeTaints"},
{"name": "NoVolumeNodeConflict"}
],
"priorities" : [
{"name": "SelectorSpreadPriority", "weight" : 1},
{"name": "LeastRequestedPriority", "weight" : 1},
{"name": "BalancedResourceAllocation", "weight" : 1},
{"name": "NodePreferAvoidPodsPriority", "weight" : 1},
{"name": "NodeAffinityPriority", "weight" : 1},
{"name": "TaintTolerationPriority", "weight" : 1},
{"name": "InterPodAffinityPriority", "weight" : 1}
],
"hardPodAffinitySymmetricWeight" : 1
}
15 changes: 15 additions & 0 deletions upup/pkg/fi/cloudup/bootstrapchannelbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,5 +639,20 @@ func (b *BootstrapChannelBuilder) buildManifest() (*channelsapi.Addons, map[stri
}
}

if b.cluster.Spec.KubeScheduler.UsePolicyConfigMap != nil {
key := "scheduler.addons.k8s.io"
version := "1.7.0"

location := key + "/v" + version + ".yaml"

addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(version),
Selector: map[string]string{"k8s-addon": key},
Manifest: fi.String(location),
})
manifests[key] = "addons/" + location
}

return addons, manifests, nil
}

0 comments on commit 66f7400

Please sign in to comment.