Repository: kubernetes-sigs/kube-scheduler-simulator
Pull request #282 (2023-04-08 14:03:27)

BugFix: some wrappedPlugin returns non suit status
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

#### What type of PR is this?
/area simulator
/kind bug
<!--
Add related area tag(s):
/area web
/area simulator
/area scenario

Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:

Some wrappedPlugin returns nonsuit status if it does not support the extension point.
This caused the first and subsequent plugins to no called if more than one plugin was set for that extension point. This caused the first and subsequent plugins to no called if more than one plugin was set for that extension point.

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

#### Special notes for your reviewer:


/label tide/merge-method-squash
/assign @sanposhiho 

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/282#" title="Author self-approved">196Ikuchil</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign sanposhiho for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["sanposhiho"]} -->
sanposhiho: /priority next-release
k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/282#" title="Author self-approved">196Ikuchil</a>*
**Once this PR has been reviewed and has the lgtm label**, please ask for approval from sanposhiho. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["sanposhiho"]} -->
196Ikuchil: @sanposhiho 
Thanks for your review. 
Fixed :pray:

bfe9ee6
k8s-ci-robot: @196Ikuchil: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kube-scheduler-simulator-backend-unit-test | bfe9ee64e9882ef709bf7eee3ac9b39ff05b75e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kube-scheduler-simulator/282/pull-kube-scheduler-simulator-backend-unit-test/1644938767804403712) | true | `/test pull-kube-scheduler-simulator-backend-unit-test`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kube-scheduler-simulator&pr=282). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3A196Ikuchil). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kube-scheduler-simulator/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
sanposhiho: /lgtm
/approve

Thanks!
k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/282#" title="Author self-approved">196Ikuchil</a>*, *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/282#issuecomment-1501050074" title="Approved">sanposhiho</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/OWNERS)~~ [sanposhiho]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/simulator/scheduler/plugin/wrappedplugin.go b/simulator/scheduler/plugin/wrappedplugin.go
index 6d6a5fd2..dfdd5a0f 100644
--- a/simulator/scheduler/plugin/wrappedplugin.go
+++ b/simulator/scheduler/plugin/wrappedplugin.go
@@ -517,8 +517,9 @@ func (w *wrappedPlugin) Filter(ctx context.Context, state *framework.CycleState,
 
 func (w *wrappedPlugin) PostFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
 	if w.originalPostFilterPlugin == nil {
-		// return nil not to affect post filtering.
-		return nil, nil
+		// return Unschedulable not to affect post filtering.
+		// (If return Unschedulable, the scheduler will execute next PostFilter plugin.)
+		return nil, framework.NewStatus(framework.Unschedulable)
 	}
 	if w.postFilterPluginExtender != nil {
 		r, s := w.postFilterPluginExtender.BeforePostFilter(ctx, state, pod, filteredNodeStatusMap)
@@ -665,8 +666,8 @@ func (w *wrappedPlugin) PreBind(ctx context.Context, state *framework.CycleState
 
 func (w *wrappedPlugin) Bind(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodename string) *framework.Status {
 	if w.originalBindPlugin == nil {
-		// return nil not to affect scoring
-		return nil
+		// return skip not to affect other bind plugins.
+		return framework.NewStatus(framework.Skip, "called wrapped bind plugin is nil")
 	}
 
 	if w.bindPluginExtender != nil {


Test patch:
diff --git a/simulator/scheduler/plugin/wrappedplugin_test.go b/simulator/scheduler/plugin/wrappedplugin_test.go
index 8a8694b8..8de3a14a 100644
--- a/simulator/scheduler/plugin/wrappedplugin_test.go
+++ b/simulator/scheduler/plugin/wrappedplugin_test.go
@@ -472,7 +472,7 @@ func Test_wrappedPlugin_PostFilter(t *testing.T) {
 				},
 			},
 			wantResult: nil,
-			wantStatus: nil,
+			wantStatus: framework.NewStatus(framework.Unschedulable),
 		},
 		{
 			name: "fail when original plugin return non-success",
@@ -1860,24 +1860,33 @@ func Test_wrappedPlugin_Bind(t *testing.T) {
 			noExtender: true,
 			want:       framework.NewStatus(framework.Success),
 		},
+		{
+			name:       "unhappy: it is not bind plugin",
+			noExtender: true,
+			want:       framework.NewStatus(framework.Skip, "called wrapped bind plugin is nil"),
+		},
 	}
 	for _, tt := range tests {
 		tt := tt
 		t.Run(tt.name, func(t *testing.T) {
 			t.Parallel()
 			ctrl := gomock.NewController(t)
-			s := mock_plugin.NewMockStore(ctrl)
-			p := mock_plugin.NewMockBindPlugin(ctrl)
-			ex := mock_plugin.NewMockBindPluginExtender(ctrl)
-			tt.prepareMocksFn(s, p, ex)
 
-			w := &wrappedPlugin{
-				store:              s,
-				originalBindPlugin: p,
-			}
-			if !tt.noExtender {
-				w.bindPluginExtender = ex
+			w := &wrappedPlugin{}
+			if tt.prepareMocksFn != nil {
+				s := mock_plugin.NewMockStore(ctrl)
+				p := mock_plugin.NewMockBindPlugin(ctrl)
+				ex := mock_plugin.NewMockBindPluginExtender(ctrl)
+				tt.prepareMocksFn(s, p, ex)
+				w = &wrappedPlugin{
+					store:              s,
+					originalBindPlugin: p,
+				}
+				if !tt.noExtender {
+					w.bindPluginExtender = ex
+				}
 			}
+
 			assert.Equalf(t, tt.want, w.Bind(context.Background(), framework.NewCycleState(), testPod, testNodeName), "Bind(ctx, cyclestate, %v, %v)", testPod, testNodeName)
 		})
 	}