Skip to content

Commit

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

Added PolicyConfigMap and PolicyConfigMapNamespace to KubeSchedulerConfig
  • Loading branch information
Kubernetes Submit Queue authored Oct 10, 2017
2 parents eff2651 + a06fbba commit d7d62b8
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/cluster_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ NOTE: Where the corresponding configuration value can be empty, fields can be se

Will result in the flag `--resolv-conf=` being built.

### kubeScheduler

This block contains configurations for `kube-scheduler`. See https://kubernetes.io/docs/admin/kube-scheduler/

```yaml
spec:
kubeScheduler:
policyConfigMap: scheduler-policy
policyConfigMapNamespace: default
```

Will resulting to running kube-scheduler with the arguments `--policy-configmap=scheduler-policy --policy-configmap-namespace=default`.

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.

#### Feature Gates

```yaml
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ 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"`
}

// LeaderElectionConfiguration defines the configuration of leader election
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kops/v1alpha1/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ 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"`
}

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

Expand All @@ -2024,6 +2026,8 @@ func autoConvert_kops_KubeSchedulerConfig_To_v1alpha1_KubeSchedulerConfig(in *ko
} else {
out.LeaderElection = nil
}
out.PolicyConfigMap = in.PolicyConfigMap
out.PolicyConfigMapNamespace = in.PolicyConfigMapNamespace
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ 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"`
}

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

Expand All @@ -2286,6 +2288,8 @@ func autoConvert_kops_KubeSchedulerConfig_To_v1alpha2_KubeSchedulerConfig(in *ko
} else {
out.LeaderElection = nil
}
out.PolicyConfigMap = in.PolicyConfigMap
out.PolicyConfigMapNamespace = in.PolicyConfigMapNamespace
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/model/components/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go_test(
srcs = [
"kubecontrollermanager_test.go",
"kubelet_test.go",
"kubescheduler_test.go",
],
library = ":go_default_library",
deps = [
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/components/kubescheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package components

import (
"fmt"

"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/loader"
Expand All @@ -37,6 +39,10 @@ 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.LogLevel == 0 {
// TODO: No way to set to 0?
config.LogLevel = 2
Expand Down
135 changes: 135 additions & 0 deletions pkg/model/components/kubescheduler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
Copyright 2017 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 components

import (
"testing"

api "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/kops/util"
"k8s.io/kops/pkg/assets"
)

func buildSchedulerConfigMapCluster() *api.Cluster {
return &api.Cluster{
Spec: api.ClusterSpec{
CloudProvider: "aws",
KubernetesVersion: "v1.4.0",
KubeScheduler: &api.KubeSchedulerConfig{
PolicyConfigMap: "scheduler-config",
},
},
}
}

func Test_Build_Scheduler_Without_PolicyConfigMap(t *testing.T) {
versions := []string{"v1.6.0", "v1.6.4", "v1.7.0", "v1.7.4"}
b := assets.NewAssetBuilder(nil)

for _, v := range versions {

c := buildCluster()

version, err := util.ParseKubernetesVersion(v)

if err != nil {
t.Fatalf("unexpected error from ParseKubernetesVersion %s: %v", v, err)
}

ks := &KubeSchedulerOptionsBuilder{
&OptionsContext{
AssetBuilder: b,
KubernetesVersion: *version,
},
}

spec := c.Spec

spec.KubernetesVersion = v
err = ks.BuildOptions(&spec)

if err != nil {
t.Fatalf("unexpected error from BuildOptions: %v", err)
}
}

}
func Test_Build_Scheduler_PolicyConfigMap_Unsupported_Version(t *testing.T) {
versions := []string{"v1.6.0", "v1.6.4"}
b := assets.NewAssetBuilder(nil)

for _, v := range versions {

c := buildSchedulerConfigMapCluster()

version, err := util.ParseKubernetesVersion(v)

if err != nil {
t.Fatalf("unexpected error from ParseKubernetesVersion %s: %v", v, err)
}

ks := &KubeSchedulerOptionsBuilder{
&OptionsContext{
AssetBuilder: b,
KubernetesVersion: *version,
},
}

spec := c.Spec

spec.KubernetesVersion = v
err = ks.BuildOptions(&spec)

if err == nil {
t.Fatalf("error is expected, but none are returned")
}
}

}

func Test_Build_Scheduler_PolicyConfigMap_Supported_Version(t *testing.T) {
versions := []string{"v1.7.0", "v1.7.4", "v1.8.0"}
b := assets.NewAssetBuilder(nil)

for _, v := range versions {

c := buildSchedulerConfigMapCluster()

version, err := util.ParseKubernetesVersion(v)

if err != nil {
t.Fatalf("unexpected error from ParseKubernetesVersion %s: %v", v, err)
}

ks := &KubeSchedulerOptionsBuilder{
&OptionsContext{
AssetBuilder: b,
KubernetesVersion: *version,
},
}

spec := c.Spec

spec.KubernetesVersion = v
err = ks.BuildOptions(&spec)

if err != nil {
t.Fatalf("unexpected error from BuildOptions %s: %v", v, err)
}
}

}

0 comments on commit d7d62b8

Please sign in to comment.