Skip to content

Commit

Permalink
Use PollUntilContextTimeout instead of deprecated Poll
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Cho <[email protected]>
  • Loading branch information
jcho02 authored and openshift-cherrypick-robot committed May 7, 2024
1 parent 83902d5 commit 3e3e8ee
Showing 1 changed file with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
// the host from the cluster's context
if infra.Spec.PlatformSpec.Type == configv1.PowerVSPlatformType || infra.Spec.PlatformSpec.Type == configv1.IBMCloudPlatformType {
nodeTgt := "node/" + nodeList.Items[0].ObjectMeta.Name
if err := checkHostnameReady(tcpService, nodeTgt); err != nil {
if err := checkHostnameReady(ctx, tcpService, nodeTgt); err != nil {
return err
}
}
Expand Down Expand Up @@ -327,32 +327,27 @@ func httpGetNoConnectionPoolTimeout(url string, timeout time.Duration) (*http.Re
}

// Uses the first node in the cluster to verify the LoadBalancer host is active before returning
func checkHostnameReady(tcpService *corev1.Service, nodeTgt string) error {
func checkHostnameReady(ctx context.Context, tcpService *corev1.Service, nodeTgt string) error {
oc := exutil.NewCLIForMonitorTest(tcpService.GetObjectMeta().GetNamespace())

var (
stdOut string
err error
)

for i := 0; i < 60; i++ {
fmt.Printf("Checking load balancer host is active \n")
wait.Poll(3*time.Second, 60*time.Second, func() (bool, error) {
stdOut, _, err = oc.AsAdmin().WithoutNamespace().RunInMonitorTest("debug").Args(nodeTgt, "--", "dig", "+short", tcpService.Status.LoadBalancer.Ingress[0].Hostname).Outputs()
if err != nil {
return false, nil
}
return true, nil
})

wait.PollUntilContextTimeout(ctx, 15*time.Second, 60*time.Minute, true, func(ctx context.Context) (bool, error) {
logrus.Debug("Checking load balancer host is active \n")
stdOut, _, err = oc.AsAdmin().WithoutNamespace().RunInMonitorTest("debug").Args(nodeTgt, "--", "dig", "+short", "+notcp", tcpService.Status.LoadBalancer.Ingress[0].Hostname).Outputs()
if err != nil {
return false, nil
}
output := strings.TrimSpace(stdOut)
if output == "" {
fmt.Println("waiting for the LB to come active")
time.Sleep(1 * time.Minute)
continue
} else {
break
logrus.Debug("Waiting for the load balancer to become active")
return false, nil
}
}
return nil
logrus.Debug("Load balancer active")
return true, nil
})
return err
}

0 comments on commit 3e3e8ee

Please sign in to comment.