Skip to content

Commit d7b130e

Browse files
feat(ske): port to v2api version of SDK (#1337)
1 parent 0f02251 commit d7b130e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+385
-384
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6
3636
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
3737
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7
38-
github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0
38+
github.com/stackitcloud/stackit-sdk-go/services/ske v1.9.0
3939
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3
4040
github.com/zalando/go-keyring v0.2.6
4141
golang.org/x/mod v0.33.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 h1:M2PY
654654
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7/go.mod h1:jitkQuP2K/SH63Qor0C4pcqz1GDCy/lK2H4t8/VDse4=
655655
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.4.0 h1:ofdGO2dGH6ywKbIVxaxRVal3jWX9WlcHSm5BTud5bC4=
656656
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.4.0/go.mod h1:r5lBwzJpJe2xBIYctkVIIpaZ41Y6vUEpkmsWR2VoQJs=
657-
github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0 h1:l1QjxW7sdE/6B6BZtHxbmus8XJdI9KDuXX3fwUa5fog=
658-
github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0/go.mod h1:1Jr+ImrmPERxbYnlTy6O2aSZYNnREf2qQyysv6YC1RY=
657+
github.com/stackitcloud/stackit-sdk-go/services/ske v1.9.0 h1:pNEIQdUJMP5oMsBV/U9ENGBbzsFedb/3ZRC+Mw7bcYc=
658+
github.com/stackitcloud/stackit-sdk-go/services/ske v1.9.0/go.mod h1:VW6csYWkytVufoiDMquVEdyF0amYICzOzSe6ynRRDsI=
659659
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3 h1:AQrcr+qeIuZob+3TT2q1L4WOPtpsu5SEpkTnOUHDqfE=
660660
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3/go.mod h1:8BBGC69WFXWWmKgzSjgE4HvsI7pEgO0RN2cASwuPJ18=
661661
github.com/stbenjam/no-sprintf-host-port v0.3.1 h1:AyX7+dxI4IdLBPtDbsGAyqiTSLpCP9hWRrXQDU4Cm/g=

internal/cmd/ske/cluster/create/create.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils"
2222
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
2323
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
24-
"github.com/stackitcloud/stackit-sdk-go/services/ske"
25-
"github.com/stackitcloud/stackit-sdk-go/services/ske/wait"
24+
ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api"
25+
wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait"
2626
)
2727

2828
const (
@@ -106,7 +106,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
106106
}
107107

108108
// Check if cluster exists
109-
exists, err := skeUtils.ClusterExists(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName)
109+
exists, err := skeUtils.ClusterExists(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName)
110110
if err != nil {
111111
return err
112112
}
@@ -116,7 +116,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
116116

117117
// Fill in default payload, if needed
118118
if model.Payload == nil {
119-
defaultPayload, err := skeUtils.GetDefaultPayload(ctx, apiClient, model.Region)
119+
defaultPayload, err := skeUtils.GetDefaultPayload(ctx, apiClient.DefaultAPI, model.Region)
120120
if err != nil {
121121
return fmt.Errorf("get default payload: %w", err)
122122
}
@@ -135,7 +135,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
135135
if !model.Async {
136136
s := spinner.New(params.Printer)
137137
s.Start("Creating cluster")
138-
_, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient, model.ProjectId, model.Region, name).WaitWithContext(ctx)
138+
_, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, name).WaitWithContext(ctx)
139139
if err != nil {
140140
return fmt.Errorf("wait for SKE cluster creation: %w", err)
141141
}
@@ -182,7 +182,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
182182
}
183183

184184
func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiCreateOrUpdateClusterRequest {
185-
req := apiClient.CreateOrUpdateCluster(ctx, model.ProjectId, model.Region, model.ClusterName)
185+
req := apiClient.DefaultAPI.CreateOrUpdateCluster(ctx, model.ProjectId, model.Region, model.ClusterName)
186186

187187
req = req.CreateOrUpdateClusterPayload(*model.Payload)
188188
return req

internal/cmd/ske/cluster/create/create_test.go

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package create
22

33
import (
44
"context"
5-
"fmt"
65
"testing"
76
"time"
87

@@ -17,59 +16,59 @@ import (
1716
"github.com/google/go-cmp/cmp"
1817
"github.com/google/go-cmp/cmp/cmpopts"
1918
"github.com/google/uuid"
20-
"github.com/stackitcloud/stackit-sdk-go/services/ske"
19+
ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api"
2120
)
2221

2322
var projectIdFlag = globalflags.ProjectIdFlag
2423

2524
type testCtxKey struct{}
2625

2726
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
28-
var testClient = &ske.APIClient{}
27+
var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}}
2928
var testProjectId = uuid.NewString()
3029
var testClusterName = "cluster"
3130

3231
const testRegion = "eu01"
3332

3433
var testPayload = &ske.CreateOrUpdateClusterPayload{
35-
Kubernetes: &ske.Kubernetes{
36-
Version: utils.Ptr("1.25.15"),
34+
Kubernetes: ske.Kubernetes{
35+
Version: "1.25.15",
3736
},
38-
Nodepools: &[]ske.Nodepool{
37+
Nodepools: []ske.Nodepool{
3938
{
40-
Name: utils.Ptr("np-name"),
41-
Machine: &ske.Machine{
42-
Image: &ske.Image{
43-
Name: utils.Ptr("flatcar"),
44-
Version: utils.Ptr("3760.2.1"),
39+
Name: "np-name",
40+
Machine: ske.Machine{
41+
Image: ske.Image{
42+
Name: "flatcar",
43+
Version: "3760.2.1",
4544
},
46-
Type: utils.Ptr("b1.2"),
45+
Type: "b1.2",
4746
},
48-
Minimum: utils.Ptr(int64(1)),
49-
Maximum: utils.Ptr(int64(2)),
50-
MaxSurge: utils.Ptr(int64(1)),
51-
Volume: &ske.Volume{
47+
Minimum: int32(1),
48+
Maximum: int32(2),
49+
MaxSurge: utils.Ptr(int32(1)),
50+
Volume: ske.Volume{
5251
Type: utils.Ptr("storage_premium_perf0"),
53-
Size: utils.Ptr(int64(40)),
52+
Size: int32(40),
5453
},
55-
AvailabilityZones: &[]string{"eu01-3"},
56-
Cri: &ske.CRI{Name: ske.CRINAME_DOCKER.Ptr()},
54+
AvailabilityZones: []string{"eu01-3"},
55+
Cri: &ske.CRI{Name: utils.Ptr("containerd")},
5756
},
5857
},
5958
Extensions: &ske.Extension{
6059
Acl: &ske.ACL{
61-
Enabled: utils.Ptr(true),
62-
AllowedCidrs: &[]string{"0.0.0.0/0"},
60+
Enabled: true,
61+
AllowedCidrs: []string{"0.0.0.0/0"},
6362
},
6463
},
6564
Maintenance: &ske.Maintenance{
66-
AutoUpdate: &ske.MaintenanceAutoUpdate{
65+
AutoUpdate: ske.MaintenanceAutoUpdate{
6766
KubernetesVersion: utils.Ptr(true),
6867
MachineImageVersion: utils.Ptr(true),
6968
},
70-
TimeWindow: &ske.TimeWindow{
71-
End: utils.Ptr(time.Date(0, 1, 1, 5, 0, 0, 0, time.FixedZone("test-zone", 2*60*60))),
72-
Start: utils.Ptr(time.Date(0, 1, 1, 3, 0, 0, 0, time.FixedZone("test-zone", 2*60*60))),
69+
TimeWindow: ske.TimeWindow{
70+
End: time.Date(0, 1, 1, 5, 0, 0, 0, time.FixedZone("test-zone", 2*60*60)),
71+
Start: time.Date(0, 1, 1, 3, 0, 0, 0, time.FixedZone("test-zone", 2*60*60)),
7372
},
7473
},
7574
}
@@ -88,8 +87,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
8887
flagValues := map[string]string{
8988
globalflags.ProjectIdFlag: testProjectId,
9089
globalflags.RegionFlag: testRegion,
91-
payloadFlag: fmt.Sprintf(`{
92-
"name": "cli-jp",
90+
payloadFlag: `{
9391
"kubernetes": {
9492
"version": "1.25.15"
9593
},
@@ -107,7 +105,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
107105
"maximum": 2,
108106
"maxSurge": 1,
109107
"volume": { "type": "storage_premium_perf0", "size": 40 },
110-
"cri": { "name": "%s" },
108+
"cri": { "name": "containerd" },
111109
"availabilityZones": ["eu01-3"]
112110
}
113111
],
@@ -122,7 +120,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
122120
"start": "0000-01-01T03:00:00+02:00"
123121
}
124122
}
125-
}`, ske.CRINAME_DOCKER),
123+
}`,
126124
}
127125
for _, mod := range mods {
128126
mod(flagValues)
@@ -147,7 +145,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
147145
}
148146

149147
func fixtureRequest(mods ...func(request *ske.ApiCreateOrUpdateClusterRequest)) ske.ApiCreateOrUpdateClusterRequest {
150-
request := testClient.CreateOrUpdateCluster(testCtx, testProjectId, testRegion, fixtureInputModel().ClusterName)
148+
request := testClient.DefaultAPI.CreateOrUpdateCluster(testCtx, testProjectId, testRegion, fixtureInputModel().ClusterName)
151149
request = request.CreateOrUpdateClusterPayload(*testPayload)
152150
for _, mod := range mods {
153151
mod(&request)
@@ -262,6 +260,7 @@ func TestBuildRequest(t *testing.T) {
262260
diff := cmp.Diff(request, tt.expectedRequest,
263261
cmp.AllowUnexported(tt.expectedRequest),
264262
cmpopts.EquateComparable(testCtx),
263+
cmpopts.EquateComparable(testClient.DefaultAPI),
265264
)
266265
if diff != "" {
267266
t.Fatalf("Data does not match: %s", diff)

internal/cmd/ske/cluster/delete/delete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1616

1717
"github.com/spf13/cobra"
18-
"github.com/stackitcloud/stackit-sdk-go/services/ske"
19-
"github.com/stackitcloud/stackit-sdk-go/services/ske/wait"
18+
ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api"
19+
wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait"
2020
)
2121

2222
const (
@@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6969
if !model.Async {
7070
s := spinner.New(params.Printer)
7171
s.Start("Deleting cluster")
72-
_, err = wait.DeleteClusterWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx)
72+
_, err = wait.DeleteClusterWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx)
7373
if err != nil {
7474
return fmt.Errorf("wait for SKE cluster deletion: %w", err)
7575
}
@@ -105,6 +105,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
105105
}
106106

107107
func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiDeleteClusterRequest {
108-
req := apiClient.DeleteCluster(ctx, model.ProjectId, model.Region, model.ClusterName)
108+
req := apiClient.DefaultAPI.DeleteCluster(ctx, model.ProjectId, model.Region, model.ClusterName)
109109
return req
110110
}

internal/cmd/ske/cluster/delete/delete_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/google/uuid"
13-
"github.com/stackitcloud/stackit-sdk-go/services/ske"
13+
ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api"
1414
)
1515

1616
var projectIdFlag = globalflags.ProjectIdFlag
1717

1818
type testCtxKey struct{}
1919

2020
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &ske.APIClient{}
21+
var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}}
2222
var testProjectId = uuid.NewString()
2323
var testClusterName = "cluster"
2424

@@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6161
}
6262

6363
func fixtureRequest(mods ...func(request *ske.ApiDeleteClusterRequest)) ske.ApiDeleteClusterRequest {
64-
request := testClient.DeleteCluster(testCtx, testProjectId, testRegion, testClusterName)
64+
request := testClient.DefaultAPI.DeleteCluster(testCtx, testProjectId, testRegion, testClusterName)
6565
for _, mod := range mods {
6666
mod(&request)
6767
}
@@ -156,6 +156,7 @@ func TestBuildRequest(t *testing.T) {
156156
diff := cmp.Diff(request, tt.expectedRequest,
157157
cmp.AllowUnexported(tt.expectedRequest),
158158
cmpopts.EquateComparable(testCtx),
159+
cmpopts.EquateComparable(testClient.DefaultAPI),
159160
)
160161
if diff != "" {
161162
t.Fatalf("Data does not match: %s", diff)

internal/cmd/ske/cluster/describe/describe.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client"
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
19-
"github.com/stackitcloud/stackit-sdk-go/services/ske"
19+
ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api"
2020
)
2121

2222
const (
@@ -85,7 +85,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8585
}
8686

8787
func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiGetClusterRequest {
88-
req := apiClient.GetCluster(ctx, model.ProjectId, model.Region, model.ClusterName)
88+
req := apiClient.DefaultAPI.GetCluster(ctx, model.ProjectId, model.Region, model.ClusterName)
8989
return req
9090
}
9191

@@ -97,11 +97,11 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e
9797
return p.OutputResult(outputFormat, cluster, func() error {
9898
acl := []string{}
9999
if cluster.Extensions != nil && cluster.Extensions.Acl != nil {
100-
acl = *cluster.Extensions.Acl.AllowedCidrs
100+
acl = cluster.Extensions.Acl.AllowedCidrs
101101
}
102102

103103
table := tables.NewTable()
104-
table.AddRow("NAME", utils.PtrString(cluster.Name))
104+
table.AddRow("NAME", cluster.Name)
105105
table.AddSeparator()
106106
if cluster.HasStatus() {
107107
table.AddRow("STATE", utils.PtrString(cluster.Status.Aggregated))
@@ -110,8 +110,8 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e
110110
handleClusterErrors(clusterErrs, &table)
111111
}
112112
}
113-
if cluster.Kubernetes != nil {
114-
table.AddRow("VERSION", utils.PtrString(cluster.Kubernetes.Version))
113+
if cluster.Kubernetes.Version != "" {
114+
table.AddRow("VERSION", cluster.Kubernetes.Version)
115115
table.AddSeparator()
116116
}
117117

@@ -131,7 +131,7 @@ func handleClusterErrors(clusterErrs []ske.ClusterError, table *tables.Table) {
131131
b := new(strings.Builder)
132132
fmt.Fprint(b, e.GetCode())
133133
if msg, ok := e.GetMessageOk(); ok {
134-
fmt.Fprintf(b, ": %s", msg)
134+
fmt.Fprintf(b, ": %s", *msg)
135135
}
136136
errs = append(errs, b.String())
137137
}

0 commit comments

Comments
 (0)