Skip to content

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

Open
cmaclaughlin wants to merge 25 commits intoAzure:mainfrom
cmaclaughlin:inmemory-policy-state
Open

feat: refactor to maintain policy state in-memory#49
cmaclaughlin wants to merge 25 commits intoAzure:mainfrom
cmaclaughlin:inmemory-policy-state

Conversation

@cmaclaughlin
Copy link
Copy Markdown
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
Copy Markdown
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!

Comment thread pkg/plugins/placementpolicy/core/core.go Outdated
Comment thread pkg/plugins/placementpolicy/placementpolicy.go Outdated
@cmaclaughlin cmaclaughlin requested a review from helayoty January 24, 2022 21:41
@helayoty helayoty linked an issue Feb 7, 2022 that may be closed by this pull request
Copy link
Copy Markdown
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.

Comment thread pkg/plugins/placementpolicy/core/core.go Outdated
Comment thread pkg/plugins/placementpolicy/core/core.go Outdated
Comment thread pkg/plugins/placementpolicy/core/core.go Outdated
Comment thread pkg/plugins/placementpolicy/core/core.go Outdated
Comment thread pkg/plugins/placementpolicy/core/core.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
p.qualifiedPods = p.qualifiedPods.Delete(key)

if p.PodIsManagedByPolicy(key) {
p.managedPods = p.managedPods.Delete(key)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
@cmaclaughlin cmaclaughlin requested a review from aramase February 8, 2022 20:28
Copy link
Copy Markdown
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.

Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go Outdated
Comment thread pkg/plugins/placementpolicy/core/policy.go
Comment thread pkg/plugins/placementpolicy/placementpolicy.go
Comment thread pkg/plugins/placementpolicy/placementpolicy.go Outdated
Comment thread pkg/plugins/placementpolicy/placementpolicy.go Outdated
Comment thread pkg/plugins/placementpolicy/placementpolicy.go Outdated
Comment thread pkg/plugins/placementpolicy/placementpolicy.go Outdated
@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 and others added 8 commits February 24, 2022 18:07
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Co-authored-by: Anish Ramasekar <anish.ramasekar@gmail.com>
@cmaclaughlin
Copy link
Copy Markdown
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?

@cmaclaughlin cmaclaughlin requested a review from aramase February 25, 2022 21:43
@helayoty
Copy link
Copy Markdown
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