@@ -26,6 +26,7 @@ import (
26
26
"k8s.io/apimachinery/pkg/api/resource"
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
28
"k8s.io/apimachinery/pkg/types"
29
+ clientset "k8s.io/client-go/kubernetes"
29
30
helpers "k8s.io/component-helpers/resource"
30
31
resourceapi "k8s.io/kubernetes/pkg/api/v1/resource"
31
32
"k8s.io/kubernetes/pkg/features"
@@ -64,6 +65,12 @@ func doPodResizeAdmissionPluginsTests() {
64
65
ginkgo .By ("Creating a ResourceQuota" )
65
66
_ , rqErr := f .ClientSet .CoreV1 ().ResourceQuotas (f .Namespace .Name ).Create (ctx , & resourceQuota , metav1.CreateOptions {})
66
67
framework .ExpectNoError (rqErr , "failed to create resource quota" )
68
+ // pod creation using this quota will fail until the quota status is populated, so we need to wait to
69
+ // prevent races with the resourcequota controller
70
+ ginkgo .By ("Waiting for ResourceQuota status to populate" )
71
+ quotaStatusErr := waitForResourceQuota (ctx , f .ClientSet , f .Namespace .Name , resourceQuota .Name )
72
+ framework .ExpectNoError (quotaStatusErr , "resource quota status failed to populate" )
73
+
67
74
},
68
75
wantMemoryError : "exceeded quota: resize-resource-quota, requested: memory=350Mi, used: memory=700Mi, limited: memory=800Mi" ,
69
76
wantCPUError : "exceeded quota: resize-resource-quota, requested: cpu=200m, used: cpu=700m, limited: cpu=800m" ,
@@ -453,3 +460,13 @@ var _ = SIGDescribe("Pod InPlace Resize Container", framework.WithFeatureGate(fe
453
460
})
454
461
doPodResizeAdmissionPluginsTests ()
455
462
})
463
+
464
+ func waitForResourceQuota (ctx context.Context , c clientset.Interface , ns , quotaName string ) error {
465
+ return framework .Gomega ().Eventually (ctx , framework .HandleRetry (func (ctx context.Context ) (v1.ResourceList , error ) {
466
+ quota , err := c .CoreV1 ().ResourceQuotas (ns ).Get (ctx , quotaName , metav1.GetOptions {})
467
+ if err != nil {
468
+ return nil , err
469
+ }
470
+ return quota .Status .Used , nil
471
+ })).WithTimeout (framework .PollShortTimeout ).ShouldNot (gomega .BeEmpty ())
472
+ }
0 commit comments