Skip to content
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

extracts out pool and stubs plugin functions #31

Merged
merged 1 commit into from
Jun 7, 2023

Conversation

codefromthecrypt
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This extracts the guest pool into its own type so that it can be unit tested without export helpers. Notably, this makes it a generic type which makes testing a lot easier. In the process, I found and fixed a test bug.

This also stubs all the host-side plugins in declaration order according to the framework interface. This helps me understand what we are implementing, and allows the IDE to find the upstream documentation vs guessing.

https://github.com/kubernetes/kubernetes/blob/master/pkg/scheduler/framework/interface.go#L304-L506

Which issue(s) this PR fixes:

NONE

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

What are the benchmark results of this change?

N/A

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 6, 2023
Copy link
Contributor Author

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notes

"k8s.io/kubernetes/pkg/scheduler/framework"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"

"github.com/tetratelabs/wazero"
)

const PluginName = "wasm"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all logic in this file is the same, I only implemented the plugin interfaces, stubbed with TODO.

// guestPool manages guest to pod assignments in a scheduling or binding cycle.
type guestPool[guest any] struct {
// newGuest is a function to create a new guest.
newGuest func(context.Context) (guest, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By extracting this function and making it a generic type, I was able to find a subtle bug in the test.

}

uid := types.UID("test-uid")
differentuid := types.UID("test-uid")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the bug in test which drove me a little bonkers until I saw it ;)

// pointer to the current request.
type filterArgsKey struct{}
type filterParamsKey struct{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: renamed to params because functions have parameters not args (in Go and Wasm)

// into the pool.
func (p *guestPool[guest]) unassignForScheduling() {
assigned := p.assignedToSchedulingPod
var zero guest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only weird thing for people not used to generics is you can't cast to nil (guest(nil)), However the following has the same effect.

Copy link
Contributor

@kerthcet kerthcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one nit, other LGTM

scheduler/plugin/host.go Outdated Show resolved Hide resolved
Signed-off-by: Adrian Cole <adrian@tetrate.io>
@kerthcet
Copy link
Contributor

kerthcet commented Jun 7, 2023

/lgtm
/approve

thanks

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 7, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: codefromthecrypt, kerthcet

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 7, 2023
@k8s-ci-robot k8s-ci-robot merged commit e0e8e71 into kubernetes-sigs:main Jun 7, 2023
2 checks passed
@codefromthecrypt
Copy link
Contributor Author

thanks for the review @kerthcet!

@codefromthecrypt codefromthecrypt deleted the pool-refactor branch June 7, 2023 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants