mirror of https://github.com/k3s-io/k3s
Add test for scheduler config defaults
parent
4d40dd0783
commit
13de114286
|
@ -68,6 +68,9 @@ go_test(
|
||||||
"//cmd/kube-scheduler/app/config:go_default_library",
|
"//cmd/kube-scheduler/app/config:go_default_library",
|
||||||
"//pkg/apis/componentconfig: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/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/apimachinery/pkg/util/rand:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apiserver/pkg/apis/config:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,10 +23,15 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
apimachineryconfig "k8s.io/apimachinery/pkg/apis/config"
|
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"
|
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -127,24 +132,86 @@ users:
|
||||||
defer os.Setenv("KUBERNETES_SERVICE_HOST", originalHost)
|
defer os.Setenv("KUBERNETES_SERVICE_HOST", originalHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultSource := "DefaultProvider"
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
options *Options
|
options *Options
|
||||||
expectedUsername string
|
expectedUsername string
|
||||||
expectedError string
|
expectedError string
|
||||||
|
expectedConfig componentconfig.KubeSchedulerConfiguration
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "config file",
|
name: "config file",
|
||||||
options: &Options{ConfigFile: configFile},
|
options: &Options{
|
||||||
|
ConfigFile: configFile,
|
||||||
|
ComponentConfig: func() componentconfig.KubeSchedulerConfiguration {
|
||||||
|
cfg, _ := newDefaultComponentConfig()
|
||||||
|
return *cfg
|
||||||
|
}(),
|
||||||
|
},
|
||||||
expectedUsername: "config",
|
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",
|
name: "kubeconfig flag",
|
||||||
options: &Options{
|
options: &Options{
|
||||||
ComponentConfig: componentconfig.KubeSchedulerConfiguration{
|
ComponentConfig: func() componentconfig.KubeSchedulerConfiguration {
|
||||||
ClientConnection: apimachineryconfig.ClientConnectionConfiguration{
|
cfg, _ := newDefaultComponentConfig()
|
||||||
Kubeconfig: flagKubeconfig}}},
|
cfg.ClientConnection.Kubeconfig = flagKubeconfig
|
||||||
|
return *cfg
|
||||||
|
}(),
|
||||||
|
},
|
||||||
expectedUsername: "flag",
|
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",
|
name: "overridden master",
|
||||||
|
@ -173,6 +240,10 @@ users:
|
||||||
return
|
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
|
// ensure we have a client
|
||||||
if config.Client == nil {
|
if config.Client == nil {
|
||||||
t.Error("unexpected nil client")
|
t.Error("unexpected nil client")
|
||||||
|
|
Loading…
Reference in New Issue