mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-25 11:31:44 +00:00
ResourceQuota should ignore subresources
This commit is contained in:
parent
9a747cde38
commit
795e444ba3
@ -80,6 +80,10 @@ var resourceToResourceName = map[string]api.ResourceName{
|
||||
}
|
||||
|
||||
func (q *quota) Admit(a admission.Attributes) (err error) {
|
||||
if a.GetSubresource() != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if a.GetOperation() == "DELETE" {
|
||||
return nil
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
|
||||
)
|
||||
|
||||
@ -47,6 +48,41 @@ func TestAdmissionIgnoresDelete(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdmissionIgnoresSubresources(t *testing.T) {
|
||||
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{"namespace": cache.MetaNamespaceIndexFunc})
|
||||
handler := createResourceQuota(&testclient.Fake{}, indexer)
|
||||
|
||||
quota := &api.ResourceQuota{}
|
||||
quota.Name = "quota"
|
||||
quota.Namespace = "test"
|
||||
quota.Status = api.ResourceQuotaStatus{
|
||||
Hard: api.ResourceList{},
|
||||
Used: api.ResourceList{},
|
||||
}
|
||||
quota.Status.Hard[api.ResourceMemory] = resource.MustParse("2Gi")
|
||||
quota.Status.Used[api.ResourceMemory] = resource.MustParse("1Gi")
|
||||
|
||||
indexer.Add(quota)
|
||||
|
||||
newPod := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: quota.Namespace},
|
||||
Spec: api.PodSpec{
|
||||
Volumes: []api.Volume{{Name: "vol"}},
|
||||
Containers: []api.Container{{Name: "ctr", Image: "image", Resources: getResourceRequirements("100m", "2Gi")}},
|
||||
}}
|
||||
|
||||
err := handler.Admit(admission.NewAttributesRecord(newPod, "Pod", newPod.Namespace, "pods", "", admission.Create, nil))
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error because the pod exceeded allowed quota")
|
||||
}
|
||||
|
||||
err = handler.Admit(admission.NewAttributesRecord(newPod, "Pod", newPod.Namespace, "pods", "subresource", admission.Create, nil))
|
||||
if err != nil {
|
||||
t.Errorf("Did not expect an error because the action went to a subresource: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIncrementUsagePods(t *testing.T) {
|
||||
namespace := "default"
|
||||
client := testclient.NewSimpleFake(&api.PodList{
|
||||
|
Loading…
Reference in New Issue
Block a user