@@ -2,11 +2,20 @@ package k8s
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "net/http"
7
+ "time"
5
8
6
9
"github.com/fatih/color"
7
10
"github.com/scaleway/scaleway-cli/internal/core"
8
11
"github.com/scaleway/scaleway-cli/internal/human"
9
12
k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1beta4"
13
+ "github.com/scaleway/scaleway-sdk-go/scw"
14
+ "golang.org/x/xerrors"
15
+ )
16
+
17
+ const (
18
+ clusterActionTimeout = 10 * time .Minute
10
19
)
11
20
12
21
//
@@ -40,3 +49,41 @@ func clusterAvailableVersionsListBuilder(c *core.Command) *core.Command {
40
49
41
50
return c
42
51
}
52
+
53
+ func clusterCreateBuilder (c * core.Command ) * core.Command {
54
+ c .WaitFunc = waitForClusterFunc ()
55
+ return c
56
+ }
57
+
58
+ func clusterDeleteBuilder (c * core.Command ) * core.Command {
59
+ c .WaitFunc = waitForClusterFunc ()
60
+ return c
61
+ }
62
+
63
+ func clusterUpgradeBuilder (c * core.Command ) * core.Command {
64
+ c .WaitFunc = waitForClusterFunc ()
65
+ return c
66
+ }
67
+
68
+ func clusterUpdateBuilder (c * core.Command ) * core.Command {
69
+ c .WaitFunc = waitForClusterFunc ()
70
+ return c
71
+ }
72
+
73
+ func waitForClusterFunc () core.WaitFunc {
74
+ return func (ctx context.Context , _ , respI interface {}) (interface {}, error ) {
75
+ cluster , err := k8s .NewAPI (core .ExtractClient (ctx )).WaitForCluster (& k8s.WaitForClusterRequest {
76
+ Region : respI .(* k8s.Cluster ).Region ,
77
+ ClusterID : respI .(* k8s.Cluster ).ID ,
78
+ Timeout : scw .DurationPtr (clusterActionTimeout ),
79
+ })
80
+ if err != nil {
81
+ notFoundError := & scw.ResourceNotFoundError {}
82
+ responseError := & scw.ResponseError {}
83
+ if xerrors .As (err , & responseError ) && responseError .StatusCode == http .StatusNotFound || xerrors .As (err , & notFoundError ) {
84
+ return fmt .Sprintf ("Cluster %s successfully deleted." , respI .(* k8s.Cluster ).ID ), nil
85
+ }
86
+ }
87
+ return cluster , nil
88
+ }
89
+ }
0 commit comments