Merge pull request #7505 from omerap12/e2e-wait-deprecated

VPA: Poll/PollImmediate PollUntilContextTimeout in v1 e2e tests
This commit is contained in:
Kubernetes Prow Robot 2024-11-22 19:02:54 +00:00 committed by GitHub
commit f8b2129609
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 17 additions and 30 deletions

View File

@ -192,7 +192,7 @@ func newMutatingIsReadyWebhookFixture(f *framework.Framework, certContext *certC
// the webhook configuration.
func waitWebhookConfigurationReady(f *framework.Framework) error {
cmClient := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name + "-markers")
return wait.PollImmediate(100*time.Millisecond, 30*time.Second, func() (bool, error) {
return wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 30*time.Second, true, func(ctx context.Context) (done bool, err error) {
marker := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: string(uuid.NewUUID()),
@ -201,7 +201,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
},
},
}
_, err := cmClient.Create(context.TODO(), marker, metav1.CreateOptions{})
_, err = cmClient.Create(ctx, marker, metav1.CreateOptions{})
if err != nil {
// The always-deny webhook does not provide a reason, so check for the error string we expect
if strings.Contains(err.Error(), "denied") {
@ -210,7 +210,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
return false, err
}
// best effort cleanup of markers that are no longer needed
_ = cmClient.Delete(context.TODO(), marker.GetName(), metav1.DeleteOptions{})
_ = cmClient.Delete(ctx, marker.GetName(), metav1.DeleteOptions{})
framework.Logf("Waiting for webhook configuration to be ready...")
return false, nil
})

View File

@ -530,9 +530,8 @@ func assertPodsPendingForDuration(c clientset.Interface, deployment *appsv1.Depl
pendingPods := make(map[string]time.Time)
err := wait.PollImmediate(pollInterval, pollTimeout+pendingDuration, func() (bool, error) {
var err error
currentPodList, err := framework_deployment.GetPodsForDeployment(context.TODO(), c, deployment)
err := wait.PollUntilContextTimeout(context.Background(), pollInterval, pollTimeout, true, func(ctx context.Context) (done bool, err error) {
currentPodList, err := framework_deployment.GetPodsForDeployment(ctx, c, deployment)
if err != nil {
return false, err
}
@ -708,7 +707,7 @@ func setupHamsterReplicationController(f *framework.Framework, cpu, memory strin
}
func waitForRCPodsRunning(f *framework.Framework, rc *apiv1.ReplicationController) error {
return wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
return wait.PollUntilContextTimeout(context.Background(), pollInterval, pollTimeout, true, func(ctx context.Context) (done bool, err error) {
podList, err := GetHamsterPods(f)
if err != nil {
framework.Logf("Error listing pods, retrying: %v", err)

View File

@ -245,7 +245,7 @@ func (rc *ResourceConsumer) sendConsumeCPURequest(millicores int) {
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
defer cancel()
err := wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
err := wait.PollUntilContextTimeout(ctx, serviceInitializationInterval, serviceInitializationTimeout, true, func(ctx context.Context) (done bool, err error) {
proxyRequest, err := e2eservice.GetServicesProxyRequest(rc.clientSet, rc.clientSet.CoreV1().RESTClient().Post())
framework.ExpectNoError(err)
req := proxyRequest.Namespace(rc.nsName).
@ -271,7 +271,7 @@ func (rc *ResourceConsumer) sendConsumeMemRequest(megabytes int) {
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
defer cancel()
err := wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
err := wait.PollUntilContextTimeout(ctx, serviceInitializationInterval, serviceInitializationTimeout, true, func(ctx context.Context) (done bool, err error) {
proxyRequest, err := e2eservice.GetServicesProxyRequest(rc.clientSet, rc.clientSet.CoreV1().RESTClient().Post())
framework.ExpectNoError(err)
req := proxyRequest.Namespace(rc.nsName).
@ -297,7 +297,7 @@ func (rc *ResourceConsumer) sendConsumeCustomMetric(delta int) {
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
defer cancel()
err := wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
err := wait.PollUntilContextTimeout(ctx, serviceInitializationInterval, serviceInitializationTimeout, true, func(ctx context.Context) (done bool, err error) {
proxyRequest, err := e2eservice.GetServicesProxyRequest(rc.clientSet, rc.clientSet.CoreV1().RESTClient().Post())
framework.ExpectNoError(err)
req := proxyRequest.Namespace(rc.nsName).

View File

@ -241,7 +241,7 @@ func NewTestCronJob(name, schedule string, replicas int32) *batchv1.CronJob {
}
func waitForActiveJobs(c clientset.Interface, ns, cronJobName string, active int) error {
return wait.Poll(framework.Poll, cronJobsWaitTimeout, func() (bool, error) {
return wait.PollUntilContextTimeout(context.Background(), framework.Poll, cronJobsWaitTimeout, true, func(ctx context.Context) (done bool, err error) {
curr, err := getCronJob(c, ns, cronJobName)
if err != nil {
return false, err
@ -391,7 +391,7 @@ func MakePodSet(pods *apiv1.PodList) PodSet {
func WaitForPodsRestarted(f *framework.Framework, podList *apiv1.PodList) error {
initialPodSet := MakePodSet(podList)
err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
return wait.PollUntilContextTimeout(context.Background(), pollInterval, pollTimeout, true, func(ctx context.Context) (done bool, err error) {
currentPodList, err := GetHamsterPods(f)
if err != nil {
return false, err
@ -399,18 +399,13 @@ func WaitForPodsRestarted(f *framework.Framework, podList *apiv1.PodList) error
currentPodSet := MakePodSet(currentPodList)
return WerePodsSuccessfullyRestarted(currentPodSet, initialPodSet), nil
})
if err != nil {
return fmt.Errorf("waiting for set of pods changed: %v", err)
}
return nil
}
// WaitForPodsEvicted waits until some pods from the list are evicted.
func WaitForPodsEvicted(f *framework.Framework, podList *apiv1.PodList) error {
initialPodSet := MakePodSet(podList)
err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
return wait.PollUntilContextTimeout(context.Background(), pollInterval, pollTimeout, true, func(ctx context.Context) (done bool, err error) {
currentPodList, err := GetHamsterPods(f)
if err != nil {
return false, err
@ -418,11 +413,6 @@ func WaitForPodsEvicted(f *framework.Framework, podList *apiv1.PodList) error {
currentPodSet := MakePodSet(currentPodList)
return GetEvictedPodsCount(currentPodSet, initialPodSet) > 0, nil
})
if err != nil {
return fmt.Errorf("waiting for set of pods changed: %v", err)
}
return nil
}
// WerePodsSuccessfullyRestarted returns true if some pods from initialPodSet have been
@ -469,8 +459,7 @@ func CheckNoPodsEvicted(f *framework.Framework, initialPodSet PodSet) {
// polled vpa object. On timeout returns error.
func WaitForVPAMatch(c vpa_clientset.Interface, vpa *vpa_types.VerticalPodAutoscaler, match func(vpa *vpa_types.VerticalPodAutoscaler) bool) (*vpa_types.VerticalPodAutoscaler, error) {
var polledVpa *vpa_types.VerticalPodAutoscaler
err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
var err error
err := wait.PollUntilContextTimeout(context.Background(), pollInterval, pollTimeout, true, func(ctx context.Context) (done bool, err error) {
polledVpa, err = c.AutoscalingV1().VerticalPodAutoscalers(vpa.Namespace).Get(context.TODO(), vpa.Name, metav1.GetOptions{})
if err != nil {
return false, err

View File

@ -156,8 +156,8 @@ func waitForDaemonSets(c clientset.Interface, ns string, allowedNotReadyNodes in
framework.Logf("Waiting up to %v for all daemonsets in namespace '%s' to start",
timeout, ns)
return wait.PollImmediate(framework.Poll, timeout, func() (bool, error) {
dsList, err := c.AppsV1().DaemonSets(ns).List(context.TODO(), metav1.ListOptions{})
return wait.PollUntilContextTimeout(context.Background(), framework.Poll, timeout, true, func(ctx context.Context) (done bool, err error) {
dsList, err := c.AppsV1().DaemonSets(ns).List(ctx, metav1.ListOptions{})
if err != nil {
framework.Logf("Error getting daemonsets in namespace: '%s': %v", ns, err)
return false, err

View File

@ -316,12 +316,11 @@ var _ = FullVpaE2eDescribe("OOMing pods under VPA", func() {
})
func waitForPodsMatch(f *framework.Framework, timeout time.Duration, listOptions metav1.ListOptions, matcher func(pod apiv1.Pod) bool) error {
return wait.PollImmediate(pollInterval, timeout, func() (bool, error) {
return wait.PollUntilContextTimeout(context.Background(), pollInterval, timeout, true, func(ctx context.Context) (done bool, err error) {
ns := f.Namespace.Name
c := f.ClientSet
podList, err := c.CoreV1().Pods(ns).List(context.TODO(), listOptions)
podList, err := c.CoreV1().Pods(ns).List(ctx, listOptions)
if err != nil {
return false, err
}