diff --git a/pkg/scheduler/plugins/elasticquota/core/group_quota_manager.go b/pkg/scheduler/plugins/elasticquota/core/group_quota_manager.go index ef30d58fa9..5310e746f8 100644 --- a/pkg/scheduler/plugins/elasticquota/core/group_quota_manager.go +++ b/pkg/scheduler/plugins/elasticquota/core/group_quota_manager.go @@ -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 @@ -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 } @@ -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 } diff --git a/pkg/scheduler/plugins/elasticquota/core/quota_info.go b/pkg/scheduler/plugins/elasticquota/core/quota_info.go index d468c1ed6d..da4ed4ec06 100644 --- a/pkg/scheduler/plugins/elasticquota/core/quota_info.go +++ b/pkg/scheduler/plugins/elasticquota/core/quota_info.go @@ -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() @@ -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() diff --git a/pkg/scheduler/plugins/elasticquota/plugin.go b/pkg/scheduler/plugins/elasticquota/plugin.go index 235c11c280..5502debdb1 100644 --- a/pkg/scheduler/plugins/elasticquota/plugin.go +++ b/pkg/scheduler/plugins/elasticquota/plugin.go @@ -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")) diff --git a/pkg/scheduler/plugins/elasticquota/plugin_service_test.go b/pkg/scheduler/plugins/elasticquota/plugin_service_test.go index c70f1904ae..d4a5c068d2 100644 --- a/pkg/scheduler/plugins/elasticquota/plugin_service_test.go +++ b/pkg/scheduler/plugins/elasticquota/plugin_service_test.go @@ -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{ @@ -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{ @@ -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", @@ -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) @@ -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) @@ -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)