Skip to content

Commit 30f8f3d

Browse files
authored
Merge pull request kubernetes#131361 from jkyros/fix-inplace-test-wait-quota-status
[FG:InPlacePodVerticalScaling] deflake - wait for resourceQuota status to be populated
2 parents b2e72e6 + 00908ce commit 30f8f3d

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"
@@ -65,6 +66,12 @@ func doPodResizeAdmissionPluginsTests() {
6566
ginkgo.By("Creating a ResourceQuota")
6667
_, rqErr := f.ClientSet.CoreV1().ResourceQuotas(f.Namespace.Name).Create(ctx, &resourceQuota, metav1.CreateOptions{})
6768
framework.ExpectNoError(rqErr, "failed to create resource quota")
69+
// pod creation using this quota will fail until the quota status is populated, so we need to wait to
70+
// prevent races with the resourcequota controller
71+
ginkgo.By("Waiting for ResourceQuota status to populate")
72+
quotaStatusErr := waitForResourceQuota(ctx, f.ClientSet, f.Namespace.Name, resourceQuota.Name)
73+
framework.ExpectNoError(quotaStatusErr, "resource quota status failed to populate")
74+
6875
},
6976
wantMemoryError: "exceeded quota: resize-resource-quota, requested: memory=350Mi, used: memory=700Mi, limited: memory=800Mi",
7077
wantCPUError: "exceeded quota: resize-resource-quota, requested: cpu=200m, used: cpu=700m, limited: cpu=800m",
@@ -454,3 +461,13 @@ var _ = SIGDescribe("Pod InPlace Resize Container", framework.WithFeatureGate(fe
454461
})
455462
doPodResizeAdmissionPluginsTests()
456463
})
464+
465+
func waitForResourceQuota(ctx context.Context, c clientset.Interface, ns, quotaName string) error {
466+
return framework.Gomega().Eventually(ctx, framework.HandleRetry(func(ctx context.Context) (v1.ResourceList, error) {
467+
quota, err := c.CoreV1().ResourceQuotas(ns).Get(ctx, quotaName, metav1.GetOptions{})
468+
if err != nil {
469+
return nil, err
470+
}
471+
return quota.Status.Used, nil
472+
})).WithTimeout(framework.PollShortTimeout).ShouldNot(gomega.BeEmpty())
473+
}

0 commit comments

Comments
 (0)