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

koord-scheduler: fix root quota when deleted #1678

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pkg/scheduler/plugins/elasticquota/quota_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (g *Plugin) OnQuotaAdd(obj interface{}) {
treeID := mgr.GetTreeID()
g.updateQuotaToTreeMap(quota.Name, treeID)

g.handlerQuotaWhenRoot(quota, mgr)
g.handlerQuotaWhenRoot(quota, mgr, false)

oldQuotaInfo := mgr.GetQuotaInfoByName(quota.Name)
if oldQuotaInfo != nil && quota.Name != extension.DefaultQuotaName && quota.Name != extension.SystemQuotaName {
Expand Down Expand Up @@ -76,7 +76,7 @@ func (g *Plugin) OnQuotaUpdate(oldObj, newObj interface{}) {
treeID := mgr.GetTreeID()
g.updateQuotaToTreeMap(newQuota.Name, treeID)

g.handlerQuotaWhenRoot(newQuota, mgr)
g.handlerQuotaWhenRoot(newQuota, mgr, false)

err := mgr.UpdateQuota(newQuota, false)
if err != nil {
Expand Down Expand Up @@ -106,7 +106,9 @@ func (g *Plugin) OnQuotaDelete(obj interface{}) {
klog.Errorf("OnQuotaDeleteFunc failed: %v.%v, tree: %v, err: %v", quota.Namespace, quota.Name, treeID, err)
return
}
// TODO: when quota is root. we should clean the manager

g.handlerQuotaWhenRoot(quota, mgr, true)

klog.V(5).Infof("OnQuotaDeleteFunc failed: %v.%v, tree: %v", quota.Namespace, quota.Name, treeID)

}
Expand Down Expand Up @@ -234,15 +236,22 @@ func (g *Plugin) deleteQuotaToTreeMap(quota string) {
}

// handlerQuotaForRoot will update quota tree total resource when the quota is root quota and enable MultiQuotaTree
func (g *Plugin) handlerQuotaWhenRoot(quota *schedulerv1alpha1.ElasticQuota, mgr *core.GroupQuotaManager) {
func (g *Plugin) handlerQuotaWhenRoot(quota *schedulerv1alpha1.ElasticQuota, mgr *core.GroupQuotaManager, isDelete bool) {
if !k8sfeature.DefaultFeatureGate.Enabled(koordfeatures.MultiQuotaTree) ||
quota.Labels[extension.LabelQuotaIsRoot] != "true" || mgr.GetTreeID() == "" {
return
}

totalResource, ok := getTotalResource(quota)
if ok {
delta := mgr.SetTotalResourceForTree(totalResource)
var delta corev1.ResourceList
if isDelete {
delta = quotav1.Subtract(corev1.ResourceList{}, totalResource)
delete(g.groupQuotaManagersForQuotaTree, mgr.GetTreeID())
} else {
delta = mgr.SetTotalResourceForTree(totalResource)
}

if !quotav1.IsZero(delta) {
// decrease the default GroupQuotaManager resource
deltaForDefault := quotav1.Subtract(corev1.ResourceList{}, delta)
Expand Down
3 changes: 3 additions & 0 deletions pkg/scheduler/plugins/elasticquota/quota_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,7 @@ func TestPlugin_HandlerQuotaWhenRoot(t *testing.T) {

assert.True(t, quotav1.Equals(createResourceList(250, 2500), gqmA.GetClusterTotalResource()))
assert.True(t, quotav1.Equals(createResourceList(50, 500), plugin.groupQuotaManager.GetClusterTotalResource()))

plugin.OnQuotaDelete(copy)
assert.True(t, quotav1.Equals(createResourceList(300, 3000), plugin.groupQuotaManager.GetClusterTotalResource()))
}