Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit ea9e68b

Browse files
committed
Wait for server to acknowledge app deletion before trying ignore-cleanup
There are certain situations where the app delete succeeds and the call to ignore-cleanup fails because it thinks that the app is not being deleted. This change will retry on this error to avoid the necessity of having to delete the app and then ignore-cleanup. Signed-off-by: Donnie Adams <[email protected]>
1 parent c337c56 commit ea9e68b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pkg/cli/rm_helper.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package cli
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"net/http"
68
"strings"
79
"time"
810

@@ -11,6 +13,7 @@ import (
1113
"github.com/pterm/pterm"
1214
"github.com/sirupsen/logrus"
1315
apierrors "k8s.io/apimachinery/pkg/api/errors"
16+
k8swait "k8s.io/apimachinery/pkg/util/wait"
1417
"k8s.io/client-go/util/retry"
1518

1619
"github.com/acorn-io/runtime/pkg/client"
@@ -147,7 +150,19 @@ func removeAcorn(ctx context.Context, c client.Client, arg string, ignoreCleanup
147150
}
148151

149152
if ignoreCleanup {
150-
if err := c.AppIgnoreDeleteCleanup(ctx, arg); err != nil {
153+
// There are situations where an app being deleted the first time with the --ignore-cleanup flag will fail at this
154+
// step because the server thinks that the app is not being deleted. Retrying here will work around this issue.
155+
if err = retry.OnError(k8swait.Backoff{
156+
Steps: 5,
157+
Duration: 500 * time.Millisecond,
158+
Factor: 2,
159+
Jitter: 0.1,
160+
}, func(err error) bool {
161+
var statusErr *apierrors.StatusError
162+
return errors.As(err, &statusErr) && statusErr.Status().Code == http.StatusBadRequest && strings.HasSuffix(statusErr.Status().Message, "it is not being deleted")
163+
}, func() error {
164+
return c.AppIgnoreDeleteCleanup(ctx, arg)
165+
}); err != nil {
151166
return fmt.Errorf("skipping cleanup for app %s: %w", arg, err)
152167
}
153168
}

pkg/server/registry/apigroups/acorn/apps/ignorecleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s *ignoreCleanupStrategy) Create(ctx context.Context, obj types.Object) (t
5959
}
6060

6161
if app.DeletionTimestamp.IsZero() {
62-
return fmt.Errorf("cannot force delete app %s because it is not being deleted", app.Name)
62+
return apierrors.NewBadRequest(fmt.Sprintf("cannot force delete app %s because it is not being deleted", app.Name))
6363
}
6464

6565
// If the app has the destroy job finalizer, remove it to force delete

0 commit comments

Comments
 (0)