Skip to content

Commit a9fae64

Browse files
authored
feat(objsto): add --force flag to delete command (#678)
1 parent e1865fe commit a9fae64

10 files changed

Lines changed: 30 additions & 12 deletions

File tree

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ jobs:
6262
timeout-minutes: 5
6363
run: upctl all purge --include example-upctl-*
6464
- name: List remaining resources
65-
run: upctl all list --include *tf-acc-test* --exclude *persistent*
65+
run: upctl all list --include example-upctl-*
6666
if: ${{ failure() }}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Unconditionally enable colors if the [FORCE_COLOR](https://force-color.org) environment variable is set to a non-empty value.
13+
- Add `--force` flag to `object-storage delete` command.
14+
15+
### Changed
16+
17+
- Use `--force` flag in `all purge` command when deleting object storage instances instead of deleting sub-resources one-by-one.
1318

1419
## [3.28.0] - 2026-01-14
1520

examples/use_object_storage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Once not needed anymore, delete the user:
4141
upctl object-storage user delete ${prefix}service --username ${prefix}user
4242
```
4343

44-
Delete also the managed object storage service along with its buckets:
44+
Delete also the managed object storage service along with all its sub-resources such as buckets and users:
4545

4646
```sh
47-
upctl object-storage delete ${prefix}service --delete-buckets
47+
upctl object-storage delete ${prefix}service --force
4848
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
dario.cat/mergo v1.0.2
77
github.com/UpCloudLtd/progress v1.1.0
88
github.com/UpCloudLtd/upcloud-go-api/credentials v0.1.1
9-
github.com/UpCloudLtd/upcloud-go-api/v8 v8.34.0
9+
github.com/UpCloudLtd/upcloud-go-api/v8 v8.34.3
1010
github.com/adrg/xdg v0.5.3
1111
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
1212
github.com/jedib0t/go-pretty/v6 v6.7.8

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/UpCloudLtd/progress v1.1.0 h1:RT2DNMlvJy1R8WZr2dKdDgR+xD1+3+UdZauIfWr
2828
github.com/UpCloudLtd/progress v1.1.0/go.mod h1:iGxOnb9HvHW0yrLGUjHr0lxHhn7TehgWwh7a8NqK6iQ=
2929
github.com/UpCloudLtd/upcloud-go-api/credentials v0.1.1 h1:eTfQsv58ufALOk9BZ7WbS/i7pMUD11RnYYpRPsz0LdI=
3030
github.com/UpCloudLtd/upcloud-go-api/credentials v0.1.1/go.mod h1:7OtVs2UqtfvjkC1HfE+Oud0MnbMv7qUWnbEgxnTAqts=
31-
github.com/UpCloudLtd/upcloud-go-api/v8 v8.34.0 h1:MCrAV9HwUFOzFJ0OEKIlgXefaZVXo23PuAC/ctZwfFo=
32-
github.com/UpCloudLtd/upcloud-go-api/v8 v8.34.0/go.mod h1:NBh1d/ip1bhdAIhuPWbyPme7tbLzDTV7dhutUmU1vg8=
31+
github.com/UpCloudLtd/upcloud-go-api/v8 v8.34.3 h1:7ba03u4L5LafZPVO2k6B0/f114k5dFF3GtAN7FEKfno=
32+
github.com/UpCloudLtd/upcloud-go-api/v8 v8.34.3/go.mod h1:NBh1d/ip1bhdAIhuPWbyPme7tbLzDTV7dhutUmU1vg8=
3333
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
3434
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
3535
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=

internal/commands/all/purge_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ func TestPurgeCommand(t *testing.T) {
2424
args: []string{"--include", "*tf-acc-test*", "--exclude", "*persistent*"},
2525
called: [][]any{
2626
{"DeleteManagedObjectStorage", &request.DeleteManagedObjectStorageRequest{
27-
UUID: objectStorages[0].UUID,
27+
UUID: objectStorages[0].UUID,
28+
Force: true,
2829
}},
2930
{"DeleteNetwork", &request.DeleteNetworkRequest{
3031
UUID: networks.Networks[0].UUID,

internal/commands/all/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func deleteResource(exec commands.Executor, resource Resource) (err error) {
276276
case typeRouter:
277277
_, err = router.Delete(exec, resource.UUID)
278278
case typeObjectStorage:
279-
_, err = objectstorage.Delete(exec, resource.UUID, true, true, true, true)
279+
_, err = objectstorage.Delete(exec, resource.UUID, false, false, false, true, true)
280280
case typeDatabase:
281281
_, err = database.Delete(exec, resource.UUID, true, true)
282282
case typeServer:

internal/commands/objectstorage/delete.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type deleteCommand struct {
3333
deleteUsers config.OptionalBoolean
3434
deletePolicies config.OptionalBoolean
3535
deleteBuckets config.OptionalBoolean
36+
force config.OptionalBoolean
3637
wait config.OptionalBoolean
3738
}
3839

@@ -42,6 +43,7 @@ func (c *deleteCommand) InitCommand() {
4243
config.AddToggleFlag(flags, &c.deleteUsers, "delete-users", false, "Delete all users from the service before deleting the object storage instance.")
4344
config.AddToggleFlag(flags, &c.deletePolicies, "delete-policies", false, "Delete all policies from the service before deleting the object storage instance.")
4445
config.AddToggleFlag(flags, &c.deleteBuckets, "delete-buckets", false, "Delete all buckets from the service before deleting the object storage instance.")
46+
config.AddToggleFlag(flags, &c.force, "force", false, "Delete the object storage instance even if there are buckets or other sub-resources that would normally block the deletion.")
4547
config.AddToggleFlag(flags, &c.wait, "wait", false, "Wait until the object storage instance has been deleted before returning.")
4648
c.AddFlags(flags)
4749

@@ -50,7 +52,7 @@ func (c *deleteCommand) InitCommand() {
5052
commands.SetSubcommandDeprecationHelp(c, []string{"objectstorage", "objsto"})
5153
}
5254

53-
func Delete(exec commands.Executor, uuid string, deleteUsers, deletePolicies, deleteBuckets, wait bool) (output.Output, error) {
55+
func Delete(exec commands.Executor, uuid string, deleteUsers, deletePolicies, deleteBuckets, force, wait bool) (output.Output, error) {
5456
svc := exec.All()
5557
msg := fmt.Sprintf("Deleting object storage service %v", uuid)
5658
exec.PushProgressStarted(msg)
@@ -124,7 +126,8 @@ func Delete(exec commands.Executor, uuid string, deleteUsers, deletePolicies, de
124126

125127
exec.PushProgressUpdateMessage(msg, msg)
126128
err := svc.DeleteManagedObjectStorage(exec.Context(), &request.DeleteManagedObjectStorageRequest{
127-
UUID: uuid,
129+
UUID: uuid,
130+
Force: force,
128131
})
129132
if err != nil {
130133
return commands.HandleError(exec, msg, err)
@@ -150,7 +153,7 @@ func (c *deleteCommand) Execute(exec commands.Executor, arg string) (output.Outp
150153
// TODO: Remove this in the future
151154
commands.SetSubcommandExecutionDeprecationMessage(c, []string{"objectstorage", "objsto"}, "object-storage")
152155

153-
return Delete(exec, arg, c.deleteUsers.Value(), c.deletePolicies.Value(), c.deleteBuckets.Value(), c.wait.Value())
156+
return Delete(exec, arg, c.deleteUsers.Value(), c.deletePolicies.Value(), c.deleteBuckets.Value(), c.force.Value(), c.wait.Value())
154157
}
155158

156159
func waitUntilBucketsHaveBeenDeleted(exec commands.Executor, serviceUUID string) error {

internal/commands/objectstorage/delete_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ func TestDeleteCommand(t *testing.T) {
5555
flags: []string{"--delete-users", "--delete-policies"},
5656
req: request.DeleteManagedObjectStorageRequest{UUID: objectstorage.UUID},
5757
},
58+
{
59+
name: "delete with UUID using force",
60+
arg: objectstorage.UUID,
61+
flags: []string{"--force"},
62+
req: request.DeleteManagedObjectStorageRequest{
63+
UUID: objectstorage.UUID,
64+
Force: true,
65+
},
66+
},
5867
} {
5968
t.Run(test.name, func(t *testing.T) {
6069
mService := smock.Service{}

internal/commands/stack/stackops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func DestroyStack(exec commands.Executor, name, zone string, deleteStorage, dele
333333
}
334334

335335
if deleteObjectStorage {
336-
_, err = objectstorage.Delete(exec, storageUUID, true, true, true, true)
336+
_, err = objectstorage.Delete(exec, storageUUID, false, false, false, true, true)
337337
if err != nil {
338338
return fmt.Errorf("failed to delete object storage: %w", err)
339339
}

0 commit comments

Comments
 (0)