mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Improve quota controller performance by eliminating unneeded list calls
This commit is contained in:
parent
d08a722647
commit
f2f65fe9c4
@ -270,6 +270,10 @@ func (rq *ResourceQuotaController) syncResourceQuota(resourceQuota api.ResourceQ
|
|||||||
newUsage := api.ResourceList{}
|
newUsage := api.ResourceList{}
|
||||||
usageStatsOptions := quota.UsageStatsOptions{Namespace: resourceQuota.Namespace, Scopes: resourceQuota.Spec.Scopes}
|
usageStatsOptions := quota.UsageStatsOptions{Namespace: resourceQuota.Namespace, Scopes: resourceQuota.Spec.Scopes}
|
||||||
for _, evaluator := range evaluators {
|
for _, evaluator := range evaluators {
|
||||||
|
// only trigger the evaluator if it matches a resource in the quota, otherwise, skip calculating anything
|
||||||
|
if intersection := quota.Intersection(evaluator.MatchesResources(), matchedResources); len(intersection) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
stats, err := evaluator.UsageStats(usageStatsOptions)
|
stats, err := evaluator.UsageStats(usageStatsOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -122,12 +122,7 @@ func TestSyncResourceQuota(t *testing.T) {
|
|||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
expectedActionSet := sets.NewString(
|
expectedActionSet := sets.NewString(
|
||||||
strings.Join([]string{"list", "replicationcontrollers", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "services", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "pods", ""}, "-"),
|
strings.Join([]string{"list", "pods", ""}, "-"),
|
||||||
strings.Join([]string{"list", "resourcequotas", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "secrets", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "persistentvolumeclaims", ""}, "-"),
|
|
||||||
strings.Join([]string{"update", "resourcequotas", "status"}, "-"),
|
strings.Join([]string{"update", "resourcequotas", "status"}, "-"),
|
||||||
)
|
)
|
||||||
actionSet := sets.NewString()
|
actionSet := sets.NewString()
|
||||||
@ -213,12 +208,7 @@ func TestSyncResourceQuotaSpecChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedActionSet := sets.NewString(
|
expectedActionSet := sets.NewString(
|
||||||
strings.Join([]string{"list", "replicationcontrollers", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "services", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "pods", ""}, "-"),
|
strings.Join([]string{"list", "pods", ""}, "-"),
|
||||||
strings.Join([]string{"list", "resourcequotas", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "secrets", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "persistentvolumeclaims", ""}, "-"),
|
|
||||||
strings.Join([]string{"update", "resourcequotas", "status"}, "-"),
|
strings.Join([]string{"update", "resourcequotas", "status"}, "-"),
|
||||||
)
|
)
|
||||||
actionSet := sets.NewString()
|
actionSet := sets.NewString()
|
||||||
@ -293,12 +283,7 @@ func TestSyncResourceQuotaNoChange(t *testing.T) {
|
|||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
expectedActionSet := sets.NewString(
|
expectedActionSet := sets.NewString(
|
||||||
strings.Join([]string{"list", "replicationcontrollers", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "services", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "pods", ""}, "-"),
|
strings.Join([]string{"list", "pods", ""}, "-"),
|
||||||
strings.Join([]string{"list", "resourcequotas", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "secrets", ""}, "-"),
|
|
||||||
strings.Join([]string{"list", "persistentvolumeclaims", ""}, "-"),
|
|
||||||
)
|
)
|
||||||
actionSet := sets.NewString()
|
actionSet := sets.NewString()
|
||||||
for _, action := range kubeClient.Actions() {
|
for _, action := range kubeClient.Actions() {
|
||||||
|
Loading…
Reference in New Issue
Block a user