New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scheduler_test.go to use Clientset #70290

Merged
merged 1 commit into from Oct 30, 2018

Conversation

Projects
None yet
4 participants
@tossmilestone
Contributor

tossmilestone commented Oct 26, 2018

What type of PR is this?

Uncomment only one, leave it on its own line:

/kind api-change
/kind bug

/kind cleanup

/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:
Use k8s.io/client-go/kubernetes/fake.Clientset as the fake k8s client in pkg/scheduler/scheduler_test.go.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #68962

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Refactor scheduler_test.go to use a fake k8s client.
@tossmilestone

This comment has been minimized.

Contributor

tossmilestone commented Oct 26, 2018

/assign @misterikkit

@timothysc timothysc removed their request for review Oct 26, 2018

@k82cn

This comment has been minimized.

Member

k82cn commented Oct 29, 2018

/ok-to-test
/approve

@k8s-ci-robot

This comment has been minimized.

Contributor

k8s-ci-robot commented Oct 29, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: k82cn, tossmilestone

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Refactor scheduler_test.go to use Clientset
Signed-off-by: He Xiaoxi <xxhe@alauda.io>
@misterikkit

This looks pretty good. I think overall, scheduler_test.go is already somewhat messy, but this PR is not about cleaning that up. Please look into the SelfLink thing, and then I'll approve.

@@ -54,19 +54,20 @@ go_test(
"//pkg/scheduler/factory:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/cache/fake:go_default_library",
"//pkg/scheduler/testing:go_default_library",

This comment has been minimized.

@misterikkit

misterikkit Oct 29, 2018

Contributor

❤️

func podWithID(id, desiredHost string) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: id,
UID: types.UID(id),
SelfLink: schedulertesting.Test.SelfLink(string(v1.ResourcePods), id),
SelfLink: fmt.Sprintf("/api/v1/%s/%s", string(v1.ResourcePods), id),

This comment has been minimized.

@misterikkit

misterikkit Oct 29, 2018

Contributor

Do the tests pass with this line removed? My understanding is that SelfLink is not important to any of the behavior we are trying to test.

This comment has been minimized.

@tossmilestone

tossmilestone Oct 30, 2018

Contributor

I have run the test without SelfLink, but it will cause error below:

1030 01:51:38.384380   13145 event.go:259] Could not construct reference to: '&v1.Pod{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"foo", GenerateName:"", Namespace:"", SelfLink:"", UID:"foo", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:v1.PodSpec{Volumes:[]v1.Volume(nil), InitContainers:[]v1.Container(nil), Containers:[]v1.Container(nil), RestartPolicy:"", TerminationGracePeriodSeconds:(*int64)(nil), ActiveDeadlineSeconds:(*int64)(nil), DNSPolicy:"", NodeSelector:map[string]string(nil), ServiceAccountName:"", DeprecatedServiceAccount:"", AutomountServiceAccountToken:(*bool)(nil), NodeName:"machine1", HostNetwork:false, HostPID:false, HostIPC:false, ShareProcessNamespace:(*bool)(nil), SecurityContext:(*v1.PodSecurityContext)(nil), ImagePullSecrets:[]v1.LocalObjectReference(nil), Hostname:"", Subdomain:"", Affinity:(*v1.Affinity)(nil), SchedulerName:"", Tolerations:[]v1.Toleration(nil), HostAliases:[]v1.HostAlias(nil), PriorityClassName:"", Priority:(*int32)(nil), DNSConfig:(*v1.PodDNSConfig)(nil), ReadinessGates:[]v1.PodReadinessGate(nil), RuntimeClassName:(*string)(nil), EnableServiceLinks:(*bool)(nil)}, Status:v1.PodStatus{Phase:"", Conditions:[]v1.PodCondition(nil), Message:"", Reason:"", NominatedNodeName:"", HostIP:"", PodIP:"", StartTime:(*v1.Time)(nil), InitContainerStatuses:[]v1.ContainerStatus(nil), ContainerStatuses:[]v1.ContainerStatus(nil), QOSClass:""}}' due to: 'selfLink was empty, can't make reference'. Will not report event: 'Normal' 'Scheduled' 'Successfully assigned /foo to machine1'

and the test will hang waiting for the event. So the SelfLink is necessary for test. 😢

This comment has been minimized.

@misterikkit

misterikkit Oct 30, 2018

Contributor

Huh, weird. I'd like to look into that eventually.

@misterikkit

This comment has been minimized.

Contributor

misterikkit commented Oct 30, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Oct 30, 2018

@k8s-ci-robot k8s-ci-robot merged commit 2f175c1 into kubernetes:master Oct 30, 2018

18 checks passed

cla/linuxfoundation tossmilestone authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-e2e-kubeadm-gce Skipped
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped
pull-kubernetes-local-e2e-containerized Skipped
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
tide In merge pool.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment