// waitForLimitSync waits until a usage of a quota reaches given limit with a short timeout func waitForLimitSync(oc *exutil.CLI, hardLimit kapi.ResourceList) error { g.By(fmt.Sprintf("waiting for resource quota %s to get updated", quotaName)) return testutil.WaitForResourceQuotaLimitSync( oc.KubeClient().Core().ResourceQuotas(oc.Namespace()), quotaName, hardLimit, waitTimeout) }
// bumpQuota modifies hard spec of quota object with the given value. It returns modified hard spec. func bumpQuota(t *testing.T, rqs kclient.ResourceQuotaInterface, quotaName string, resourceName kapi.ResourceName, value int64) kapi.ResourceList { t.Logf("bump the quota %s to %s=%d", quotaName, resourceName, value) rq, err := rqs.Get(quotaName) if err != nil { t.Fatal(err) } rq.Spec.Hard[resourceName] = *resource.NewQuantity(value, resource.DecimalSI) _, err = rqs.Update(rq) if err != nil { t.Fatal(err) } err = testutil.WaitForResourceQuotaLimitSync( rqs, quotaName, rq.Spec.Hard, time.Second*10) if err != nil { t.Fatal(err) } return rq.Spec.Hard }
// createResourceQuota creates a resource quota with given hard limits in a current namespace and waits until // a first usage refresh func createResourceQuota(t *testing.T, rqClient kclient.ResourceQuotaInterface, quotaName string, hard kapi.ResourceList) *kapi.ResourceQuota { rq := &kapi.ResourceQuota{ ObjectMeta: kapi.ObjectMeta{ Name: quotaName, }, Spec: kapi.ResourceQuotaSpec{ Hard: hard, }, } t.Logf("creating resource quota %q with a limit %v", quotaName, hard) rq, err := rqClient.Create(rq) if err != nil { t.Fatal(err) } err = testutil.WaitForResourceQuotaLimitSync(rqClient, quotaName, hard, time.Second*30) if err != nil { t.Fatal(err) } return rq }