mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #109683 from ii/create-resourcequota-test
Write List, Patch & DeleteCollection ResourceQuota test - +3 endpoint coverage
This commit is contained in:
		@@ -29,7 +29,10 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/api/resource"
 | 
						"k8s.io/apimachinery/pkg/api/resource"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 | 
						"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 | 
				
			||||||
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/intstr"
 | 
						"k8s.io/apimachinery/pkg/util/intstr"
 | 
				
			||||||
 | 
						utilrand "k8s.io/apimachinery/pkg/util/rand"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	clientset "k8s.io/client-go/kubernetes"
 | 
						clientset "k8s.io/client-go/kubernetes"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/quota/v1/evaluator/core"
 | 
						"k8s.io/kubernetes/pkg/quota/v1/evaluator/core"
 | 
				
			||||||
@@ -915,6 +918,58 @@ var _ = SIGDescribe("ResourceQuota", func() {
 | 
				
			|||||||
			framework.Failf("Expected `not found` error, got: %v", err)
 | 
								framework.Failf("Expected `not found` error, got: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.It("should manage the lifecycle of a ResourceQuota", func() {
 | 
				
			||||||
 | 
							client := f.ClientSet
 | 
				
			||||||
 | 
							ns := f.Namespace.Name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							rqName := "e2e-quota-" + utilrand.String(5)
 | 
				
			||||||
 | 
							label := map[string]string{"e2e-rq-label": rqName}
 | 
				
			||||||
 | 
							labelSelector := labels.SelectorFromSet(label).String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ginkgo.By("Creating a ResourceQuota")
 | 
				
			||||||
 | 
							resourceQuota := &v1.ResourceQuota{
 | 
				
			||||||
 | 
								ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
 | 
									Name:   rqName,
 | 
				
			||||||
 | 
									Labels: label,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								Spec: v1.ResourceQuotaSpec{
 | 
				
			||||||
 | 
									Hard: v1.ResourceList{},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							resourceQuota.Spec.Hard[v1.ResourceCPU] = resource.MustParse("1")
 | 
				
			||||||
 | 
							resourceQuota.Spec.Hard[v1.ResourceMemory] = resource.MustParse("500Mi")
 | 
				
			||||||
 | 
							_, err := createResourceQuota(client, ns, resourceQuota)
 | 
				
			||||||
 | 
							framework.ExpectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ginkgo.By("Getting a ResourceQuota")
 | 
				
			||||||
 | 
							resourceQuotaResult, err := client.CoreV1().ResourceQuotas(ns).Get(context.TODO(), rqName, metav1.GetOptions{})
 | 
				
			||||||
 | 
							framework.ExpectNoError(err)
 | 
				
			||||||
 | 
							framework.ExpectEqual(resourceQuotaResult.Spec.Hard[v1.ResourceCPU], resource.MustParse("1"))
 | 
				
			||||||
 | 
							framework.ExpectEqual(resourceQuotaResult.Spec.Hard[v1.ResourceMemory], resource.MustParse("500Mi"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ginkgo.By("Listing all ResourceQuotas with LabelSelector")
 | 
				
			||||||
 | 
							rq, err := client.CoreV1().ResourceQuotas("").List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector})
 | 
				
			||||||
 | 
							framework.ExpectNoError(err, "Failed to list job. %v", err)
 | 
				
			||||||
 | 
							framework.ExpectEqual(len(rq.Items), 1, "Failed to find ResourceQuotes %v", rqName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ginkgo.By("Patching the ResourceQuota")
 | 
				
			||||||
 | 
							payload := "{\"metadata\":{\"labels\":{\"" + rqName + "\":\"patched\"}},\"spec\":{\"hard\":{ \"memory\":\"750Mi\"}}}"
 | 
				
			||||||
 | 
							patchedResourceQuota, err := client.CoreV1().ResourceQuotas(ns).Patch(context.TODO(), rqName, types.StrategicMergePatchType, []byte(payload), metav1.PatchOptions{})
 | 
				
			||||||
 | 
							framework.ExpectNoError(err, "failed to patch ResourceQuota %s in namespace %s", rqName, ns)
 | 
				
			||||||
 | 
							framework.ExpectEqual(patchedResourceQuota.Labels[rqName], "patched", "Did not find the label for this ResourceQuota. Current labels: %v", patchedResourceQuota.Labels)
 | 
				
			||||||
 | 
							framework.ExpectEqual(*patchedResourceQuota.Spec.Hard.Memory(), resource.MustParse("750Mi"), "Hard memory value for ResourceQuota %q is %s not 750Mi.", patchedResourceQuota.ObjectMeta.Name, patchedResourceQuota.Spec.Hard.Memory().String())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ginkgo.By("Deleting a Collection of ResourceQuotas")
 | 
				
			||||||
 | 
							err = client.CoreV1().ResourceQuotas(ns).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: labelSelector})
 | 
				
			||||||
 | 
							framework.ExpectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ginkgo.By("Verifying the deleted ResourceQuota")
 | 
				
			||||||
 | 
							_, err = client.CoreV1().ResourceQuotas(ns).Get(context.TODO(), rqName, metav1.GetOptions{})
 | 
				
			||||||
 | 
							if !apierrors.IsNotFound(err) {
 | 
				
			||||||
 | 
								framework.Failf("Expected `not found` error, got: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var _ = SIGDescribe("ResourceQuota [Feature:ScopeSelectors]", func() {
 | 
					var _ = SIGDescribe("ResourceQuota [Feature:ScopeSelectors]", func() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user