mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-01-28 02:19:27 +00:00
Wait for resource quota status to be populated
Trying to create a pod using a resourcequota whose status has not been populated will result in api admission rejecting it with a 403 Forbidden. The pod resize tests do not wait/check to make sure the resourcequota status is populated before trying to use the quota when creating a pod, so in scenarious where either the test runs too fast, or the resourcequota controller is too slow, the tests will fail. This just makes the test wait up to a minute for the quota status to populate. The status generation timing/logic gets tested separately in test/e2e/apimachinery/resource_quota.go, and it waits a minute, so we wait a minute, but in practice it takes at worst seconds.
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
helpers "k8s.io/component-helpers/resource"
|
||||
resourceapi "k8s.io/kubernetes/pkg/api/v1/resource"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
@@ -64,6 +65,12 @@ func doPodResizeAdmissionPluginsTests() {
|
||||
ginkgo.By("Creating a ResourceQuota")
|
||||
_, rqErr := f.ClientSet.CoreV1().ResourceQuotas(f.Namespace.Name).Create(ctx, &resourceQuota, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(rqErr, "failed to create resource quota")
|
||||
// pod creation using this quota will fail until the quota status is populated, so we need to wait to
|
||||
// prevent races with the resourcequota controller
|
||||
ginkgo.By("Waiting for ResourceQuota status to populate")
|
||||
quotaStatusErr := waitForResourceQuota(ctx, f.ClientSet, f.Namespace.Name, resourceQuota.Name)
|
||||
framework.ExpectNoError(quotaStatusErr, "resource quota status failed to populate")
|
||||
|
||||
},
|
||||
wantMemoryError: "exceeded quota: resize-resource-quota, requested: memory=350Mi, used: memory=700Mi, limited: memory=800Mi",
|
||||
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
|
||||
})
|
||||
doPodResizeAdmissionPluginsTests()
|
||||
})
|
||||
|
||||
func waitForResourceQuota(ctx context.Context, c clientset.Interface, ns, quotaName string) error {
|
||||
return framework.Gomega().Eventually(ctx, framework.HandleRetry(func(ctx context.Context) (v1.ResourceList, error) {
|
||||
quota, err := c.CoreV1().ResourceQuotas(ns).Get(ctx, quotaName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return quota.Status.Used, nil
|
||||
})).WithTimeout(framework.PollShortTimeout).ShouldNot(gomega.BeEmpty())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user