Skip to content

Commit

Permalink
Fix infinity loop while waiting for migration Pod to become ready
Browse files Browse the repository at this point in the history
Currently, if the user sends a SIGINT (Ctrl+C) to the process while it
is waiting for the migration Pod to become Ready, the process will
enter an infinity loop, because:

1. It will try to get the Pod from the API Server
2. The client will return an error because the context is expired (due
   to SIGINT).
3. It will continue to the next iteration of the loop.

This fix, before its iteration checks if the context is Done(), and if
so, returns immediately an error to the caller.

Signed-off-by: Grigoris Thanasoulas <[email protected]>
  • Loading branch information
Grigoris Thanasoulas committed Oct 23, 2023
1 parent 225cf0a commit 81718b1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ func copyOnePVC(ctx context.Context, w *log.Logger, clientset k8sclient.Interfac
// wait for the pod to be created
time.Sleep(waitTime)
for {
select {
case <-ctx.Done():
return fmt.Errorf("context ended waiting for Pod %s in %s to be deleted", createdPod.Name, ns)
default:
}

gotPod, err := clientset.CoreV1().Pods(ns).Get(ctx, createdPod.Name, metav1.GetOptions{})
if err != nil {
w.Printf("failed to get newly created migration pod %s: %v\n", createdPod.Name, err)
Expand Down

0 comments on commit 81718b1

Please sign in to comment.