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

feat: refactor to maintain policy state in-memory #49

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

cmaclaughlin
Copy link
Contributor

Re: #25

The capacity scheduling plugin was used for frame of reference. A collection of policy information is kept in-memory on the PlacementPolicyManager. Instead of annotations, the policy info in the collection includes 2 sets:

  • all pods that qualify for / fall under the policy
  • all pods assigned to nodes in accordance with the policy ("managed by")

An event handler was attached to the pod informer so pod deletion can trigger updating the in-memory version of the policy accordingly. Additionally, the custom info object is included in the state object added to cycle state as a part of PreFilter and PreScore stages so that Filter and Score stages have access to it as well.

@cmaclaughlin cmaclaughlin marked this pull request as ready for review January 21, 2022 20:48
@helayoty helayoty added the enhancement New feature or request label Jan 21, 2022
Copy link
Collaborator

@helayoty helayoty left a comment

Choose a reason for hiding this comment

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

The way you implemented it is great. Thank you for your efforts!

pkg/plugins/placementpolicy/core/core.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/placementpolicy.go Outdated Show resolved Hide resolved
@helayoty helayoty linked an issue Feb 7, 2022 that may be closed by this pull request
Copy link
Member

@aramase aramase left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I've reviewed core.go and policy.go mostly and added comments. I'll review the other files next and add comments if any.

pkg/plugins/placementpolicy/core/core.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/core.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/core.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/core.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/core.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
p.qualifiedPods = p.qualifiedPods.Delete(key)

if p.PodIsManagedByPolicy(key) {
p.managedPods = p.managedPods.Delete(key)
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if Delete from the set is thread safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is since it is implemented via map[string]struct{} and delete(map, key) is not thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you like a thread safe implementation or leave it as-is?

pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
Copy link
Member

@aramase aramase left a comment

Choose a reason for hiding this comment

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

Added few more comments!

One thing I noticed is that PreScore now depends on cycle state set by the PreFilter phase. If a user wants to to use the scheduler plugin only for the preScore and score extension points and not configure it for preFilter and filter the plugin will now not work. IMO we should not depend on state being set by a different extension point.

pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/core/policy.go Show resolved Hide resolved
pkg/plugins/placementpolicy/placementpolicy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/placementpolicy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/placementpolicy.go Outdated Show resolved Hide resolved
pkg/plugins/placementpolicy/placementpolicy.go Outdated Show resolved Hide resolved
@aramase aramase changed the title enhancement: refactor to maintain policy state in-memory feat: refactor to maintain policy state in-memory Feb 24, 2022
@cmaclaughlin
Copy link
Contributor Author

One thing I noticed is that PreScore now depends on cycle state set by the PreFilter phase. If a user wants to to use the scheduler plugin only for the preScore and score extension points and not configure it for preFilter and filter the plugin will now not work. IMO we should not depend on state being set by a different extension point.

I've removed that dependency now. For context, I had been looking at the Volume Binding plugin which sets state data in PreFilter and then reads/consumes it in all other extension points (Filter, Score, Reserve and PreBind). Out of curiosity, though, if the user only wants to use PreScore and Score and disables PreFilter and Filter, any policy with a Strict enforcement mode is essentially ignored. Is this the intent?

@helayoty
Copy link
Collaborator

@aramase what is the status of the PR? Can we merge it soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updates to scheduler plugin logic
3 participants