Skip to content

Commit

Permalink
scheduler: ElasticQuota runtime is no longer calculated when not need…
Browse files Browse the repository at this point in the history
…ed (koordinator-sh#1855)

Signed-off-by: Joseph <joseph.t.lee@outlook.com>
  • Loading branch information
eahydra committed Feb 26, 2024
1 parent bcee742 commit 15ba039
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
14 changes: 4 additions & 10 deletions pkg/scheduler/plugins/elasticquota/core/group_quota_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ func (gqm *GroupQuotaManager) RefreshRuntime(quotaName string) v1.ResourceList {
gqm.hierarchyUpdateLock.RLock()
defer gqm.hierarchyUpdateLock.RUnlock()

return gqm.RefreshRuntimeNoLock(quotaName)
return gqm.refreshRuntimeNoLock(quotaName)
}

func (gqm *GroupQuotaManager) RefreshRuntimeNoLock(quotaName string) v1.ResourceList {
func (gqm *GroupQuotaManager) refreshRuntimeNoLock(quotaName string) v1.ResourceList {
quotaInfo := gqm.getQuotaInfoByNameNoLock(quotaName)
if quotaInfo == nil {
return nil
Expand Down Expand Up @@ -705,10 +705,7 @@ func (gqm *GroupQuotaManager) GetQuotaSummary(quotaName string, includePods bool
return nil, false
}

quotaSummary := quotaInfo.GetQuotaSummary(includePods)
runtime := gqm.RefreshRuntimeNoLock(quotaName)
quotaSummary.Runtime = runtime.DeepCopy()
quotaSummary.Tree = gqm.treeID
quotaSummary := quotaInfo.GetQuotaSummary(gqm.treeID, includePods)
return quotaSummary, true
}

Expand All @@ -722,10 +719,7 @@ func (gqm *GroupQuotaManager) GetQuotaSummaries(includePods bool) map[string]*Qu
if quotaName == extension.RootQuotaName {
continue
}
quotaSummary := quotaInfo.GetQuotaSummary(includePods)
runtime := gqm.RefreshRuntimeNoLock(quotaName)
quotaSummary.Runtime = runtime.DeepCopy()
quotaSummary.Tree = gqm.treeID
quotaSummary := quotaInfo.GetQuotaSummary(gqm.treeID, includePods)
result[quotaName] = quotaSummary
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/scheduler/plugins/elasticquota/core/quota_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (qi *QuotaInfo) DeepCopy() *QuotaInfo {
return quotaInfo
}

func (qi *QuotaInfo) GetQuotaSummary(includePods bool) *QuotaInfoSummary {
func (qi *QuotaInfo) GetQuotaSummary(treeID string, includePods bool) *QuotaInfoSummary {
qi.lock.Lock()
defer qi.lock.Unlock()

Expand All @@ -149,6 +149,7 @@ func (qi *QuotaInfo) GetQuotaSummary(includePods bool) *QuotaInfoSummary {
quotaInfoSummary.IsParent = qi.IsParent
quotaInfoSummary.RuntimeVersion = qi.RuntimeVersion
quotaInfoSummary.AllowLentResource = qi.AllowLentResource
quotaInfoSummary.Tree = treeID
quotaInfoSummary.Max = qi.CalculateInfo.Max.DeepCopy()
quotaInfoSummary.Min = qi.CalculateInfo.Min.DeepCopy()
quotaInfoSummary.AutoScaleMin = qi.CalculateInfo.AutoScaleMin.DeepCopy()
Expand Down
4 changes: 3 additions & 1 deletion pkg/scheduler/plugins/elasticquota/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ func (g *Plugin) PreFilter(ctx context.Context, cycleState *framework.CycleState
if mgr == nil {
return nil, framework.NewStatus(framework.Error, fmt.Sprintf("Could not find the specified ElasticQuotaManager for quota: %v, tree: %v", quotaName, treeID))
}
mgr.RefreshRuntime(quotaName)
if g.pluginArgs.EnableRuntimeQuota {
mgr.RefreshRuntime(quotaName)
}
quotaInfo := mgr.GetQuotaInfoByName(quotaName)
if quotaInfo == nil {
return nil, framework.NewStatus(framework.Error, fmt.Sprintf("Could not find the specified ElasticQuota"))
Expand Down
19 changes: 11 additions & 8 deletions pkg/scheduler/plugins/elasticquota/plugin_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
assert.NotNil(t, p)
assert.Nil(t, err)

eq := p.(*Plugin)
plugin := p.(*Plugin)
quota := CreateQuota2("test1", "", 100, 100, 10, 10, 20, 20, false, "")
eq.OnQuotaAdd(quota)
plugin.OnQuotaAdd(quota)

node := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -53,7 +53,7 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
Allocatable: createResourceList(1000, 1000),
},
}
eq.OnNodeAdd(node)
plugin.OnNodeAdd(node)

podToCreate := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -74,7 +74,10 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
},
}
podToCreate.Spec.NodeName = "n1"
eq.OnPodAdd(podToCreate)
plugin.OnPodAdd(podToCreate)

mgr := plugin.GetGroupQuotaManagerForQuota(quota.Name)
mgr.RefreshRuntime(quota.Name)

quotaExpected := core.QuotaInfoSummary{
Name: "test1",
Expand All @@ -98,7 +101,7 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
}
{
engine := gin.Default()
eq.RegisterEndpoints(engine.Group("/"))
plugin.RegisterEndpoints(engine.Group("/"))
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/quotas/test1?includePods=true", nil)
engine.ServeHTTP(w, req)
Expand All @@ -125,7 +128,7 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
}
{
engine := gin.Default()
eq.RegisterEndpoints(engine.Group("/"))
plugin.RegisterEndpoints(engine.Group("/"))
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/quotas?includePods=true", nil)
engine.ServeHTTP(w, req)
Expand Down Expand Up @@ -155,10 +158,10 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
defer utilfeature.SetFeatureGateDuringTest(t, k8sfeature.DefaultMutableFeatureGate, koordfeatures.MultiQuotaTree, true)()

// add root quota
eq.addRootQuota("tree1-root", "", 20, 20, 10, 10, 30, 30, false, "", "tree1")
plugin.addRootQuota("tree1-root", "", 20, 20, 10, 10, 30, 30, false, "", "tree1")

engine := gin.Default()
eq.RegisterEndpoints(engine.Group("/"))
plugin.RegisterEndpoints(engine.Group("/"))
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/quotas?tree=tree1&includePods=true", nil)
engine.ServeHTTP(w, req)
Expand Down

0 comments on commit 15ba039

Please sign in to comment.