Skip to content

Commit

Permalink
scheduler: quota debug api support multi tree (#1706)
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 Oct 12, 2023
1 parent 58850b4 commit beefb7c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ func (gqm *GroupQuotaManager) GetQuotaSummaries() map[string]*QuotaInfoSummary {
quotaSummary := quotaInfo.GetQuotaSummary()
runtime := gqm.RefreshRuntimeNoLock(quotaName)
quotaSummary.Runtime = runtime.DeepCopy()
quotaSummary.Tree = gqm.treeID
result[quotaName] = quotaSummary
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/scheduler/plugins/elasticquota/core/quota_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func (qi *QuotaInfo) GetQuotaSummary() *QuotaInfoSummary {
quotaInfoSummary.SharedWeight = qi.CalculateInfo.SharedWeight.DeepCopy()
quotaInfoSummary.Runtime = qi.CalculateInfo.Runtime.DeepCopy()
quotaInfoSummary.ChildRequest = qi.CalculateInfo.ChildRequest.DeepCopy()
quotaInfoSummary.Allocated = qi.CalculateInfo.Allocated.DeepCopy()
quotaInfoSummary.Guaranteed = qi.CalculateInfo.Guaranteed.DeepCopy()

for podName, podInfo := range qi.PodCache {
quotaInfoSummary.PodCache[podName] = &SimplePodInfo{
Expand Down
3 changes: 3 additions & 0 deletions pkg/scheduler/plugins/elasticquota/core/quota_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type QuotaInfoSummary struct {
IsParent bool `json:"isParent"`
RuntimeVersion int64 `json:"runtimeVersion"`
AllowLentResource bool `json:"allowLentResource"`
Tree string `json:"tree"`

Max v1.ResourceList `json:"max"`
Min v1.ResourceList `json:"min"`
Expand All @@ -41,6 +42,8 @@ type QuotaInfoSummary struct {
SharedWeight v1.ResourceList `json:"sharedWeight"`
Runtime v1.ResourceList `json:"runtime"`
ChildRequest v1.ResourceList `json:"childRequest"`
Allocated v1.ResourceList `json:"allocated"`
Guaranteed v1.ResourceList `json:"guaranteed"`

PodCache map[string]*SimplePodInfo `json:"podCache"`
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/scheduler/plugins/elasticquota/plugin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func (g *Plugin) RegisterEndpoints(group *gin.RouterGroup) {
c.JSON(http.StatusOK, quotaSummary)
})
group.GET("/quotas", func(c *gin.Context) {
quotaSummaries := g.GetQuotaSummaries()
tree := c.Query("tree")
quotaSummaries := g.GetQuotaSummaries(tree)
c.JSON(http.StatusOK, quotaSummaries)
})
}
29 changes: 29 additions & 0 deletions pkg/scheduler/plugins/elasticquota/plugin_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
quotav1 "k8s.io/apiserver/pkg/quota/v1"
k8sfeature "k8s.io/apiserver/pkg/util/feature"

"github.com/koordinator-sh/koordinator/apis/extension"
koordfeatures "github.com/koordinator-sh/koordinator/pkg/features"
"github.com/koordinator-sh/koordinator/pkg/scheduler/plugins/elasticquota/core"
utilfeature "github.com/koordinator-sh/koordinator/pkg/util/feature"
)

func TestEndpointsQueryQuotaInfo(t *testing.T) {
Expand Down Expand Up @@ -148,4 +151,30 @@ func TestEndpointsQueryQuotaInfo(t *testing.T) {
assert.Equal(t, quotaSummary.PodCache[podToCreate.Namespace+"/"+podToCreate.Name].IsAssigned, true)
assert.True(t, quotav1.Equals(quotaSummary.PodCache[podToCreate.Namespace+"/"+podToCreate.Name].Resource, createResourceList(33, 33)))
}
{
defer utilfeature.SetFeatureGateDuringTest(t, k8sfeature.DefaultMutableFeatureGate, koordfeatures.MultiQuotaTree, true)()

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

engine := gin.Default()
eq.RegisterEndpoints(engine.Group("/"))
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/quotas?tree=tree1", nil)
engine.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Result().StatusCode)
quotaSummaries := make(map[string]*core.QuotaInfoSummary)
err = json.Unmarshal([]byte(w.Body.String()), &quotaSummaries)
assert.NoError(t, err)

_, ok := quotaSummaries["test1"]
assert.False(t, ok)

quotaSummary, ok := quotaSummaries["tree1-root"]
assert.True(t, ok)
assert.True(t, quotav1.Equals(quotaSummary.Max, createResourceList(20, 20)))
assert.True(t, quotav1.Equals(quotaSummary.Min, createResourceList(10, 10)))
assert.True(t, quotav1.Equals(quotaSummary.AutoScaleMin, createResourceList(10, 10)))
assert.True(t, quotav1.Equals(quotaSummary.SharedWeight, createResourceList(30, 30)))
}
}
13 changes: 11 additions & 2 deletions pkg/scheduler/plugins/elasticquota/quota_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ func (g *Plugin) GetQuotaSummary(quotaName string) (*core.QuotaInfoSummary, bool
return mgr.GetQuotaSummary(quotaName)
}

func (g *Plugin) GetQuotaSummaries() map[string]*core.QuotaInfoSummary {
summaries := g.groupQuotaManager.GetQuotaSummaries()
func (g *Plugin) GetQuotaSummaries(tree string) map[string]*core.QuotaInfoSummary {
summaries := make(map[string]*core.QuotaInfoSummary)

managers := g.ListGroupQuotaManagersForQuotaTree()
for _, mgr := range managers {
if tree != "" && mgr.GetTreeID() != tree {
continue
}
for quotaName, summary := range mgr.GetQuotaSummaries() {
// quota tree root quota is virtual
if quotaName == extension.RootQuotaName {
Expand All @@ -133,6 +136,12 @@ func (g *Plugin) GetQuotaSummaries() map[string]*core.QuotaInfoSummary {
}
}

if g.groupQuotaManager.GetTreeID() == tree {
for quotaName, summary := range g.groupQuotaManager.GetQuotaSummaries() {
summaries[quotaName] = summary
}
}

return summaries
}

Expand Down

0 comments on commit beefb7c

Please sign in to comment.