Skip to content

Commit

Permalink
Add a timeout when deleting a namespace
Browse files Browse the repository at this point in the history
This typically finish in less than 10 seconds. If it does not complete
in 60 seconds it needs manual intervention so lets fail fast.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Oct 29, 2024
1 parent b175d30 commit 57e887c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions e2e/util/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package util

import (
"context"
"fmt"
"time"

"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -55,11 +56,11 @@ func DeleteNamespace(client client.Client, namespace string) error {
}

Ctx.Log.Info("waiting until namespace " + namespace + " is deleted")

startTime := time.Now()
key := types.NamespacedName{Name: namespace}

for {
time.Sleep(time.Second)

if err := client.Get(context.Background(), key, ns); err != nil {
if !errors.IsNotFound(err) {
return err
Expand All @@ -69,6 +70,12 @@ func DeleteNamespace(client client.Client, namespace string) error {

return nil
}

if time.Since(startTime) > 60*time.Second {
return fmt.Errorf("timeout deleting namespace %q", namespace)
}

time.Sleep(time.Second)
}
}

Expand Down

0 comments on commit 57e887c

Please sign in to comment.