mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
enable the quota e2e test
This commit is contained in:
parent
84fc3b3df8
commit
7bfffb40c5
@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
@ -147,72 +148,72 @@ var _ = framework.KubeDescribe("ResourceQuota", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("should create a ResourceQuota and capture the life of an uninitialized pod.", func() {
|
||||
// TODO: uncomment the test when #50344 is merged.
|
||||
// By("Creating a ResourceQuota")
|
||||
// quotaName := "test-quota"
|
||||
// resourceQuota := newTestResourceQuota(quotaName)
|
||||
// resourceQuota, err := createResourceQuota(f.ClientSet, f.Namespace.Name, resourceQuota)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
It("[Feature:Initializers] should create a ResourceQuota and capture the life of an uninitialized pod.", func() {
|
||||
By("Creating a ResourceQuota")
|
||||
quotaName := "test-quota"
|
||||
resourceQuota := newTestResourceQuota(quotaName)
|
||||
resourceQuota, err := createResourceQuota(f.ClientSet, f.Namespace.Name, resourceQuota)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// By("Ensuring resource quota status is calculated")
|
||||
// usedResources := v1.ResourceList{}
|
||||
// usedResources[v1.ResourceQuotas] = resource.MustParse("1")
|
||||
// err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
By("Ensuring resource quota status is calculated")
|
||||
usedResources := v1.ResourceList{}
|
||||
usedResources[v1.ResourceQuotas] = resource.MustParse("1")
|
||||
err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// By("Creating an uninitialized Pod that fits quota")
|
||||
// podName := "test-pod"
|
||||
// requests := v1.ResourceList{}
|
||||
// requests[v1.ResourceCPU] = resource.MustParse("500m")
|
||||
// requests[v1.ResourceMemory] = resource.MustParse("252Mi")
|
||||
// pod := newTestPodForQuota(f, podName, requests, v1.ResourceList{})
|
||||
// pod.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "unhandled"}}}
|
||||
// _, err = f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
|
||||
// // because no one is handling the initializer, server will return a 504 timeout
|
||||
// if err != nil && !errors.IsTimeout(err) {
|
||||
// framework.Failf("expect err to be timeout error, got %v", err)
|
||||
// }
|
||||
// podToUpdate, err := f.ClientSet.Core().Pods(f.Namespace.Name).Get(podName, metav1.GetOptions{})
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
By("Creating an uninitialized Pod that fits quota")
|
||||
podName := "test-pod"
|
||||
requests := v1.ResourceList{}
|
||||
requests[v1.ResourceCPU] = resource.MustParse("500m")
|
||||
requests[v1.ResourceMemory] = resource.MustParse("252Mi")
|
||||
pod := newTestPodForQuota(f, podName, requests, v1.ResourceList{})
|
||||
pod.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "unhandled"}}}
|
||||
_, err = f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
|
||||
// because no one is handling the initializer, server will return a 504 timeout
|
||||
if err != nil && !errors.IsTimeout(err) {
|
||||
framework.Failf("expect err to be timeout error, got %v", err)
|
||||
}
|
||||
podToUpdate, err := f.ClientSet.Core().Pods(f.Namespace.Name).Get(podName, metav1.GetOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// By("Ensuring ResourceQuota status captures the pod usage")
|
||||
// usedResources[v1.ResourceQuotas] = resource.MustParse("1")
|
||||
// usedResources[v1.ResourcePods] = resource.MustParse("1")
|
||||
// usedResources[v1.ResourceCPU] = requests[v1.ResourceCPU]
|
||||
// usedResources[v1.ResourceMemory] = requests[v1.ResourceMemory]
|
||||
// err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
By("Ensuring ResourceQuota status captures the pod usage")
|
||||
usedResources[v1.ResourceQuotas] = resource.MustParse("1")
|
||||
usedResources[v1.ResourcePods] = resource.MustParse("1")
|
||||
usedResources[v1.ResourceCPU] = requests[v1.ResourceCPU]
|
||||
usedResources[v1.ResourceMemory] = requests[v1.ResourceMemory]
|
||||
err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// By("Not allowing an uninitialized pod to be created that exceeds remaining quota")
|
||||
// requests = v1.ResourceList{}
|
||||
// requests[v1.ResourceCPU] = resource.MustParse("600m")
|
||||
// requests[v1.ResourceMemory] = resource.MustParse("100Mi")
|
||||
// pod = newTestPodForQuota(f, "fail-pod", requests, v1.ResourceList{})
|
||||
// pod.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "unhandled"}}}
|
||||
// pod, err = f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
|
||||
// Expect(err).To(HaveOccurred())
|
||||
// fmt.Println("CHAO: err=", err)
|
||||
By("Not allowing an uninitialized pod to be created that exceeds remaining quota")
|
||||
requests = v1.ResourceList{}
|
||||
requests[v1.ResourceCPU] = resource.MustParse("600m")
|
||||
requests[v1.ResourceMemory] = resource.MustParse("100Mi")
|
||||
pod = newTestPodForQuota(f, "fail-pod", requests, v1.ResourceList{})
|
||||
pod.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "unhandled"}}}
|
||||
pod, err = f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
|
||||
Expect(err).To(HaveOccurred())
|
||||
fmt.Println("CHAO: err=", err)
|
||||
|
||||
// By("Ensuring an uninitialized pod can update its resource requirements")
|
||||
// // a pod cannot dynamically update its resource requirements.
|
||||
// requests = v1.ResourceList{}
|
||||
// requests[v1.ResourceCPU] = resource.MustParse("100m")
|
||||
// requests[v1.ResourceMemory] = resource.MustParse("100Mi")
|
||||
// podToUpdate.Spec.Containers[0].Resources.Requests = requests
|
||||
// _, err = f.ClientSet.Core().Pods(f.Namespace.Name).Update(podToUpdate)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
By("Ensuring an uninitialized pod can update its resource requirements")
|
||||
// a pod cannot dynamically update its resource requirements.
|
||||
requests = v1.ResourceList{}
|
||||
requests[v1.ResourceCPU] = resource.MustParse("100m")
|
||||
requests[v1.ResourceMemory] = resource.MustParse("100Mi")
|
||||
podToUpdate.Spec.Containers[0].Resources.Requests = requests
|
||||
_, err = f.ClientSet.Core().Pods(f.Namespace.Name).Update(podToUpdate)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// By("Ensuring attempts to update pod resource requirements did change quota usage")
|
||||
// usedResources[v1.ResourceQuotas] = resource.MustParse("1")
|
||||
// usedResources[v1.ResourcePods] = resource.MustParse("1")
|
||||
// usedResources[v1.ResourceCPU] = requests[v1.ResourceCPU]
|
||||
// usedResources[v1.ResourceMemory] = requests[v1.ResourceMemory]
|
||||
// err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
By("Ensuring attempts to update pod resource requirements did change quota usage")
|
||||
usedResources[v1.ResourceQuotas] = resource.MustParse("1")
|
||||
usedResources[v1.ResourcePods] = resource.MustParse("1")
|
||||
usedResources[v1.ResourceCPU] = requests[v1.ResourceCPU]
|
||||
usedResources[v1.ResourceMemory] = requests[v1.ResourceMemory]
|
||||
err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// TODO: uncomment the test when the replenishment_controller uses the
|
||||
// sharedInformer that list/watches uninitialized objects.
|
||||
// TODO: uncomment the test after 51247 is merged, in which the
|
||||
// replenishment_controller uses the sharedInformer that list/watches
|
||||
// uninitialized objects.
|
||||
// By("Deleting the pod")
|
||||
// err = f.ClientSet.Core().Pods(f.Namespace.Name).Delete(podName, metav1.NewDeleteOptions(0))
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
|
Loading…
Reference in New Issue
Block a user