// KindAndNamespace returns the kind, namespace, and path parts for the request relative to /{kind}/{name}
// APIRequestInfo holds information parsed from the http.Request
typeAPIRequestInfostruct{
// Verb is the kube verb associated with the request, not the http verb. This includes things like list and watch.
Verbstring
APIVersionstring
Namespacestring
// Resource is the name of the resource being requested. This is not the kind. For example: pods
Resourcestring
// Kind is the type of object being manipulated. For example: Pod
Kindstring
// Name is empty for some verbs, but if the request directly indicates a name (not in body content) then this field is filled in.
Namestring
// Parts are the path parts for the request relative to /{resource}/{name}
Parts[]string
}
typeAPIRequestInfoResolverstruct{
apiPrefixesutil.StringSet
restMappermeta.RESTMapper
}
// GetAPIRequestInfo returns the information from the http request. If error is not nil, APIRequestInfo holds the information as best it is known before the failure
returnapierrors.NewForbidden(a.GetKind(),name,fmt.Errorf("Unable to %s %s at this time because there was an error enforcing quota",a.GetOperation(),kind))
returnapierrors.NewForbidden(a.GetResource(),name,fmt.Errorf("Unable to %s %s at this time because there was an error enforcing quota",a.GetOperation(),resource))
returnapierrors.NewForbidden(a.GetKind(),name,fmt.Errorf("Unable to %s %s at this time because there was an error enforcing quota",a.GetOperation(),a.GetKind()))
returnapierrors.NewForbidden(a.GetResource(),name,fmt.Errorf("Unable to %s %s at this time because there was an error enforcing quota",a.GetOperation(),a.GetResource()))
returnfalse,apierrors.NewForbidden(kind,name,fmt.Errorf("Quota usage stats are not yet known, unable to admit resource until an accurate count is completed."))
returnfalse,apierrors.NewForbidden(a.GetResource(),name,fmt.Errorf("Quota usage stats are not yet known, unable to admit resource until an accurate count is completed."))
}
}
ifused.Value()>=hard.Value(){
ifused.Value()>=hard.Value(){
returnfalse,apierrors.NewForbidden(kind,name,fmt.Errorf("Limited to %s %s",hard.String(),kind))
returnfalse,apierrors.NewForbidden(a.GetResource(),name,fmt.Errorf("Limited to %s %s",hard.String(),a.GetResource()))
@@ -150,10 +150,10 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
...
@@ -150,10 +150,10 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
ifhardMemFound{
ifhardMemFound{
used,usedFound:=status.Used[api.ResourceMemory]
used,usedFound:=status.Used[api.ResourceMemory]
if!usedFound{
if!usedFound{
returnfalse,apierrors.NewForbidden(kind,name,fmt.Errorf("Quota usage stats are not yet known, unable to admit resource until an accurate count is completed."))
returnfalse,apierrors.NewForbidden(resourceName,name,fmt.Errorf("Quota usage stats are not yet known, unable to admit resource until an accurate count is completed."))
@@ -163,10 +163,10 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
...
@@ -163,10 +163,10 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
ifhardCPUFound{
ifhardCPUFound{
used,usedFound:=status.Used[api.ResourceCPU]
used,usedFound:=status.Used[api.ResourceCPU]
if!usedFound{
if!usedFound{
returnfalse,apierrors.NewForbidden(kind,name,fmt.Errorf("Quota usage stats are not yet known, unable to admit resource until an accurate count is completed."))
returnfalse,apierrors.NewForbidden(resourceName,name,fmt.Errorf("Quota usage stats are not yet known, unable to admit resource until an accurate count is completed."))