From 42a89ea81e45bb407bc63e468e1b4fc1e7fec1bf Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 12 Apr 2019 16:23:12 -0400 Subject: [PATCH] Short-circuit quota admission rejection on zero-delta updates --- .../pkg/admission/resourcequota/controller.go | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/plugin/pkg/admission/resourcequota/controller.go b/plugin/pkg/admission/resourcequota/controller.go index 1c109d2713..abefe34b79 100644 --- a/plugin/pkg/admission/resourcequota/controller.go +++ b/plugin/pkg/admission/resourcequota/controller.go @@ -468,29 +468,6 @@ func CheckRequest(quotas []corev1.ResourceQuota, a admission.Attributes, evaluat restrictedResourcesSet.Insert(localRestrictedResourcesSet.List()...) } - // verify that for every resource that had limited by default consumption - // enabled that there was a corresponding quota that covered its use. - // if not, we reject the request. - hasNoCoveringQuota := limitedResourceNamesSet.Difference(restrictedResourcesSet) - if len(hasNoCoveringQuota) > 0 { - return quotas, admission.NewForbidden(a, fmt.Errorf("insufficient quota to consume: %v", strings.Join(hasNoCoveringQuota.List(), ","))) - } - - // verify that for every scope that had limited access enabled - // that there was a corresponding quota that covered it. - // if not, we reject the request. - scopesHasNoCoveringQuota, err := evaluator.UncoveredQuotaScopes(limitedScopes, restrictedScopes) - if err != nil { - return quotas, err - } - if len(scopesHasNoCoveringQuota) > 0 { - return quotas, fmt.Errorf("insufficient quota to match these scopes: %v", scopesHasNoCoveringQuota) - } - - if len(interestingQuotaIndexes) == 0 { - return quotas, nil - } - // Usage of some resources cannot be counted in isolation. For example, when // the resource represents a number of unique references to external // resource. In such a case an evaluator needs to process other objects in @@ -537,6 +514,29 @@ func CheckRequest(quotas []corev1.ResourceQuota, a admission.Attributes, evaluat return quotas, nil } + // verify that for every resource that had limited by default consumption + // enabled that there was a corresponding quota that covered its use. + // if not, we reject the request. + hasNoCoveringQuota := limitedResourceNamesSet.Difference(restrictedResourcesSet) + if len(hasNoCoveringQuota) > 0 { + return quotas, admission.NewForbidden(a, fmt.Errorf("insufficient quota to consume: %v", strings.Join(hasNoCoveringQuota.List(), ","))) + } + + // verify that for every scope that had limited access enabled + // that there was a corresponding quota that covered it. + // if not, we reject the request. + scopesHasNoCoveringQuota, err := evaluator.UncoveredQuotaScopes(limitedScopes, restrictedScopes) + if err != nil { + return quotas, err + } + if len(scopesHasNoCoveringQuota) > 0 { + return quotas, fmt.Errorf("insufficient quota to match these scopes: %v", scopesHasNoCoveringQuota) + } + + if len(interestingQuotaIndexes) == 0 { + return quotas, nil + } + outQuotas, err := copyQuotas(quotas) if err != nil { return nil, err