Skip to content

Commit 435530f

Browse files
authored
refactor(loadbalancer): use WaitForLoadBalancerDeletion from Go SDK (#472)
1 parent c0bfcf5 commit 435530f

1 file changed

Lines changed: 3 additions & 32 deletions

File tree

internal/commands/loadbalancer/delete.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package loadbalancer
22

33
import (
4-
"errors"
54
"fmt"
6-
"net/http"
7-
"time"
85

96
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
107
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
118
"github.com/UpCloudLtd/upcloud-cli/v3/internal/config"
129
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
1310
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
14-
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
1511
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
1612
"github.com/spf13/pflag"
1713
)
@@ -60,7 +56,9 @@ func Delete(exec commands.Executor, uuid string, wait bool) (output.Output, erro
6056

6157
if wait {
6258
exec.PushProgressUpdateMessage(msg, fmt.Sprintf("Waiting for load balancer %s to be deleted", uuid))
63-
err = waitUntilLoadBalancerDeleted(exec, uuid)
59+
err = svc.WaitForLoadBalancerDeletion(exec.Context(), &request.WaitForLoadBalancerDeletionRequest{
60+
UUID: uuid,
61+
})
6462
if err != nil {
6563
return commands.HandleError(exec, msg, err)
6664
}
@@ -80,30 +78,3 @@ func (s *deleteCommand) Execute(exec commands.Executor, arg string) (output.Outp
8078

8179
return Delete(exec, arg, s.wait.Value())
8280
}
83-
84-
func waitUntilLoadBalancerDeleted(exec commands.Executor, uuid string) error {
85-
ticker := time.NewTicker(5 * time.Second)
86-
defer ticker.Stop()
87-
88-
ctx := exec.Context()
89-
svc := exec.All()
90-
91-
for i := 0; ; i++ {
92-
select {
93-
case <-ticker.C:
94-
_, err := svc.GetLoadBalancer(exec.Context(), &request.GetLoadBalancerRequest{
95-
UUID: uuid,
96-
})
97-
if err != nil {
98-
var ucErr *upcloud.Problem
99-
if errors.As(err, &ucErr) && ucErr.Status == http.StatusNotFound {
100-
return nil
101-
}
102-
103-
return err
104-
}
105-
case <-ctx.Done():
106-
return ctx.Err()
107-
}
108-
}
109-
}

0 commit comments

Comments
 (0)