Skip to content

Commit

Permalink
koord-scheduler: fix root quota when deleted (#1678)
Browse files Browse the repository at this point in the history
Signed-off-by: chuanyun.lcy <[email protected]>
Co-authored-by: chuanyun.lcy <[email protected]>
  • Loading branch information
shaloulcy and chuanyun.lcy authored Sep 22, 2023
1 parent 259fa61 commit 9688137
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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()))
}

0 comments on commit 9688137

Please sign in to comment.