Skip to content

Commit

Permalink
Merge pull request #67352 from liggitt/scheduler-default-test
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Add test for scheduler config defaults

This test will let us notice if defaults change when loading from a config file or from flags.

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue committed Aug 17, 2018
2 parents 4411a6f + 13de114 commit 7ff2fee
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/kube-scheduler/app/options/BUILD
Expand Up @@ -68,6 +68,9 @@ go_test(
"//cmd/kube-scheduler/app/config:go_default_library",
"//pkg/apis/componentconfig:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/config:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/config:go_default_library",
],
)
81 changes: 76 additions & 5 deletions cmd/kube-scheduler/app/options/options_test.go
Expand Up @@ -23,10 +23,15 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"time"

apimachineryconfig "k8s.io/apimachinery/pkg/apis/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/diff"
apiserverconfig "k8s.io/apiserver/pkg/apis/config"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)

Expand Down Expand Up @@ -127,24 +132,86 @@ users:
defer os.Setenv("KUBERNETES_SERVICE_HOST", originalHost)
}

defaultSource := "DefaultProvider"

testcases := []struct {
name string
options *Options
expectedUsername string
expectedError string
expectedConfig componentconfig.KubeSchedulerConfiguration
}{
{
name: "config file",
options: &Options{ConfigFile: configFile},
name: "config file",
options: &Options{
ConfigFile: configFile,
ComponentConfig: func() componentconfig.KubeSchedulerConfiguration {
cfg, _ := newDefaultComponentConfig()
return *cfg
}(),
},
expectedUsername: "config",
expectedConfig: componentconfig.KubeSchedulerConfiguration{
SchedulerName: "default-scheduler",
AlgorithmSource: componentconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
HardPodAffinitySymmetricWeight: 1,
HealthzBindAddress: "0.0.0.0:10251",
MetricsBindAddress: "0.0.0.0:10251",
FailureDomains: "kubernetes.io/hostname,failure-domain.beta.kubernetes.io/zone,failure-domain.beta.kubernetes.io/region",
LeaderElection: componentconfig.KubeSchedulerLeaderElectionConfiguration{
LeaderElectionConfiguration: apiserverconfig.LeaderElectionConfiguration{
LeaderElect: true,
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
ResourceLock: "endpoints",
},
LockObjectNamespace: "kube-system",
LockObjectName: "kube-scheduler",
},
ClientConnection: apimachineryconfig.ClientConnectionConfiguration{
Kubeconfig: configKubeconfig,
QPS: 50,
Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf",
},
},
},
{
name: "kubeconfig flag",
options: &Options{
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
ClientConnection: apimachineryconfig.ClientConnectionConfiguration{
Kubeconfig: flagKubeconfig}}},
ComponentConfig: func() componentconfig.KubeSchedulerConfiguration {
cfg, _ := newDefaultComponentConfig()
cfg.ClientConnection.Kubeconfig = flagKubeconfig
return *cfg
}(),
},
expectedUsername: "flag",
expectedConfig: componentconfig.KubeSchedulerConfiguration{
SchedulerName: "default-scheduler",
AlgorithmSource: componentconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
HardPodAffinitySymmetricWeight: 1,
HealthzBindAddress: "", // defaults empty when not running from config file
MetricsBindAddress: "", // defaults empty when not running from config file
FailureDomains: "kubernetes.io/hostname,failure-domain.beta.kubernetes.io/zone,failure-domain.beta.kubernetes.io/region",
LeaderElection: componentconfig.KubeSchedulerLeaderElectionConfiguration{
LeaderElectionConfiguration: apiserverconfig.LeaderElectionConfiguration{
LeaderElect: true,
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
ResourceLock: "endpoints",
},
LockObjectNamespace: "kube-system",
LockObjectName: "kube-scheduler",
},
ClientConnection: apimachineryconfig.ClientConnectionConfiguration{
Kubeconfig: flagKubeconfig,
QPS: 50,
Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf",
},
},
},
{
name: "overridden master",
Expand Down Expand Up @@ -173,6 +240,10 @@ users:
return
}

if !reflect.DeepEqual(config.ComponentConfig, tc.expectedConfig) {
t.Errorf("config.diff:\n%s", diff.ObjectReflectDiff(tc.expectedConfig, config.ComponentConfig))
}

// ensure we have a client
if config.Client == nil {
t.Error("unexpected nil client")
Expand Down

0 comments on commit 7ff2fee

Please sign in to comment.