Skip to content

Commit 1fb5099

Browse files
committed
UPSTREAM: 131361: Wait for resource quota status to be populated
1 parent cf20d36 commit 1fb5099

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/e2e/node/pod_resize.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/apimachinery/pkg/api/resource"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/types"
29+
clientset "k8s.io/client-go/kubernetes"
2930
helpers "k8s.io/component-helpers/resource"
3031
resourceapi "k8s.io/kubernetes/pkg/api/v1/resource"
3132
"k8s.io/kubernetes/pkg/features"
@@ -64,6 +65,12 @@ func doPodResizeAdmissionPluginsTests() {
6465
ginkgo.By("Creating a ResourceQuota")
6566
_, rqErr := f.ClientSet.CoreV1().ResourceQuotas(f.Namespace.Name).Create(ctx, &resourceQuota, metav1.CreateOptions{})
6667
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+
6774
},
6875
wantMemoryError: "exceeded quota: resize-resource-quota, requested: memory=350Mi, used: memory=700Mi, limited: memory=800Mi",
6976
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
453460
})
454461
doPodResizeAdmissionPluginsTests()
455462
})
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

Comments
 (0)