diff --git a/pkg/controller/resourcequota/resource_quota_controller.go b/pkg/controller/resourcequota/resource_quota_controller.go index 7314209b39a..d111b7e37d8 100644 --- a/pkg/controller/resourcequota/resource_quota_controller.go +++ b/pkg/controller/resourcequota/resource_quota_controller.go @@ -285,7 +285,14 @@ func (rq *ResourceQuotaController) syncResourceQuota(resourceQuota api.ResourceQ // replenishQuota is a replenishment function invoked by a controller to notify that a quota should be recalculated func (rq *ResourceQuotaController) replenishQuota(groupKind unversioned.GroupKind, namespace string, object runtime.Object) { - // TODO: make this support targeted replenishment to a specific kind, right now it does a full replenish + // check if the quota controller can evaluate this kind, if not, ignore it altogether... + evaluators := rq.registry.Evaluators() + evaluator, found := evaluators[groupKind] + if !found { + return + } + + // check if this namespace even has a quota... indexKey := &api.ResourceQuota{} indexKey.Namespace = namespace resourceQuotas, err := rq.rqIndexer.Index("namespace", indexKey) @@ -295,8 +302,15 @@ func (rq *ResourceQuotaController) replenishQuota(groupKind unversioned.GroupKin if len(resourceQuotas) == 0 { return } + + // only queue those quotas that are tracking a resource associated with this kind. + matchedResources := evaluator.MatchesResources() for i := range resourceQuotas { resourceQuota := resourceQuotas[i].(*api.ResourceQuota) - rq.enqueueResourceQuota(resourceQuota) + resourceQuotaResources := quota.ResourceNames(resourceQuota.Status.Hard) + if len(quota.Intersection(matchedResources, resourceQuotaResources)) > 0 { + // TODO: make this support targeted replenishment to a specific kind, right now it does a full recalc on that quota. + rq.enqueueResourceQuota(resourceQuota) + } } }