Skip to content

Commit 0274372

Browse files
authored
fix(all): assume resource was deleted on HTTP 404 response (#565)
1 parent c9dc4a1 commit 0274372

6 files changed

Lines changed: 33 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- stack destroy command for supabase, dokku and starter-kit
1313
- Add devices list to `server show` output.
1414

15+
### Fixed
16+
17+
- In `upctl all purge`, if resource deletion fails with HTTP 404 status, consider the resource deleted.
18+
1519
## [3.24.1] - 2025-10-14
1620

1721
### Changed

internal/commands/all/resource.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/servergroup"
2424
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/storage"
2525
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
26+
"github.com/UpCloudLtd/upcloud-cli/v3/internal/utils"
2627
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
2728
)
2829

@@ -344,8 +345,9 @@ func DeleteResources(exec commands.Executor, resources []Resource, workerCount i
344345
}
345346
}(i)
346347
case res := <-returnChan:
347-
// Requeue failed deletes after 5 seconds
348-
if res.Error != nil {
348+
// Requeue failed deletes after 5 seconds.
349+
// Assume resource has been deleted, if delete failed with HTTP 404 status.
350+
if res.Error != nil && !utils.IsNotFoundError(res.Error) {
349351
exec.PushProgressUpdate(messages.Update{
350352
Key: res.Resource.Key(),
351353
Message: fmt.Sprintf("Waiting 5 seconds before retrying to delete %s %s", res.Resource.Type, res.Resource.Name),

internal/commands/database/delete.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package database
22

33
import (
4-
"errors"
54
"fmt"
6-
"net/http"
75
"time"
86

97
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
108
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
119
"github.com/UpCloudLtd/upcloud-cli/v3/internal/config"
1210
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
1311
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
14-
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
12+
"github.com/UpCloudLtd/upcloud-cli/v3/internal/utils"
1513
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
1614
"github.com/spf13/pflag"
1715
)
@@ -99,8 +97,7 @@ func waitUntilDatabaseDeleted(exec commands.Executor, uuid string) error {
9997
UUID: uuid,
10098
})
10199
if err != nil {
102-
var ucErr *upcloud.Problem
103-
if errors.As(err, &ucErr) && ucErr.Status == http.StatusNotFound {
100+
if utils.IsNotFoundError(err) {
104101
return nil
105102
}
106103

internal/commands/error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func (h handledError) Error() string {
2424
return h.err.Error()
2525
}
2626

27+
func (h handledError) Unwrap() error {
28+
return h.err
29+
}
30+
2731
// outputError outputs given error to progress log, if the error has not been already handled by HandleError
2832
func outputError(arg string, err error, exec Executor) {
2933
if err == nil {

internal/commands/kubernetes/delete.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package kubernetes
22

33
import (
4-
"errors"
54
"fmt"
6-
"net/http"
75
"time"
86

97
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
108
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
119
"github.com/UpCloudLtd/upcloud-cli/v3/internal/config"
1210
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
1311
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
12+
"github.com/UpCloudLtd/upcloud-cli/v3/internal/utils"
1413
"github.com/spf13/pflag"
1514

16-
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
1715
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
1816
)
1917

@@ -96,8 +94,7 @@ func waitUntilClusterDeleted(exec commands.Executor, uuid string) error {
9694
UUID: uuid,
9795
})
9896
if err != nil {
99-
var ucErr *upcloud.Problem
100-
if errors.As(err, &ucErr) && ucErr.Status == http.StatusNotFound {
97+
if utils.IsNotFoundError(err) {
10198
return nil
10299
}
103100

internal/utils/errors.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package utils
2+
3+
import (
4+
"errors"
5+
"net/http"
6+
7+
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
8+
)
9+
10+
func IsNotFoundError(err error) bool {
11+
var ucErr *upcloud.Problem
12+
if errors.As(err, &ucErr) && ucErr.Status == http.StatusNotFound {
13+
return true
14+
}
15+
16+
return false
17+
}

0 commit comments

Comments
 (0)