mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #53783 from tizhou86/schedulerUnitTest
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>. Added more unit tests for kube-scheduler. **What this PR does / why we need it**: Added more unit tests for kube-scheduler. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # NONE **Special notes for your reviewer**: NONE **Release note**: ```release-note NONE ```
This commit is contained in:
commit
16dbab9778
@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
@ -34,3 +35,15 @@ filegroup(
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["options_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//pkg/apis/componentconfig:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
],
|
||||
)
|
||||
|
103
plugin/cmd/kube-scheduler/app/options/options_test.go
Normal file
103
plugin/cmd/kube-scheduler/app/options/options_test.go
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
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 options
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func TestAddFlags(t *testing.T) {
|
||||
f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
|
||||
s := NewSchedulerServer()
|
||||
s.AddFlags(f)
|
||||
|
||||
args := []string{
|
||||
"--address=192.168.4.20",
|
||||
"--algorithm-provider=FooProvider",
|
||||
"--contention-profiling=true",
|
||||
"--failure-domains=kubernetes.io/hostname",
|
||||
"--hard-pod-affinity-symmetric-weight=0",
|
||||
"--kube-api-burst=80",
|
||||
"--kube-api-content-type=application/vnd.kubernetes.protobuf",
|
||||
"--kube-api-qps=40.0",
|
||||
"--kubeconfig=/foo/bar/kubeconfig",
|
||||
"--leader-elect=true",
|
||||
"--leader-elect-lease-duration=20s",
|
||||
"--leader-elect-renew-deadline=15s",
|
||||
"--leader-elect-resource-lock=endpoints",
|
||||
"--leader-elect-retry-period=3s",
|
||||
"--lock-object-name=test-lock-object-name",
|
||||
"--lock-object-namespace=test-lock-object-ns",
|
||||
"--master=192.168.4.20",
|
||||
"--policy-config-file=/foo/bar/policyconfig",
|
||||
"--policy-configmap=test-policy-configmap",
|
||||
"--policy-configmap-namespace=test-policy-configmap-ns",
|
||||
"--port=10000",
|
||||
"--profiling=false",
|
||||
"--scheduler-name=test-scheduler-name",
|
||||
"--use-legacy-policy-config=true",
|
||||
}
|
||||
|
||||
f.Parse(args)
|
||||
|
||||
expected := &SchedulerServer{
|
||||
KubeSchedulerConfiguration: componentconfig.KubeSchedulerConfiguration{
|
||||
Port: 10000,
|
||||
Address: "192.168.4.20",
|
||||
AlgorithmProvider: "FooProvider",
|
||||
PolicyConfigFile: "/foo/bar/policyconfig",
|
||||
EnableContentionProfiling: true,
|
||||
EnableProfiling: false,
|
||||
|
||||
ContentType: "application/vnd.kubernetes.protobuf",
|
||||
KubeAPIQPS: 40.0,
|
||||
KubeAPIBurst: 80,
|
||||
SchedulerName: "test-scheduler-name",
|
||||
LeaderElection: componentconfig.LeaderElectionConfiguration{
|
||||
ResourceLock: "endpoints",
|
||||
LeaderElect: true,
|
||||
LeaseDuration: metav1.Duration{Duration: 20 * time.Second},
|
||||
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
||||
RetryPeriod: metav1.Duration{Duration: 3 * time.Second},
|
||||
},
|
||||
|
||||
LockObjectNamespace: "test-lock-object-ns",
|
||||
LockObjectName: "test-lock-object-name",
|
||||
|
||||
PolicyConfigMapName: "test-policy-configmap",
|
||||
PolicyConfigMapNamespace: "test-policy-configmap-ns",
|
||||
UseLegacyPolicyConfig: true,
|
||||
|
||||
HardPodAffinitySymmetricWeight: 0,
|
||||
FailureDomains: "kubernetes.io/hostname",
|
||||
},
|
||||
Kubeconfig: "/foo/bar/kubeconfig",
|
||||
Master: "192.168.4.20",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expected, s) {
|
||||
t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, s))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user