From 6ee4f5c0f1f563e0a5facf7c24a32e593d4cb434 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 10 Mar 2026 14:55:47 +0100 Subject: [PATCH 1/3] feat(ske): port to v2api version of SDK --- go.mod | 2 +- go.sum | 4 +- internal/cmd/ske/cluster/create/create.go | 12 +- .../cmd/ske/cluster/create/create_test.go | 58 +++---- internal/cmd/ske/cluster/delete/delete.go | 8 +- .../cmd/ske/cluster/delete/delete_test.go | 7 +- internal/cmd/ske/cluster/describe/describe.go | 14 +- .../cmd/ske/cluster/describe/describe_test.go | 31 ++-- .../generate-payload/generate_payload.go | 6 +- .../generate-payload/generate_payload_test.go | 7 +- .../cmd/ske/cluster/hibernate/hibernate.go | 8 +- .../ske/cluster/hibernate/hibernate_test.go | 7 +- internal/cmd/ske/cluster/list/list.go | 16 +- internal/cmd/ske/cluster/list/list_test.go | 7 +- .../ske/cluster/maintenance/maintenance.go | 8 +- .../cluster/maintenance/maintenance_test.go | 7 +- .../cmd/ske/cluster/reconcile/reconcile.go | 8 +- .../ske/cluster/reconcile/reconcile_test.go | 11 +- internal/cmd/ske/cluster/update/update.go | 10 +- .../cmd/ske/cluster/update/update_test.go | 58 +++---- internal/cmd/ske/cluster/wakeup/wakeup.go | 8 +- .../cmd/ske/cluster/wakeup/wakeup_test.go | 9 +- .../complete-rotation/complete_rotation.go | 8 +- .../complete_rotation_test.go | 7 +- .../start-rotation/start_rotation.go | 8 +- .../start-rotation/start_rotation_test.go | 7 +- internal/cmd/ske/kubeconfig/create/create.go | 6 +- .../cmd/ske/kubeconfig/create/create_test.go | 7 +- internal/cmd/ske/kubeconfig/login/login.go | 4 +- .../cmd/ske/kubeconfig/login/login_test.go | 7 +- .../availability_zones/availability_zones.go | 6 +- .../availability_zones_test.go | 13 +- .../kubernetes_versions.go | 6 +- .../kubernetes_versions_test.go | 15 +- .../options/machine_images/machine_images.go | 12 +- .../machine_images/machine_images_test.go | 19 +-- .../options/machine_types/machine_types.go | 6 +- .../machine_types/machine_types_test.go | 25 +-- internal/cmd/ske/options/options.go | 30 ++-- internal/cmd/ske/options/options_test.go | 7 +- .../ske/options/volume_types/volume_types.go | 6 +- .../options/volume_types/volume_types_test.go | 13 +- internal/pkg/services/ske/client/client.go | 2 +- internal/pkg/services/ske/utils/utils.go | 98 ++++++------ internal/pkg/services/ske/utils/utils_test.go | 149 ++++++++---------- 45 files changed, 385 insertions(+), 382 deletions(-) diff --git a/go.mod b/go.mod index 9948b8bcd..3eeeb67c5 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6 github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 - github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0 + github.com/stackitcloud/stackit-sdk-go/services/ske v1.9.0 github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3 github.com/zalando/go-keyring v0.2.6 golang.org/x/mod v0.33.0 diff --git a/go.sum b/go.sum index c6d5e71ed..9f1896727 100644 --- a/go.sum +++ b/go.sum @@ -654,8 +654,8 @@ github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 h1:M2PY github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7/go.mod h1:jitkQuP2K/SH63Qor0C4pcqz1GDCy/lK2H4t8/VDse4= github.com/stackitcloud/stackit-sdk-go/services/sfs v0.4.0 h1:ofdGO2dGH6ywKbIVxaxRVal3jWX9WlcHSm5BTud5bC4= github.com/stackitcloud/stackit-sdk-go/services/sfs v0.4.0/go.mod h1:r5lBwzJpJe2xBIYctkVIIpaZ41Y6vUEpkmsWR2VoQJs= -github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0 h1:l1QjxW7sdE/6B6BZtHxbmus8XJdI9KDuXX3fwUa5fog= -github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0/go.mod h1:1Jr+ImrmPERxbYnlTy6O2aSZYNnREf2qQyysv6YC1RY= +github.com/stackitcloud/stackit-sdk-go/services/ske v1.9.0 h1:pNEIQdUJMP5oMsBV/U9ENGBbzsFedb/3ZRC+Mw7bcYc= +github.com/stackitcloud/stackit-sdk-go/services/ske v1.9.0/go.mod h1:VW6csYWkytVufoiDMquVEdyF0amYICzOzSe6ynRRDsI= github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3 h1:AQrcr+qeIuZob+3TT2q1L4WOPtpsu5SEpkTnOUHDqfE= github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3/go.mod h1:8BBGC69WFXWWmKgzSjgE4HvsI7pEgO0RN2cASwuPJ18= github.com/stbenjam/no-sprintf-host-port v0.3.1 h1:AyX7+dxI4IdLBPtDbsGAyqiTSLpCP9hWRrXQDU4Cm/g= diff --git a/internal/cmd/ske/cluster/create/create.go b/internal/cmd/ske/cluster/create/create.go index 1602e3680..faca273bb 100644 --- a/internal/cmd/ske/cluster/create/create.go +++ b/internal/cmd/ske/cluster/create/create.go @@ -21,8 +21,8 @@ import ( skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -106,7 +106,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Check if cluster exists - exists, err := skeUtils.ClusterExists(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName) + exists, err := skeUtils.ClusterExists(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName) if err != nil { return err } @@ -116,7 +116,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Fill in default payload, if needed if model.Payload == nil { - defaultPayload, err := skeUtils.GetDefaultPayload(ctx, apiClient, model.Region) + defaultPayload, err := skeUtils.GetDefaultPayload(ctx, apiClient.DefaultAPI, model.Region) if err != nil { return fmt.Errorf("get default payload: %w", err) } @@ -135,7 +135,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Creating cluster") - _, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient, model.ProjectId, model.Region, name).WaitWithContext(ctx) + _, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, name).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster creation: %w", err) } @@ -182,7 +182,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiCreateOrUpdateClusterRequest { - req := apiClient.CreateOrUpdateCluster(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.CreateOrUpdateCluster(ctx, model.ProjectId, model.Region, model.ClusterName) req = req.CreateOrUpdateClusterPayload(*model.Payload) return req diff --git a/internal/cmd/ske/cluster/create/create_test.go b/internal/cmd/ske/cluster/create/create_test.go index 99392a63d..1093081ca 100644 --- a/internal/cmd/ske/cluster/create/create_test.go +++ b/internal/cmd/ske/cluster/create/create_test.go @@ -2,7 +2,6 @@ package create import ( "context" - "fmt" "testing" "time" @@ -17,7 +16,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -25,51 +24,51 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" const testRegion = "eu01" var testPayload = &ske.CreateOrUpdateClusterPayload{ - Kubernetes: &ske.Kubernetes{ - Version: utils.Ptr("1.25.15"), + Kubernetes: ske.Kubernetes{ + Version: "1.25.15", }, - Nodepools: &[]ske.Nodepool{ + Nodepools: []ske.Nodepool{ { - Name: utils.Ptr("np-name"), - Machine: &ske.Machine{ - Image: &ske.Image{ - Name: utils.Ptr("flatcar"), - Version: utils.Ptr("3760.2.1"), + Name: "np-name", + Machine: ske.Machine{ + Image: ske.Image{ + Name: "flatcar", + Version: "3760.2.1", }, - Type: utils.Ptr("b1.2"), + Type: "b1.2", }, - Minimum: utils.Ptr(int64(1)), - Maximum: utils.Ptr(int64(2)), - MaxSurge: utils.Ptr(int64(1)), - Volume: &ske.Volume{ + Minimum: int32(1), + Maximum: int32(2), + MaxSurge: utils.Ptr(int32(1)), + Volume: ske.Volume{ Type: utils.Ptr("storage_premium_perf0"), - Size: utils.Ptr(int64(40)), + Size: int32(40), }, - AvailabilityZones: &[]string{"eu01-3"}, - Cri: &ske.CRI{Name: ske.CRINAME_DOCKER.Ptr()}, + AvailabilityZones: []string{"eu01-3"}, + Cri: &ske.CRI{Name: utils.Ptr("containerd")}, }, }, Extensions: &ske.Extension{ Acl: &ske.ACL{ - Enabled: utils.Ptr(true), - AllowedCidrs: &[]string{"0.0.0.0/0"}, + Enabled: true, + AllowedCidrs: []string{"0.0.0.0/0"}, }, }, Maintenance: &ske.Maintenance{ - AutoUpdate: &ske.MaintenanceAutoUpdate{ + AutoUpdate: ske.MaintenanceAutoUpdate{ KubernetesVersion: utils.Ptr(true), MachineImageVersion: utils.Ptr(true), }, - TimeWindow: &ske.TimeWindow{ - End: utils.Ptr(time.Date(0, 1, 1, 5, 0, 0, 0, time.FixedZone("test-zone", 2*60*60))), - Start: utils.Ptr(time.Date(0, 1, 1, 3, 0, 0, 0, time.FixedZone("test-zone", 2*60*60))), + TimeWindow: ske.TimeWindow{ + End: time.Date(0, 1, 1, 5, 0, 0, 0, time.FixedZone("test-zone", 2*60*60)), + Start: time.Date(0, 1, 1, 3, 0, 0, 0, time.FixedZone("test-zone", 2*60*60)), }, }, } @@ -88,7 +87,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st flagValues := map[string]string{ globalflags.ProjectIdFlag: testProjectId, globalflags.RegionFlag: testRegion, - payloadFlag: fmt.Sprintf(`{ + payloadFlag: `{ "name": "cli-jp", "kubernetes": { "version": "1.25.15" @@ -107,7 +106,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st "maximum": 2, "maxSurge": 1, "volume": { "type": "storage_premium_perf0", "size": 40 }, - "cri": { "name": "%s" }, + "cri": { "name": "containerd" }, "availabilityZones": ["eu01-3"] } ], @@ -122,7 +121,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st "start": "0000-01-01T03:00:00+02:00" } } - }`, ske.CRINAME_DOCKER), + }`, } for _, mod := range mods { mod(flagValues) @@ -147,7 +146,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiCreateOrUpdateClusterRequest)) ske.ApiCreateOrUpdateClusterRequest { - request := testClient.CreateOrUpdateCluster(testCtx, testProjectId, testRegion, fixtureInputModel().ClusterName) + request := testClient.DefaultAPI.CreateOrUpdateCluster(testCtx, testProjectId, testRegion, fixtureInputModel().ClusterName) request = request.CreateOrUpdateClusterPayload(*testPayload) for _, mod := range mods { mod(&request) @@ -262,6 +261,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/cluster/delete/delete.go b/internal/cmd/ske/cluster/delete/delete.go index 34de6f2c7..f172b495b 100644 --- a/internal/cmd/ske/cluster/delete/delete.go +++ b/internal/cmd/ske/cluster/delete/delete.go @@ -15,8 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Deleting cluster") - _, err = wait.DeleteClusterWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.DeleteClusterWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster deletion: %w", err) } @@ -105,6 +105,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiDeleteClusterRequest { - req := apiClient.DeleteCluster(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.DeleteCluster(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/cluster/delete/delete_test.go b/internal/cmd/ske/cluster/delete/delete_test.go index 86cef5d06..182af1949 100644 --- a/internal/cmd/ske/cluster/delete/delete_test.go +++ b/internal/cmd/ske/cluster/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -18,7 +18,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiDeleteClusterRequest)) ske.ApiDeleteClusterRequest { - request := testClient.DeleteCluster(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.DeleteCluster(testCtx, testProjectId, testRegion, testClusterName) for _, mod := range mods { mod(&request) } @@ -156,6 +156,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/cluster/describe/describe.go b/internal/cmd/ske/cluster/describe/describe.go index 3e94fa9d9..c66afaaa3 100644 --- a/internal/cmd/ske/cluster/describe/describe.go +++ b/internal/cmd/ske/cluster/describe/describe.go @@ -16,7 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -85,7 +85,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiGetClusterRequest { - req := apiClient.GetCluster(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.GetCluster(ctx, model.ProjectId, model.Region, model.ClusterName) return req } @@ -97,11 +97,11 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e return p.OutputResult(outputFormat, cluster, func() error { acl := []string{} if cluster.Extensions != nil && cluster.Extensions.Acl != nil { - acl = *cluster.Extensions.Acl.AllowedCidrs + acl = cluster.Extensions.Acl.AllowedCidrs } table := tables.NewTable() - table.AddRow("NAME", utils.PtrString(cluster.Name)) + table.AddRow("NAME", cluster.Name) table.AddSeparator() if cluster.HasStatus() { table.AddRow("STATE", utils.PtrString(cluster.Status.Aggregated)) @@ -110,8 +110,8 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e handleClusterErrors(clusterErrs, &table) } } - if cluster.Kubernetes != nil { - table.AddRow("VERSION", utils.PtrString(cluster.Kubernetes.Version)) + if cluster.Kubernetes.Version != "" { + table.AddRow("VERSION", cluster.Kubernetes.Version) table.AddSeparator() } @@ -131,7 +131,7 @@ func handleClusterErrors(clusterErrs []ske.ClusterError, table *tables.Table) { b := new(strings.Builder) fmt.Fprint(b, e.GetCode()) if msg, ok := e.GetMessageOk(); ok { - fmt.Fprintf(b, ": %s", msg) + fmt.Fprintf(b, ": %s", *msg) } errs = append(errs, b.String()) } diff --git a/internal/cmd/ske/cluster/describe/describe_test.go b/internal/cmd/ske/cluster/describe/describe_test.go index 3049998fe..026a1405e 100644 --- a/internal/cmd/ske/cluster/describe/describe_test.go +++ b/internal/cmd/ske/cluster/describe/describe_test.go @@ -14,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -22,7 +22,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" @@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiGetClusterRequest)) ske.ApiGetClusterRequest { - request := testClient.GetCluster(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.GetCluster(testCtx, testProjectId, testRegion, testClusterName) for _, mod := range mods { mod(&request) } @@ -160,6 +160,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -197,7 +198,7 @@ func TestOutputResult(t *testing.T) { cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), Message: utils.Ptr("Network configuration not found"), @@ -215,7 +216,7 @@ func TestOutputResult(t *testing.T) { cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), Message: utils.Ptr("Network configuration not found"), @@ -241,7 +242,7 @@ func TestOutputResult(t *testing.T) { cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_FETCHING_ERRORS_NOT_POSSIBLE"), }, @@ -271,7 +272,7 @@ func TestOutputResult(t *testing.T) { cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{}, + Errors: []ske.ClusterError{}, }, }, }, @@ -294,7 +295,7 @@ func TestOutputResult(t *testing.T) { cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), Message: utils.Ptr("Network configuration not found"), @@ -312,7 +313,7 @@ func TestOutputResult(t *testing.T) { cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), Message: utils.Ptr("Network configuration not found"), @@ -329,11 +330,11 @@ func TestOutputResult(t *testing.T) { outputFormat: "", cluster: &ske.Cluster{ Name: utils.Ptr("test-cluster"), - Kubernetes: &ske.Kubernetes{ - Version: utils.Ptr("1.28.0"), + Kubernetes: ske.Kubernetes{ + Version: "1.28.0", }, Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), Message: utils.Ptr("Network configuration not found"), @@ -352,12 +353,12 @@ func TestOutputResult(t *testing.T) { Name: utils.Ptr("test-cluster"), Extensions: &ske.Extension{ Acl: &ske.ACL{ - AllowedCidrs: &[]string{"10.0.0.0/8"}, - Enabled: utils.Ptr(true), + AllowedCidrs: []string{"10.0.0.0/8"}, + Enabled: true, }, }, Status: &ske.ClusterStatus{ - Errors: &[]ske.ClusterError{ + Errors: []ske.ClusterError{ { Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), Message: utils.Ptr("Network configuration not found"), diff --git a/internal/cmd/ske/cluster/generate-payload/generate_payload.go b/internal/cmd/ske/cluster/generate-payload/generate_payload.go index 5afa14cf8..80f36394a 100644 --- a/internal/cmd/ske/cluster/generate-payload/generate_payload.go +++ b/internal/cmd/ske/cluster/generate-payload/generate_payload.go @@ -18,7 +18,7 @@ import ( skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { var payload *ske.CreateOrUpdateClusterPayload if model.ClusterName == nil { - payload, err = skeUtils.GetDefaultPayload(ctx, apiClient, model.Region) + payload, err = skeUtils.GetDefaultPayload(ctx, apiClient.DefaultAPI, model.Region) if err != nil { return err } @@ -123,7 +123,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiGetClusterRequest { - req := apiClient.GetCluster(ctx, model.ProjectId, model.Region, *model.ClusterName) + req := apiClient.DefaultAPI.GetCluster(ctx, model.ProjectId, model.Region, *model.ClusterName) return req } diff --git a/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go b/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go index 97f0aa013..16c1ad392 100644 --- a/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go +++ b/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go @@ -14,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -22,7 +22,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() const ( @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiGetClusterRequest)) ske.ApiGetClusterRequest { - request := testClient.GetCluster(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.GetCluster(testCtx, testProjectId, testRegion, testClusterName) for _, mod := range mods { mod(&request) } @@ -162,6 +162,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/cluster/hibernate/hibernate.go b/internal/cmd/ske/cluster/hibernate/hibernate.go index 5e679e38b..259ae868f 100644 --- a/internal/cmd/ske/cluster/hibernate/hibernate.go +++ b/internal/cmd/ske/cluster/hibernate/hibernate.go @@ -15,8 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Hibernating cluster") - _, err = wait.TriggerClusterHibernationWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.TriggerClusterHibernationWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster hibernation: %w", err) } @@ -110,6 +110,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiTriggerHibernateRequest { - req := apiClient.TriggerHibernate(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.TriggerHibernate(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/cluster/hibernate/hibernate_test.go b/internal/cmd/ske/cluster/hibernate/hibernate_test.go index d9d531ef1..dfdeb5c10 100644 --- a/internal/cmd/ske/cluster/hibernate/hibernate_test.go +++ b/internal/cmd/ske/cluster/hibernate/hibernate_test.go @@ -11,7 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} @@ -22,7 +22,7 @@ const ( ) var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiTriggerHibernateRequest)) ske.ApiTriggerHibernateRequest { - request := testClient.TriggerHibernate(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.TriggerHibernate(testCtx, testProjectId, testRegion, testClusterName) for _, mod := range mods { mod(&request) } @@ -177,6 +177,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmpopts.EquateComparable(testCtx), cmp.AllowUnexported(tt.expectedRequest), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("request mismatch:\n%s", diff) diff --git a/internal/cmd/ske/cluster/list/list.go b/internal/cmd/ske/cluster/list/list.go index b1fa9f024..054c4f508 100644 --- a/internal/cmd/ske/cluster/list/list.go +++ b/internal/cmd/ske/cluster/list/list.go @@ -20,7 +20,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -83,7 +83,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("get SKE clusters: %w", err) } - clusters := *resp.Items + clusters := resp.Items // Truncate output if model.Limit != nil && len(clusters) > int(*model.Limit) { @@ -134,7 +134,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiListClustersRequest { - req := apiClient.ListClusters(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListClusters(ctx, model.ProjectId, model.Region) return req } @@ -150,19 +150,17 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, clusters for i := range clusters { c := clusters[i] monitoring := "Disabled" - if c.Extensions != nil && c.Extensions.Observability != nil && *c.Extensions.Observability.Enabled { + if c.Extensions != nil && c.Extensions.Observability != nil && c.Extensions.Observability.Enabled { monitoring = "Enabled" } - statusAggregated, kubernetesVersion := "", "" + statusAggregated := "" if c.HasStatus() { statusAggregated = utils.PtrString(c.Status.Aggregated) } - if c.Kubernetes != nil { - kubernetesVersion = utils.PtrString(c.Kubernetes.Version) - } + kubernetesVersion := c.Kubernetes.Version countNodepools := 0 if c.Nodepools != nil { - countNodepools = len(*c.Nodepools) + countNodepools = len(c.Nodepools) } table.AddRow( utils.PtrString(c.Name), diff --git a/internal/cmd/ske/cluster/list/list_test.go b/internal/cmd/ske/cluster/list/list_test.go index 2b123dba0..a40ad6984 100644 --- a/internal/cmd/ske/cluster/list/list_test.go +++ b/internal/cmd/ske/cluster/list/list_test.go @@ -14,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -22,7 +22,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() const testRegion = "eu01" @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiListClustersRequest)) ske.ApiListClustersRequest { - request := testClient.ListClusters(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListClusters(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -145,6 +145,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/cluster/maintenance/maintenance.go b/internal/cmd/ske/cluster/maintenance/maintenance.go index 0b5f406ca..8fda38bb6 100644 --- a/internal/cmd/ske/cluster/maintenance/maintenance.go +++ b/internal/cmd/ske/cluster/maintenance/maintenance.go @@ -15,8 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Performing cluster maintenance") - _, err = wait.TriggerClusterMaintenanceWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.TriggerClusterMaintenanceWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster maintenance to complete: %w", err) } @@ -110,6 +110,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiTriggerMaintenanceRequest { - req := apiClient.TriggerMaintenance(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.TriggerMaintenance(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/cluster/maintenance/maintenance_test.go b/internal/cmd/ske/cluster/maintenance/maintenance_test.go index fe0ab07cb..b174d4c1d 100644 --- a/internal/cmd/ske/cluster/maintenance/maintenance_test.go +++ b/internal/cmd/ske/cluster/maintenance/maintenance_test.go @@ -11,7 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} @@ -22,7 +22,7 @@ const ( ) var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureArgValues(mods ...func([]string)) []string { @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(*inputModel)) *inputModel { } func fixtureRequest(mods ...func(*ske.ApiTriggerMaintenanceRequest)) ske.ApiTriggerMaintenanceRequest { - request := testClient.TriggerMaintenance(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.TriggerMaintenance(testCtx, testProjectId, testRegion, testClusterName) for _, m := range mods { m(&request) } @@ -178,6 +178,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(got, want, cmpopts.EquateComparable(testCtx), cmp.AllowUnexported(want), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("request mismatch:\n%s", diff) diff --git a/internal/cmd/ske/cluster/reconcile/reconcile.go b/internal/cmd/ske/cluster/reconcile/reconcile.go index 0108ae568..faf3e6da5 100644 --- a/internal/cmd/ske/cluster/reconcile/reconcile.go +++ b/internal/cmd/ske/cluster/reconcile/reconcile.go @@ -14,8 +14,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -62,7 +62,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Performing cluster reconciliation") - _, err = wait.TriggerClusterReconciliationWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.TriggerClusterReconciliationWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster reconciliation: %w", err) } @@ -98,6 +98,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiTriggerReconcileRequest { - req := apiClient.TriggerReconcile(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.TriggerReconcile(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/cluster/reconcile/reconcile_test.go b/internal/cmd/ske/cluster/reconcile/reconcile_test.go index 5c96f295b..500c408e5 100644 --- a/internal/cmd/ske/cluster/reconcile/reconcile_test.go +++ b/internal/cmd/ske/cluster/reconcile/reconcile_test.go @@ -11,7 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} @@ -22,7 +22,7 @@ const ( ) var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureArgValues(mods ...func([]string)) []string { @@ -61,8 +61,8 @@ func fixtureInputModel(mods ...func(*inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *ske.ApiTriggerReconcileRequest)) ske.ApiTriggerHibernateRequest { - request := testClient.TriggerReconcile(testCtx, testProjectId, testRegion, testClusterName) +func fixtureRequest(mods ...func(request *ske.ApiTriggerReconcileRequest)) ske.ApiTriggerReconcileRequest { + request := testClient.DefaultAPI.TriggerReconcile(testCtx, testProjectId, testRegion, testClusterName) for _, m := range mods { m(&request) } @@ -161,7 +161,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest ske.ApiTriggerHibernateRequest + expectedRequest ske.ApiTriggerReconcileRequest }{ { description: "base", @@ -178,6 +178,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(got, want, cmpopts.EquateComparable(testCtx), cmp.AllowUnexported(want), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("request mismatch:\n%s", diff) diff --git a/internal/cmd/ske/cluster/update/update.go b/internal/cmd/ske/cluster/update/update.go index 6150a9bda..7abd56eb1 100644 --- a/internal/cmd/ske/cluster/update/update.go +++ b/internal/cmd/ske/cluster/update/update.go @@ -18,8 +18,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -77,7 +77,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Check if cluster exists - exists, err := skeUtils.ClusterExists(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName) + exists, err := skeUtils.ClusterExists(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName) if err != nil { return err } @@ -97,7 +97,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Updating cluster") - _, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient, model.ProjectId, model.Region, name).WaitWithContext(ctx) + _, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, name).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster update: %w", err) } @@ -144,7 +144,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiCreateOrUpdateClusterRequest { - req := apiClient.CreateOrUpdateCluster(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.CreateOrUpdateCluster(ctx, model.ProjectId, model.Region, model.ClusterName) req = req.CreateOrUpdateClusterPayload(model.Payload) return req diff --git a/internal/cmd/ske/cluster/update/update_test.go b/internal/cmd/ske/cluster/update/update_test.go index e4a28fb91..f76f1a88a 100644 --- a/internal/cmd/ske/cluster/update/update_test.go +++ b/internal/cmd/ske/cluster/update/update_test.go @@ -2,7 +2,6 @@ package update import ( "context" - "fmt" "testing" "time" @@ -16,7 +15,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -24,51 +23,51 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" const testRegion = "eu01" var testPayload = ske.CreateOrUpdateClusterPayload{ - Kubernetes: &ske.Kubernetes{ - Version: utils.Ptr("1.25.15"), + Kubernetes: ske.Kubernetes{ + Version: "1.25.15", }, - Nodepools: &[]ske.Nodepool{ + Nodepools: []ske.Nodepool{ { - Name: utils.Ptr("np-name"), - Machine: &ske.Machine{ - Image: &ske.Image{ - Name: utils.Ptr("flatcar"), - Version: utils.Ptr("3760.2.1"), + Name: "np-name", + Machine: ske.Machine{ + Image: ske.Image{ + Name: "flatcar", + Version: "3760.2.1", }, - Type: utils.Ptr("b1.2"), + Type: "b1.2", }, - Minimum: utils.Ptr(int64(1)), - Maximum: utils.Ptr(int64(2)), - MaxSurge: utils.Ptr(int64(1)), - Volume: &ske.Volume{ + Minimum: int32(1), + Maximum: int32(2), + MaxSurge: utils.Ptr(int32(1)), + Volume: ske.Volume{ Type: utils.Ptr("storage_premium_perf0"), - Size: utils.Ptr(int64(40)), + Size: int32(40), }, - AvailabilityZones: &[]string{"eu01-3"}, - Cri: &ske.CRI{Name: ske.CRINAME_DOCKER.Ptr()}, + AvailabilityZones: []string{"eu01-3"}, + Cri: &ske.CRI{Name: utils.Ptr("containerd")}, }, }, Extensions: &ske.Extension{ Acl: &ske.ACL{ - Enabled: utils.Ptr(true), - AllowedCidrs: &[]string{"0.0.0.0/0"}, + Enabled: true, + AllowedCidrs: []string{"0.0.0.0/0"}, }, }, Maintenance: &ske.Maintenance{ - AutoUpdate: &ske.MaintenanceAutoUpdate{ + AutoUpdate: ske.MaintenanceAutoUpdate{ KubernetesVersion: utils.Ptr(true), MachineImageVersion: utils.Ptr(true), }, - TimeWindow: &ske.TimeWindow{ - End: utils.Ptr(time.Date(0, 1, 1, 5, 0, 0, 0, time.FixedZone("test-zone", 2*60*60))), - Start: utils.Ptr(time.Date(0, 1, 1, 3, 0, 0, 0, time.FixedZone("test-zone", 2*60*60))), + TimeWindow: ske.TimeWindow{ + End: time.Date(0, 1, 1, 5, 0, 0, 0, time.FixedZone("test-zone", 2*60*60)), + Start: time.Date(0, 1, 1, 3, 0, 0, 0, time.FixedZone("test-zone", 2*60*60)), }, }, } @@ -87,7 +86,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st flagValues := map[string]string{ globalflags.ProjectIdFlag: testProjectId, globalflags.RegionFlag: testRegion, - payloadFlag: fmt.Sprintf(`{ + payloadFlag: `{ "name": "cli-jp", "kubernetes": { "version": "1.25.15" @@ -106,7 +105,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st "maximum": 2, "maxSurge": 1, "volume": { "type": "storage_premium_perf0", "size": 40 }, - "cri": { "name": "%s" }, + "cri": { "name": "containerd" }, "availabilityZones": ["eu01-3"] } ], @@ -121,7 +120,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st "start": "0000-01-01T03:00:00+02:00" } } - }`, ske.CRINAME_DOCKER), + }`, } for _, mod := range mods { mod(flagValues) @@ -146,7 +145,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiCreateOrUpdateClusterRequest)) ske.ApiCreateOrUpdateClusterRequest { - request := testClient.CreateOrUpdateCluster(testCtx, testProjectId, testRegion, fixtureInputModel().ClusterName) + request := testClient.DefaultAPI.CreateOrUpdateCluster(testCtx, testProjectId, testRegion, fixtureInputModel().ClusterName) request = request.CreateOrUpdateClusterPayload(testPayload) for _, mod := range mods { mod(&request) @@ -249,6 +248,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/cluster/wakeup/wakeup.go b/internal/cmd/ske/cluster/wakeup/wakeup.go index 64b0e5ccf..44b1d976f 100644 --- a/internal/cmd/ske/cluster/wakeup/wakeup.go +++ b/internal/cmd/ske/cluster/wakeup/wakeup.go @@ -14,8 +14,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -62,7 +62,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Performing cluster wakeup") - _, err = wait.TriggerClusterWakeupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.TriggerClusterWakeupWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for SKE cluster wakeup: %w", err) } @@ -98,6 +98,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiTriggerWakeupRequest { - req := apiClient.TriggerWakeup(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.TriggerWakeup(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/cluster/wakeup/wakeup_test.go b/internal/cmd/ske/cluster/wakeup/wakeup_test.go index dd93881c1..0caf850d0 100644 --- a/internal/cmd/ske/cluster/wakeup/wakeup_test.go +++ b/internal/cmd/ske/cluster/wakeup/wakeup_test.go @@ -11,7 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} @@ -22,7 +22,7 @@ const ( ) var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureArgValues(mods ...func([]string)) []string { @@ -60,7 +60,7 @@ func fixtureInputModel(mods ...func(*inputModel)) *inputModel { } func fixtureRequest(mods ...func(*ske.ApiTriggerWakeupRequest)) ske.ApiTriggerWakeupRequest { - req := testClient.TriggerWakeup(testCtx, testProjectId, testRegion, testClusterName) + req := testClient.DefaultAPI.TriggerWakeup(testCtx, testProjectId, testRegion, testClusterName) for _, m := range mods { m(&req) } @@ -159,7 +159,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest ske.ApiTriggerHibernateRequest + expectedRequest ske.ApiTriggerWakeupRequest }{ { description: "base", @@ -176,6 +176,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(got, want, cmpopts.EquateComparable(testCtx), cmp.AllowUnexported(want), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("request mismatch:\n%s", diff) diff --git a/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go b/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go index 25f2601aa..a4a5d53af 100644 --- a/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go +++ b/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go @@ -15,8 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -86,7 +86,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Completing credentials rotation") - _, err = wait.CompleteCredentialsRotationWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.CompleteCredentialsRotationWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for completing SKE credentials rotation %w", err) } @@ -123,6 +123,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiCompleteCredentialsRotationRequest { - req := apiClient.CompleteCredentialsRotation(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.CompleteCredentialsRotation(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go b/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go index ee40fc120..9ef9dc2f8 100644 --- a/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go +++ b/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -18,7 +18,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiCompleteCredentialsRotationRequest)) ske.ApiCompleteCredentialsRotationRequest { - request := testClient.CompleteCredentialsRotation(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.CompleteCredentialsRotation(testCtx, testProjectId, testRegion, testClusterName) for _, mod := range mods { mod(&request) } @@ -154,6 +154,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/credentials/start-rotation/start_rotation.go b/internal/cmd/ske/credentials/start-rotation/start_rotation.go index 3cb3cee55..b2daa7c87 100644 --- a/internal/cmd/ske/credentials/start-rotation/start_rotation.go +++ b/internal/cmd/ske/credentials/start-rotation/start_rotation.go @@ -15,8 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" - "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api/wait" ) const ( @@ -89,7 +89,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Starting credentials rotation") - _, err = wait.StartCredentialsRotationWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) + _, err = wait.StartCredentialsRotationWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ClusterName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for start SKE credentials rotation %w", err) } @@ -126,6 +126,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiStartCredentialsRotationRequest { - req := apiClient.StartCredentialsRotation(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.StartCredentialsRotation(ctx, model.ProjectId, model.Region, model.ClusterName) return req } diff --git a/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go b/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go index 063269174..e3fae33d2 100644 --- a/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go +++ b/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -18,7 +18,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiStartCredentialsRotationRequest)) ske.ApiStartCredentialsRotationRequest { - request := testClient.StartCredentialsRotation(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.StartCredentialsRotation(testCtx, testProjectId, testRegion, testClusterName) for _, mod := range mods { mod(&request) } @@ -154,6 +154,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/kubeconfig/create/create.go b/internal/cmd/ske/kubeconfig/create/create.go index 355364098..bff2dfa18 100644 --- a/internal/cmd/ske/kubeconfig/create/create.go +++ b/internal/cmd/ske/kubeconfig/create/create.go @@ -19,7 +19,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -221,7 +221,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequestCreate(ctx context.Context, model *inputModel, apiClient *ske.APIClient) (ske.ApiCreateKubeconfigRequest, error) { - req := apiClient.CreateKubeconfig(ctx, model.ProjectId, model.Region, model.ClusterName) + req := apiClient.DefaultAPI.CreateKubeconfig(ctx, model.ProjectId, model.Region, model.ClusterName) payload := ske.CreateKubeconfigPayload{} @@ -233,7 +233,7 @@ func buildRequestCreate(ctx context.Context, model *inputModel, apiClient *ske.A } func buildRequestLogin(ctx context.Context, model *inputModel, apiClient *ske.APIClient) (ske.ApiGetLoginKubeconfigRequest, error) { - return apiClient.GetLoginKubeconfig(ctx, model.ProjectId, model.Region, model.ClusterName), nil + return apiClient.DefaultAPI.GetLoginKubeconfig(ctx, model.ProjectId, model.Region, model.ClusterName), nil } func outputResult(p *print.Printer, outputFormat, clusterName, kubeconfigPath string, respKubeconfig *ske.Kubeconfig, respLogin *ske.LoginKubeconfig) error { diff --git a/internal/cmd/ske/kubeconfig/create/create_test.go b/internal/cmd/ske/kubeconfig/create/create_test.go index f8e826064..af09214f3 100644 --- a/internal/cmd/ske/kubeconfig/create/create_test.go +++ b/internal/cmd/ske/kubeconfig/create/create_test.go @@ -13,7 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -21,7 +21,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" @@ -64,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *ske.ApiCreateKubeconfigRequest)) ske.ApiCreateKubeconfigRequest { - request := testClient.CreateKubeconfig(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.CreateKubeconfig(testCtx, testProjectId, testRegion, testClusterName) request = request.CreateKubeconfigPayload(ske.CreateKubeconfigPayload{}) for _, mod := range mods { mod(&request) @@ -242,6 +242,7 @@ func TestBuildRequestCreate(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/kubeconfig/login/login.go b/internal/cmd/ske/kubeconfig/login/login.go index fcd121bc9..2d2c88070 100644 --- a/internal/cmd/ske/kubeconfig/login/login.go +++ b/internal/cmd/ske/kubeconfig/login/login.go @@ -31,7 +31,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -248,7 +248,7 @@ func requestNewLoginKubeconfig(ctx context.Context, apiClient *ske.APIClient, cl } func buildLoginKubeconfigRequest(ctx context.Context, apiClient *ske.APIClient, clusterConfig *clusterConfig) ske.ApiCreateKubeconfigRequest { - req := apiClient.CreateKubeconfig(ctx, clusterConfig.STACKITProjectID, clusterConfig.Region, clusterConfig.ClusterName) + req := apiClient.DefaultAPI.CreateKubeconfig(ctx, clusterConfig.STACKITProjectID, clusterConfig.Region, clusterConfig.ClusterName) expirationSeconds := strconv.Itoa(expirationSeconds) return req.CreateKubeconfigPayload(ske.CreateKubeconfigPayload{ExpirationSeconds: &expirationSeconds}) diff --git a/internal/cmd/ske/kubeconfig/login/login_test.go b/internal/cmd/ske/kubeconfig/login/login_test.go index 4f2fc4a3a..cf9c3a756 100644 --- a/internal/cmd/ske/kubeconfig/login/login_test.go +++ b/internal/cmd/ske/kubeconfig/login/login_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientauthenticationv1 "k8s.io/client-go/pkg/apis/clientauthentication/v1" "k8s.io/client-go/rest" @@ -20,7 +20,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} var testProjectId = uuid.NewString() var testClusterName = "cluster" var testOrganization = uuid.NewString() @@ -42,7 +42,7 @@ func fixtureClusterConfig(mods ...func(clusterConfig *clusterConfig)) *clusterCo } func fixtureLoginRequest(mods ...func(request *ske.ApiCreateKubeconfigRequest)) ske.ApiCreateKubeconfigRequest { - request := testClient.CreateKubeconfig(testCtx, testProjectId, testRegion, testClusterName) + request := testClient.DefaultAPI.CreateKubeconfig(testCtx, testProjectId, testRegion, testClusterName) request = request.CreateKubeconfigPayload(ske.CreateKubeconfigPayload{}) for _, mod := range mods { mod(&request) @@ -71,6 +71,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/options/availability_zones/availability_zones.go b/internal/cmd/ske/options/availability_zones/availability_zones.go index bef599ad4..0b50574b2 100644 --- a/internal/cmd/ske/options/availability_zones/availability_zones.go +++ b/internal/cmd/ske/options/availability_zones/availability_zones.go @@ -14,7 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type inputModel struct { @@ -70,7 +70,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest { - req := apiClient.ListProviderOptions(ctx, model.Region) + req := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region) return req } @@ -85,7 +85,7 @@ func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOpti options.VolumeTypes = nil return p.OutputResult(model.OutputFormat, options, func() error { - zones := utils.PtrValue(options.AvailabilityZones) + zones := options.AvailabilityZones table := tables.NewTable() table.SetHeader("ZONE") diff --git a/internal/cmd/ske/options/availability_zones/availability_zones_test.go b/internal/cmd/ske/options/availability_zones/availability_zones_test.go index e66bca441..03229b4cf 100644 --- a/internal/cmd/ske/options/availability_zones/availability_zones_test.go +++ b/internal/cmd/ske/options/availability_zones/availability_zones_test.go @@ -13,13 +13,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} const testRegion = "eu01" @@ -86,7 +86,7 @@ func TestBuildRequest(t *testing.T) { { description: "base", inputModel: fixtureInputModel(), - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion), }, } @@ -97,6 +97,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -154,7 +155,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - AvailabilityZones: &[]ske.AvailabilityZone{}, + AvailabilityZones: []ske.AvailabilityZone{}, }, }, wantErr: false, @@ -166,7 +167,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - AvailabilityZones: &[]ske.AvailabilityZone{{}}, + AvailabilityZones: []ske.AvailabilityZone{{}}, }, }, wantErr: false, @@ -178,7 +179,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - AvailabilityZones: &[]ske.AvailabilityZone{ + AvailabilityZones: []ske.AvailabilityZone{ { Name: utils.Ptr("zone1"), }, diff --git a/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions.go b/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions.go index f7e0b8ab2..afe03bd2e 100644 --- a/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions.go +++ b/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions.go @@ -17,7 +17,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -87,7 +87,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest { - req := apiClient.ListProviderOptions(ctx, model.Region) + req := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region) if model.Supported { req = req.VersionState("SUPPORTED") } @@ -105,7 +105,7 @@ func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOpti options.VolumeTypes = nil return p.OutputResult(model.OutputFormat, options, func() error { - versions := utils.PtrValue(options.KubernetesVersions) + versions := options.KubernetesVersions table := tables.NewTable() table.SetHeader("VERSION", "STATE", "EXPIRATION DATE", "FEATURE GATES") diff --git a/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions_test.go b/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions_test.go index f8c7bd3c4..54f246933 100644 --- a/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions_test.go +++ b/internal/cmd/ske/options/kubernetes_versions/kubernetes_versions_test.go @@ -14,13 +14,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} const testRegion = "eu01" @@ -100,14 +100,14 @@ func TestBuildRequest(t *testing.T) { { description: "base", inputModel: fixtureInputModel(), - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion), }, { description: "base", inputModel: fixtureInputModel(func(model *inputModel) { model.Supported = true }), - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion).VersionState("SUPPORTED"), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion).VersionState("SUPPORTED"), }, } @@ -118,6 +118,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -175,7 +176,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - KubernetesVersions: &[]ske.KubernetesVersion{}, + KubernetesVersions: []ske.KubernetesVersion{}, }, }, wantErr: false, @@ -187,7 +188,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - KubernetesVersions: &[]ske.KubernetesVersion{{}}, + KubernetesVersions: []ske.KubernetesVersion{{}}, }, }, wantErr: false, @@ -199,7 +200,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - KubernetesVersions: &[]ske.KubernetesVersion{ + KubernetesVersions: []ske.KubernetesVersion{ { FeatureGates: &map[string]string{ "featureGate1": "foo", diff --git a/internal/cmd/ske/options/machine_images/machine_images.go b/internal/cmd/ske/options/machine_images/machine_images.go index 19eae47d5..4c7c9523a 100644 --- a/internal/cmd/ske/options/machine_images/machine_images.go +++ b/internal/cmd/ske/options/machine_images/machine_images.go @@ -16,7 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type inputModel struct { @@ -72,7 +72,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest { - req := apiClient.ListProviderOptions(ctx, model.Region) + req := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region) return req } @@ -87,18 +87,18 @@ func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOpti options.VolumeTypes = nil return p.OutputResult(model.OutputFormat, options, func() error { - images := utils.PtrValue(options.MachineImages) + images := options.MachineImages table := tables.NewTable() table.SetHeader("NAME", "VERSION", "STATE", "EXPIRATION DATE", "SUPPORTED CRI") for i := range images { image := images[i] - versions := utils.PtrValue(image.Versions) + versions := image.Versions for j := range versions { version := versions[j] criNames := make([]string, 0) - for i := range utils.PtrValue(version.Cri) { - cri := utils.PtrValue(version.Cri)[i] + for i := range version.Cri { + cri := version.Cri[i] criNames = append(criNames, utils.PtrString(cri.Name)) } criNamesString := strings.Join(criNames, ", ") diff --git a/internal/cmd/ske/options/machine_images/machine_images_test.go b/internal/cmd/ske/options/machine_images/machine_images_test.go index e1f073b26..ad4658757 100644 --- a/internal/cmd/ske/options/machine_images/machine_images_test.go +++ b/internal/cmd/ske/options/machine_images/machine_images_test.go @@ -14,13 +14,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} const testRegion = "eu01" @@ -87,7 +87,7 @@ func TestBuildRequest(t *testing.T) { { description: "base", inputModel: fixtureInputModel(), - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion), }, } @@ -98,6 +98,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -155,7 +156,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - MachineImages: &[]ske.MachineImage{}, + MachineImages: []ske.MachineImage{}, }, }, wantErr: false, @@ -167,7 +168,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - MachineImages: &[]ske.MachineImage{{}}, + MachineImages: []ske.MachineImage{{}}, }, }, wantErr: false, @@ -179,14 +180,14 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - MachineImages: &[]ske.MachineImage{ + MachineImages: []ske.MachineImage{ { Name: utils.Ptr("image1"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { - Cri: &[]ske.CRI{ + Cri: []ske.CRI{ { - Name: ske.CRINAME_CONTAINERD.Ptr(), + Name: utils.Ptr("containerd"), }, }, ExpirationDate: utils.Ptr(time.Now()), diff --git a/internal/cmd/ske/options/machine_types/machine_types.go b/internal/cmd/ske/options/machine_types/machine_types.go index 26014dc59..5d66cade5 100644 --- a/internal/cmd/ske/options/machine_types/machine_types.go +++ b/internal/cmd/ske/options/machine_types/machine_types.go @@ -14,7 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type inputModel struct { @@ -70,7 +70,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest { - req := apiClient.ListProviderOptions(ctx, model.Region) + req := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region) return req } @@ -85,7 +85,7 @@ func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOpti options.VolumeTypes = nil return p.OutputResult(model.OutputFormat, options, func() error { - machineTypes := utils.PtrValue(options.MachineTypes) + machineTypes := options.MachineTypes table := tables.NewTable() table.SetHeader("TYPE", "CPU", "MEMORY") diff --git a/internal/cmd/ske/options/machine_types/machine_types_test.go b/internal/cmd/ske/options/machine_types/machine_types_test.go index 7db75d847..ef405139f 100644 --- a/internal/cmd/ske/options/machine_types/machine_types_test.go +++ b/internal/cmd/ske/options/machine_types/machine_types_test.go @@ -13,13 +13,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} const testRegion = "eu01" @@ -86,7 +86,7 @@ func TestBuildRequest(t *testing.T) { { description: "base", inputModel: fixtureInputModel(), - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion), }, } @@ -97,6 +97,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -154,7 +155,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - MachineTypes: &[]ske.MachineType{}, + MachineTypes: []ske.MachineType{}, }, }, wantErr: false, @@ -166,7 +167,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - MachineTypes: &[]ske.MachineType{{}}, + MachineTypes: []ske.MachineType{{}}, }, }, wantErr: false, @@ -178,19 +179,19 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - MachineTypes: &[]ske.MachineType{ + MachineTypes: []ske.MachineType{ { Architecture: utils.Ptr("amd64"), - Cpu: utils.Ptr(int64(2)), - Gpu: utils.Ptr(int64(0)), - Memory: utils.Ptr(int64(16)), + Cpu: utils.Ptr(int32(2)), + Gpu: utils.Ptr(int32(0)), + Memory: utils.Ptr(int32(16)), Name: utils.Ptr("type1"), }, { Architecture: utils.Ptr("amd64"), - Cpu: utils.Ptr(int64(2)), - Gpu: utils.Ptr(int64(0)), - Memory: utils.Ptr(int64(16)), + Cpu: utils.Ptr(int32(2)), + Gpu: utils.Ptr(int32(0)), + Memory: utils.Ptr(int32(16)), Name: utils.Ptr("type2"), }, }, diff --git a/internal/cmd/ske/options/options.go b/internal/cmd/ske/options/options.go index 7038cee7f..58d7db759 100644 --- a/internal/cmd/ske/options/options.go +++ b/internal/cmd/ske/options/options.go @@ -22,7 +22,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) const ( @@ -135,7 +135,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest { - req := apiClient.ListProviderOptions(ctx, model.Region) + req := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region) return req } @@ -178,11 +178,11 @@ func outputResultAsTable(p *print.Printer, options *ske.ProviderOptions) error { } content := []tables.Table{} - if options.AvailabilityZones != nil && len(*options.AvailabilityZones) != 0 { + if len(options.AvailabilityZones) != 0 { content = append(content, buildAvailabilityZonesTable(options)) } - if options.KubernetesVersions != nil && len(*options.KubernetesVersions) != 0 { + if len(options.KubernetesVersions) != 0 { kubernetesVersionsTable, err := buildKubernetesVersionsTable(options) if err != nil { return fmt.Errorf("build Kubernetes versions table: %w", err) @@ -190,15 +190,15 @@ func outputResultAsTable(p *print.Printer, options *ske.ProviderOptions) error { content = append(content, kubernetesVersionsTable) } - if options.MachineImages != nil && len(*options.MachineImages) != 0 { + if len(options.MachineImages) != 0 { content = append(content, buildMachineImagesTable(options)) } - if options.MachineTypes != nil && len(*options.MachineTypes) != 0 { + if len(options.MachineTypes) != 0 { content = append(content, buildMachineTypesTable(options)) } - if options.VolumeTypes != nil && len(*options.VolumeTypes) != 0 { + if len(options.VolumeTypes) != 0 { content = append(content, buildVolumeTypesTable(options)) } @@ -211,7 +211,7 @@ func outputResultAsTable(p *print.Printer, options *ske.ProviderOptions) error { } func buildAvailabilityZonesTable(resp *ske.ProviderOptions) tables.Table { - zones := *resp.AvailabilityZones + zones := resp.AvailabilityZones table := tables.NewTable() table.SetTitle("Availability Zones") @@ -224,7 +224,7 @@ func buildAvailabilityZonesTable(resp *ske.ProviderOptions) tables.Table { } func buildKubernetesVersionsTable(resp *ske.ProviderOptions) (tables.Table, error) { - versions := *resp.KubernetesVersions + versions := resp.KubernetesVersions table := tables.NewTable() table.SetTitle("Kubernetes Versions") @@ -249,19 +249,19 @@ func buildKubernetesVersionsTable(resp *ske.ProviderOptions) (tables.Table, erro } func buildMachineImagesTable(resp *ske.ProviderOptions) tables.Table { - images := *resp.MachineImages + images := resp.MachineImages table := tables.NewTable() table.SetTitle("Machine Images") table.SetHeader("NAME", "VERSION", "STATE", "EXPIRATION DATE", "SUPPORTED CRI") for i := range images { image := images[i] - versions := *image.Versions + versions := image.Versions for j := range versions { version := versions[j] criNames := make([]string, 0) - for i := range *version.Cri { - cri := (*version.Cri)[i] + for i := range version.Cri { + cri := version.Cri[i] criNames = append(criNames, string(*cri.Name)) } criNamesString := strings.Join(criNames, ", ") @@ -284,7 +284,7 @@ func buildMachineImagesTable(resp *ske.ProviderOptions) tables.Table { } func buildMachineTypesTable(resp *ske.ProviderOptions) tables.Table { - machineTypes := *resp.MachineTypes + machineTypes := resp.MachineTypes table := tables.NewTable() table.SetTitle("Machine Types") @@ -301,7 +301,7 @@ func buildMachineTypesTable(resp *ske.ProviderOptions) tables.Table { } func buildVolumeTypesTable(resp *ske.ProviderOptions) tables.Table { - volumeTypes := *resp.VolumeTypes + volumeTypes := resp.VolumeTypes table := tables.NewTable() table.SetTitle("Volume Types") diff --git a/internal/cmd/ske/options/options_test.go b/internal/cmd/ske/options/options_test.go index 2fe568f2a..52ebe0a26 100644 --- a/internal/cmd/ske/options/options_test.go +++ b/internal/cmd/ske/options/options_test.go @@ -12,13 +12,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} const testRegion = "eu01" @@ -142,7 +142,7 @@ func TestBuildRequest(t *testing.T) { }{ { description: "base", - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion), }, } @@ -153,6 +153,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/ske/options/volume_types/volume_types.go b/internal/cmd/ske/options/volume_types/volume_types.go index 8d3983487..35aa8dbb9 100644 --- a/internal/cmd/ske/options/volume_types/volume_types.go +++ b/internal/cmd/ske/options/volume_types/volume_types.go @@ -14,7 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type inputModel struct { @@ -70,7 +70,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest { - req := apiClient.ListProviderOptions(ctx, model.Region) + req := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region) return req } @@ -85,7 +85,7 @@ func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOpti options.MachineTypes = nil return p.OutputResult(model.OutputFormat, options, func() error { - volumeTypes := utils.PtrValue(options.VolumeTypes) + volumeTypes := options.VolumeTypes table := tables.NewTable() table.SetHeader("TYPE") diff --git a/internal/cmd/ske/options/volume_types/volume_types_test.go b/internal/cmd/ske/options/volume_types/volume_types_test.go index ce37ce498..ea926f3f0 100644 --- a/internal/cmd/ske/options/volume_types/volume_types_test.go +++ b/internal/cmd/ske/options/volume_types/volume_types_test.go @@ -13,13 +13,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &ske.APIClient{} +var testClient = &ske.APIClient{DefaultAPI: &ske.DefaultAPIService{}} const testRegion = "eu01" @@ -86,7 +86,7 @@ func TestBuildRequest(t *testing.T) { { description: "base", inputModel: fixtureInputModel(), - expectedRequest: testClient.ListProviderOptions(testCtx, testRegion), + expectedRequest: testClient.DefaultAPI.ListProviderOptions(testCtx, testRegion), }, } @@ -97,6 +97,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -154,7 +155,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - VolumeTypes: &[]ske.VolumeType{}, + VolumeTypes: []ske.VolumeType{}, }, }, wantErr: false, @@ -166,7 +167,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - VolumeTypes: &[]ske.VolumeType{{}}, + VolumeTypes: []ske.VolumeType{{}}, }, }, wantErr: false, @@ -178,7 +179,7 @@ func TestOutputResult(t *testing.T) { GlobalFlagModel: globalflags.GlobalFlagModel{}, }, options: &ske.ProviderOptions{ - VolumeTypes: &[]ske.VolumeType{ + VolumeTypes: []ske.VolumeType{ { Name: utils.Ptr("type1"), }, diff --git a/internal/pkg/services/ske/client/client.go b/internal/pkg/services/ske/client/client.go index 5b4b69f38..dd3af9872 100644 --- a/internal/pkg/services/ske/client/client.go +++ b/internal/pkg/services/ske/client/client.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/viper" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) func ConfigureClient(p *print.Printer, cliVersion string) (*ske.APIClient, error) { diff --git a/internal/pkg/services/ske/utils/utils.go b/internal/pkg/services/ske/utils/utils.go index 904ff97a1..5b4f46561 100644 --- a/internal/pkg/services/ske/utils/utils.go +++ b/internal/pkg/services/ske/utils/utils.go @@ -12,12 +12,12 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "k8s.io/client-go/tools/clientcmd" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" "golang.org/x/mod/semver" ) const ( - defaultNodepoolCRI = ske.CRINAME_CONTAINERD + defaultNodepoolCRI = "containerd" defaultNodepoolMachineImageName = "flatcar" defaultNodepoolMaxUnavailable = 0 defaultNodepoolMinimum = 1 @@ -28,17 +28,12 @@ const ( supportedState = "supported" ) -type SKEClient interface { - ListClustersExecute(ctx context.Context, projectId, region string) (*ske.ListClustersResponse, error) - ListProviderOptionsExecute(ctx context.Context, region string) (*ske.ProviderOptions, error) -} - -func ClusterExists(ctx context.Context, apiClient SKEClient, projectId, region, clusterName string) (bool, error) { - clusters, err := apiClient.ListClustersExecute(ctx, projectId, region) +func ClusterExists(ctx context.Context, apiClient ske.DefaultAPI, projectId, region, clusterName string) (bool, error) { + clusters, err := apiClient.ListClusters(ctx, projectId, region).Execute() if err != nil { return false, fmt.Errorf("list SKE clusters: %w", err) } - for _, cl := range *clusters.Items { + for _, cl := range clusters.Items { if cl.Name != nil && *cl.Name == clusterName { return true, nil } @@ -46,8 +41,8 @@ func ClusterExists(ctx context.Context, apiClient SKEClient, projectId, region, return false, nil } -func GetDefaultPayload(ctx context.Context, apiClient SKEClient, region string) (*ske.CreateOrUpdateClusterPayload, error) { - resp, err := apiClient.ListProviderOptionsExecute(ctx, region) +func GetDefaultPayload(ctx context.Context, apiClient ske.DefaultAPI, region string) (*ske.CreateOrUpdateClusterPayload, error) { + resp, err := apiClient.ListProviderOptions(ctx, region).Execute() if err != nil { return nil, fmt.Errorf("get SKE provider options: %w", err) } @@ -64,86 +59,91 @@ func GetDefaultPayload(ctx context.Context, apiClient SKEClient, region string) payload := &ske.CreateOrUpdateClusterPayload{ Extensions: &ske.Extension{ Acl: &ske.ACL{ - AllowedCidrs: &[]string{}, - Enabled: utils.Ptr(false), + AllowedCidrs: []string{}, + Enabled: false, }, }, Kubernetes: payloadKubernetes, - Nodepools: &[]ske.Nodepool{ + Nodepools: []ske.Nodepool{ *payloadNodepool, }, } return payload, nil } -func getDefaultPayloadKubernetes(resp *ske.ProviderOptions) (*ske.Kubernetes, error) { - output := &ske.Kubernetes{} +func getDefaultPayloadKubernetes(resp *ske.ProviderOptions) (ske.Kubernetes, error) { + output := ske.Kubernetes{} if resp.KubernetesVersions == nil { - return nil, fmt.Errorf("no supported Kubernetes version found") + return ske.Kubernetes{}, fmt.Errorf("no supported Kubernetes version found") } foundKubernetesVersion := false - versions := *resp.KubernetesVersions + versions := resp.KubernetesVersions for i := range versions { version := versions[i] if *version.State != supportedState { continue } - if output.Version != nil { - oldSemVer := fmt.Sprintf("v%s", *output.Version) - newSemVer := fmt.Sprintf("v%s", *version.Version) + if output.Version != "" { + oldSemVer := fmt.Sprintf("v%s", output.Version) + newSemVer := fmt.Sprintf("v%s", version.GetVersion()) if semver.Compare(newSemVer, oldSemVer) != 1 { continue } } foundKubernetesVersion = true - output.Version = version.Version + output.Version = version.GetVersion() } if !foundKubernetesVersion { - return nil, fmt.Errorf("no supported Kubernetes version found") + return ske.Kubernetes{}, fmt.Errorf("no supported Kubernetes version found") } return output, nil } func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) { - if resp.AvailabilityZones == nil || len(*resp.AvailabilityZones) == 0 { + if len(resp.AvailabilityZones) == 0 { return nil, fmt.Errorf("no availability zones found") } var availabilityZones []string - for i := range *resp.AvailabilityZones { - azName := (*resp.AvailabilityZones)[i].GetName() + for i := range resp.AvailabilityZones { + azName := resp.AvailabilityZones[i].GetName() // don't include availability zones like eu01-m, eu02-m, not all flavors are available there if !regexp.MustCompile(`\w{2}\d{2}-m`).MatchString(azName) { availabilityZones = append(availabilityZones, azName) } } - if resp.MachineTypes == nil || len(*resp.MachineTypes) == 0 { + if len(resp.MachineTypes) == 0 { return nil, fmt.Errorf("no machine types found") } - machineType := (*resp.MachineTypes)[0].GetName() + azLen := len(availabilityZones) + if azLen > 1000 { + // check against a very large number to avoid gosec warning + return nil, fmt.Errorf("invalid number of availability zones") + } + machineType := resp.MachineTypes[0].GetName() output := &ske.Nodepool{ - AvailabilityZones: &availabilityZones, + AvailabilityZones: availabilityZones, Cri: &ske.CRI{ Name: utils.Ptr(defaultNodepoolCRI), }, - Machine: &ske.Machine{ - Type: &machineType, - Image: &ske.Image{ - Name: utils.Ptr(defaultNodepoolMachineImageName), + Machine: ske.Machine{ + Type: machineType, + Image: ske.Image{ + Name: defaultNodepoolMachineImageName, }, }, // there must be as many nodes as availability zones are given - MaxSurge: utils.Ptr(int64(len(availabilityZones))), - MaxUnavailable: utils.Ptr(int64(defaultNodepoolMaxUnavailable)), - Maximum: utils.Ptr(int64(len(availabilityZones))), - Minimum: utils.Ptr(int64(defaultNodepoolMinimum)), - Name: utils.Ptr(defaultNodepoolName), - Volume: &ske.Volume{ + MaxSurge: utils.Ptr(int32(azLen)), + MaxUnavailable: utils.Ptr(int32(defaultNodepoolMaxUnavailable)), + Maximum: int32(azLen), + Minimum: int32(defaultNodepoolMinimum), + Name: defaultNodepoolName, + Volume: ske.Volume{ Type: utils.Ptr(defaultNodepoolVolumeType), - Size: utils.Ptr(int64(defaultNodepoolVolumeSize)), + Size: int32(defaultNodepoolVolumeSize), }, } @@ -152,7 +152,7 @@ func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) return nil, fmt.Errorf("no supported image versions found") } foundImageVersion := false - images := *resp.MachineImages + images := resp.MachineImages for i := range images { image := images[i] if *image.Name != defaultNodepoolMachineImageName { @@ -161,7 +161,7 @@ func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) if image.Versions == nil { continue } - versions := *image.Versions + versions := image.Versions for j := range versions { version := versions[j] if *version.State != supportedState { @@ -169,12 +169,12 @@ func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) } // Check if default CRI is supported - if version.Cri == nil || len(*version.Cri) == 0 { + if len(version.Cri) == 0 { continue } criSupported := false - for k := range *version.Cri { - cri := (*version.Cri)[k] + for k := range version.Cri { + cri := version.Cri[k] if *cri.Name == defaultNodepoolCRI { criSupported = true break @@ -184,8 +184,8 @@ func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) continue } - if output.Machine.Image.Version != nil { - oldSemVer := fmt.Sprintf("v%s", *output.Machine.Image.Version) + if output.Machine.Image.Version != "" { + oldSemVer := fmt.Sprintf("v%s", output.Machine.Image.Version) newSemVer := fmt.Sprintf("v%s", *version.Version) if semver.Compare(newSemVer, oldSemVer) != 1 { continue @@ -193,7 +193,7 @@ func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) } foundImageVersion = true - output.Machine.Image.Version = version.Version + output.Machine.Image.Version = version.GetVersion() } } if !foundImageVersion { diff --git a/internal/pkg/services/ske/utils/utils_test.go b/internal/pkg/services/ske/utils/utils_test.go index a616e2d07..e6ade49fa 100644 --- a/internal/pkg/services/ske/utils/utils_test.go +++ b/internal/pkg/services/ske/utils/utils_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/ske" + ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api" ) var ( @@ -63,29 +63,8 @@ users: ` ) -type skeClientMocked struct { - listClustersFails bool - listClustersResp *ske.ListClustersResponse - listProviderOptionsFails bool - listProviderOptionsResp *ske.ProviderOptions -} - const testRegion = "eu01" -func (m *skeClientMocked) ListClustersExecute(_ context.Context, _, _ string) (*ske.ListClustersResponse, error) { - if m.listClustersFails { - return nil, fmt.Errorf("could not list clusters") - } - return m.listClustersResp, nil -} - -func (m *skeClientMocked) ListProviderOptionsExecute(_ context.Context, _ string) (*ske.ProviderOptions, error) { - if m.listProviderOptionsFails { - return nil, fmt.Errorf("could not list provider options") - } - return m.listProviderOptionsResp, nil -} - func TestClusterExists(t *testing.T) { tests := []struct { description string @@ -96,19 +75,19 @@ func TestClusterExists(t *testing.T) { }{ { description: "cluster exists", - getClustersResp: &ske.ListClustersResponse{Items: &[]ske.Cluster{{Name: utils.Ptr(testClusterName)}}}, + getClustersResp: &ske.ListClustersResponse{Items: []ske.Cluster{{Name: utils.Ptr(testClusterName)}}}, isValid: true, expectedExists: true, }, { description: "cluster exists 2", - getClustersResp: &ske.ListClustersResponse{Items: &[]ske.Cluster{{Name: utils.Ptr("some-cluster")}, {Name: utils.Ptr("some-other-cluster")}, {Name: utils.Ptr(testClusterName)}}}, + getClustersResp: &ske.ListClustersResponse{Items: []ske.Cluster{{Name: utils.Ptr("some-cluster")}, {Name: utils.Ptr("some-other-cluster")}, {Name: utils.Ptr(testClusterName)}}}, isValid: true, expectedExists: true, }, { description: "cluster does not exist", - getClustersResp: &ske.ListClustersResponse{Items: &[]ske.Cluster{{Name: utils.Ptr("some-cluster")}, {Name: utils.Ptr("some-other-cluster")}}}, + getClustersResp: &ske.ListClustersResponse{Items: []ske.Cluster{{Name: utils.Ptr("some-cluster")}, {Name: utils.Ptr("some-other-cluster")}}}, isValid: true, expectedExists: false, }, @@ -121,9 +100,13 @@ func TestClusterExists(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &skeClientMocked{ - listClustersFails: tt.getClustersFails, - listClustersResp: tt.getClustersResp, + client := &ske.DefaultAPIServiceMock{ + ListClustersExecuteMock: utils.Ptr(func(_ ske.ApiListClustersRequest) (*ske.ListClustersResponse, error) { + if tt.getClustersFails { + return nil, fmt.Errorf("could not list clusters") + } + return tt.getClustersResp, nil + }), } exists, err := ClusterExists(context.Background(), client, testProjectId, testRegion, testClusterName) @@ -146,18 +129,18 @@ func TestClusterExists(t *testing.T) { func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOptions { providerOptions := &ske.ProviderOptions{ - AvailabilityZones: &[]ske.AvailabilityZone{ + AvailabilityZones: []ske.AvailabilityZone{ {Name: utils.Ptr("eu01-m")}, {Name: utils.Ptr("eu01-1")}, {Name: utils.Ptr("eu01-2")}, {Name: utils.Ptr("eu01-3")}, }, - MachineTypes: &[]ske.MachineType{ + MachineTypes: []ske.MachineType{ { Name: utils.Ptr("b1.2"), }, }, - KubernetesVersions: &[]ske.KubernetesVersion{ + KubernetesVersions: []ske.KubernetesVersion{ { State: utils.Ptr("supported"), Version: utils.Ptr("1.2.3"), @@ -171,31 +154,31 @@ func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOpt Version: utils.Ptr("4.4.4"), }, }, - MachineImages: &[]ske.MachineImage{ + MachineImages: []ske.MachineImage{ { Name: utils.Ptr("flatcar"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { State: utils.Ptr("supported"), Version: utils.Ptr("1.2.3"), - Cri: &[]ske.CRI{ + Cri: []ske.CRI{ { - Name: ske.CRINAME_DOCKER.Ptr(), + Name: utils.Ptr("docker"), }, { - Name: ske.CRINAME_CONTAINERD.Ptr(), + Name: utils.Ptr("containerd"), }, }, }, { State: utils.Ptr("supported"), Version: utils.Ptr("3.2.1"), - Cri: &[]ske.CRI{ + Cri: []ske.CRI{ { - Name: ske.CRINAME_DOCKER.Ptr(), + Name: utils.Ptr("docker"), }, { - Name: ske.CRINAME_CONTAINERD.Ptr(), + Name: utils.Ptr("containerd"), }, }, }, @@ -203,13 +186,13 @@ func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOpt }, { Name: utils.Ptr("not-flatcar"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { State: utils.Ptr("supported"), Version: utils.Ptr("4.4.4"), - Cri: &[]ske.CRI{ + Cri: []ske.CRI{ { - Name: ske.CRINAME_CONTAINERD.Ptr(), + Name: utils.Ptr("containerd"), }, }, }, @@ -217,7 +200,7 @@ func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOpt }, { Name: utils.Ptr("flatcar"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { State: utils.Ptr("supported"), Version: utils.Ptr("4.4.4"), @@ -226,13 +209,13 @@ func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOpt }, { Name: utils.Ptr("flatcar"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { State: utils.Ptr("not-supported"), Version: utils.Ptr("4.4.4"), - Cri: &[]ske.CRI{ + Cri: []ske.CRI{ { - Name: ske.CRINAME_CONTAINERD.Ptr(), + Name: utils.Ptr("containerd"), }, }, }, @@ -240,13 +223,13 @@ func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOpt }, { Name: utils.Ptr("flatcar"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { State: utils.Ptr("supported"), Version: utils.Ptr("4.4.4"), - Cri: &[]ske.CRI{ + Cri: []ske.CRI{ { - Name: ske.CRINAME_DOCKER.Ptr(), + Name: utils.Ptr("docker"), }, }, }, @@ -264,38 +247,38 @@ func fixtureGetDefaultPayload(mods ...func(*ske.CreateOrUpdateClusterPayload)) * payload := &ske.CreateOrUpdateClusterPayload{ Extensions: &ske.Extension{ Acl: &ske.ACL{ - AllowedCidrs: &[]string{}, - Enabled: utils.Ptr(false), + AllowedCidrs: []string{}, + Enabled: false, }, }, - Kubernetes: &ske.Kubernetes{ - Version: utils.Ptr("3.2.1"), + Kubernetes: ske.Kubernetes{ + Version: "3.2.1", }, - Nodepools: &[]ske.Nodepool{ + Nodepools: []ske.Nodepool{ { - AvailabilityZones: &[]string{ + AvailabilityZones: []string{ "eu01-1", "eu01-2", "eu01-3", }, Cri: &ske.CRI{ - Name: ske.CRINAME_CONTAINERD.Ptr(), + Name: utils.Ptr("containerd"), }, - Machine: &ske.Machine{ - Type: utils.Ptr("b1.2"), - Image: &ske.Image{ - Version: utils.Ptr("3.2.1"), - Name: utils.Ptr("flatcar"), + Machine: ske.Machine{ + Type: "b1.2", + Image: ske.Image{ + Version: "3.2.1", + Name: "flatcar", }, }, - MaxSurge: utils.Ptr(int64(3)), - MaxUnavailable: utils.Ptr(int64(0)), - Maximum: utils.Ptr(int64(3)), - Minimum: utils.Ptr(int64(1)), - Name: utils.Ptr("pool-default"), - Volume: &ske.Volume{ + MaxSurge: utils.Ptr(int32(3)), + MaxUnavailable: utils.Ptr(int32(0)), + Maximum: int32(3), + Minimum: int32(1), + Name: "pool-default", + Volume: ske.Volume{ Type: utils.Ptr("storage_premium_perf2"), - Size: utils.Ptr(int64(50)), + Size: int32(50), }, }, }, @@ -335,7 +318,7 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no availability zones", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.AvailabilityZones = &[]ske.AvailabilityZone{} + po.AvailabilityZones = []ske.AvailabilityZone{} }), isValid: false, }, @@ -349,7 +332,7 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no machine types", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.MachineTypes = &[]ske.MachineType{} + po.MachineTypes = []ske.MachineType{} }), isValid: false, }, @@ -363,14 +346,14 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no Kubernetes versions 2", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.KubernetesVersions = &[]ske.KubernetesVersion{} + po.KubernetesVersions = []ske.KubernetesVersion{} }), isValid: false, }, { description: "no supported Kubernetes versions", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.KubernetesVersions = &[]ske.KubernetesVersion{ + po.KubernetesVersions = []ske.KubernetesVersion{ { State: utils.Ptr("not-supported"), Version: utils.Ptr("1.2.3"), @@ -382,7 +365,7 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no machine images 1", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.MachineImages = &[]ske.MachineImage{} + po.MachineImages = []ske.MachineImage{} }), isValid: false, }, @@ -396,7 +379,7 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no machine image versions 1", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.MachineImages = &[]ske.MachineImage{ + po.MachineImages = []ske.MachineImage{ { Name: utils.Ptr("image-1"), Versions: nil, @@ -408,10 +391,10 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no machine image versions 2", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.MachineImages = &[]ske.MachineImage{ + po.MachineImages = []ske.MachineImage{ { Name: utils.Ptr("image-1"), - Versions: &[]ske.MachineImageVersion{}, + Versions: []ske.MachineImageVersion{}, }, } }), @@ -420,10 +403,10 @@ func TestGetDefaultPayload(t *testing.T) { { description: "no supported machine image versions", listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) { - po.MachineImages = &[]ske.MachineImage{ + po.MachineImages = []ske.MachineImage{ { Name: utils.Ptr("image-1"), - Versions: &[]ske.MachineImageVersion{ + Versions: []ske.MachineImageVersion{ { State: utils.Ptr("not-supported"), Version: utils.Ptr("1.2.3"), @@ -438,9 +421,13 @@ func TestGetDefaultPayload(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &skeClientMocked{ - listProviderOptionsFails: tt.listProviderOptionsFails, - listProviderOptionsResp: tt.listProviderOptionsResp, + client := &ske.DefaultAPIServiceMock{ + ListProviderOptionsExecuteMock: utils.Ptr(func(_ ske.ApiListProviderOptionsRequest) (*ske.ProviderOptions, error) { + if tt.listProviderOptionsFails { + return nil, fmt.Errorf("could not list provider options") + } + return tt.listProviderOptionsResp, nil + }), } output, err := GetDefaultPayload(context.Background(), client, testRegion) From e0e5f5c2bd3e935c5a360f57a38ac11adabd370f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 10 Mar 2026 15:41:17 +0100 Subject: [PATCH 2/3] fix test failures --- internal/cmd/ske/cluster/create/create_test.go | 1 - internal/cmd/ske/cluster/update/update_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/internal/cmd/ske/cluster/create/create_test.go b/internal/cmd/ske/cluster/create/create_test.go index 1093081ca..1dd6b233a 100644 --- a/internal/cmd/ske/cluster/create/create_test.go +++ b/internal/cmd/ske/cluster/create/create_test.go @@ -88,7 +88,6 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st globalflags.ProjectIdFlag: testProjectId, globalflags.RegionFlag: testRegion, payloadFlag: `{ - "name": "cli-jp", "kubernetes": { "version": "1.25.15" }, diff --git a/internal/cmd/ske/cluster/update/update_test.go b/internal/cmd/ske/cluster/update/update_test.go index f76f1a88a..4b06392ff 100644 --- a/internal/cmd/ske/cluster/update/update_test.go +++ b/internal/cmd/ske/cluster/update/update_test.go @@ -87,7 +87,6 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st globalflags.ProjectIdFlag: testProjectId, globalflags.RegionFlag: testRegion, payloadFlag: `{ - "name": "cli-jp", "kubernetes": { "version": "1.25.15" }, From d8819e05894d24313836b1c12a2084267d21894d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 5 Mar 2026 10:24:58 +0100 Subject: [PATCH 3/3] feat(ske): add idp support for kubeconfig create --- docs/stackit_ske_kubeconfig_create.md | 32 ++++--- internal/cmd/ske/kubeconfig/create/create.go | 96 ++++++++++++------- .../cmd/ske/kubeconfig/create/create_test.go | 65 +++++++++++-- 3 files changed, 136 insertions(+), 57 deletions(-) diff --git a/docs/stackit_ske_kubeconfig_create.md b/docs/stackit_ske_kubeconfig_create.md index 476d50bab..5717a31f8 100644 --- a/docs/stackit_ske_kubeconfig_create.md +++ b/docs/stackit_ske_kubeconfig_create.md @@ -4,9 +4,9 @@ Creates or update a kubeconfig for a SKE cluster ### Synopsis -Creates a kubeconfig for a STACKIT Kubernetes Engine (SKE) cluster, if the config exists in the kubeconfig file the information will be updated. +Creates a kubeconfig for a STACKIT Kubernetes Engine (SKE) cluster. By default an admin kubeconfig is created. Use the `--idp` option to create an IDP kubeconfig that authenticates via the STACKIT IDP. -By default, the kubeconfig information of the SKE cluster is merged into the default kubeconfig file of the current user. If the kubeconfig file doesn't exist, a new one will be created. +If the config exists in the kubeconfig file the information will be updated. By default, the kubeconfig information of the SKE cluster is merged into the default kubeconfig file of the current user. If the kubeconfig file doesn't exist, a new one will be created. You can override this behavior by specifying a custom filepath using the --filepath flag or by setting the KUBECONFIG env variable (fallback). An expiration time can be set for the kubeconfig. The expiration time is set in seconds(s), minutes(m), hours(h), days(d) or months(M). Default is 1h. @@ -20,25 +20,28 @@ stackit ske kubeconfig create CLUSTER_NAME [flags] ### Examples ``` - Create or update a kubeconfig for the SKE cluster with name "my-cluster. If the config exits in the kubeconfig file the information will be updated." - $ stackit ske kubeconfig create my-cluster - - Get a login kubeconfig for the SKE cluster with name "my-cluster". This kubeconfig does not contain any credentials and instead obtains valid credentials via the `stackit ske kubeconfig login` command. + Get a short-lived admin kubeconfig for the SKE cluster with name "my-cluster". This kubeconfig does not contain any credentials and instead obtains valid admin credentials via the `stackit ske kubeconfig login` command. $ stackit ske kubeconfig create my-cluster --login - Create a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated. + Get an IDP kubeconfig for the SKE cluster with name "my-cluster". This kubeconfig does not grant permissions in the cluster by default and obtains credentials on-demand via the `stackit ske kubeconfig login` command. + $ stackit ske kubeconfig create my-cluster --idp + + Create or update a short-lived admin kubeconfig for the SKE cluster with name "my-cluster" in a custom filepath. If the config exits in the kubeconfig file the information will be updated. + $ stackit ske kubeconfig create my-cluster --login --filepath /path/to/config + + Create or update an admin kubeconfig for the SKE cluster with name "my-cluster". If the config exits in the kubeconfig file the information will be updated." + $ stackit ske kubeconfig create my-cluster + + Create an admin kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated. $ stackit ske kubeconfig create my-cluster --expiration 30d - Create or update a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 2 months. If the config exits in the kubeconfig file the information will be updated. + Create or update an admin kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 2 months. If the config exits in the kubeconfig file the information will be updated. $ stackit ske kubeconfig create my-cluster --expiration 2M - Create or update a kubeconfig for the SKE cluster with name "my-cluster" in a custom filepath. If the config exits in the kubeconfig file the information will be updated. - $ stackit ske kubeconfig create my-cluster --filepath /path/to/config - - Get a kubeconfig for the SKE cluster with name "my-cluster" without writing it to a file and format the output as json + Get an admin kubeconfig for the SKE cluster with name "my-cluster" without writing it to a file and format the output as json $ stackit ske kubeconfig create my-cluster --disable-writing --output-format json - Create a kubeconfig for the SKE cluster with name "my-cluster. It will OVERWRITE your current kubeconfig file." + Create an admin kubeconfig for the SKE cluster with name "my-cluster". It will OVERWRITE your current kubeconfig file. $ stackit ske kubeconfig create my-cluster --overwrite true ``` @@ -49,7 +52,8 @@ stackit ske kubeconfig create CLUSTER_NAME [flags] -e, --expiration string Expiration time for the kubeconfig in seconds(s), minutes(m), hours(h), days(d) or months(M). Example: 30d. By default, expiration time is 1h --filepath string Path to create the kubeconfig file. Will fall back to KUBECONFIG env variable if not set. In case both aren't set, the kubeconfig is created as file named 'config' in the .kube folder in the user's home directory. -h, --help Help for "stackit ske kubeconfig create" - -l, --login Create a login kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag. + --idp Create a non-admin kubeconfig that uses the STACKIT IDP to obtain credentials. + -l, --login Create a short-lived admin kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag. --overwrite Overwrite the kubeconfig file. ``` diff --git a/internal/cmd/ske/kubeconfig/create/create.go b/internal/cmd/ske/kubeconfig/create/create.go index bff2dfa18..b417e0bbc 100644 --- a/internal/cmd/ske/kubeconfig/create/create.go +++ b/internal/cmd/ske/kubeconfig/create/create.go @@ -29,6 +29,7 @@ const ( expirationFlag = "expiration" filepathFlag = "filepath" loginFlag = "login" + idpFlag = "idp" overwriteFlag = "overwrite" ) @@ -39,6 +40,7 @@ type inputModel struct { ExpirationTime *string Filepath *string Login bool + IDP bool Overwrite bool } @@ -47,34 +49,38 @@ func NewCmd(params *types.CmdParams) *cobra.Command { Use: fmt.Sprintf("create %s", clusterNameArg), Short: "Creates or update a kubeconfig for a SKE cluster", Long: fmt.Sprintf("%s\n\n%s\n%s\n%s\n%s", - "Creates a kubeconfig for a STACKIT Kubernetes Engine (SKE) cluster, if the config exists in the kubeconfig file the information will be updated.", - "By default, the kubeconfig information of the SKE cluster is merged into the default kubeconfig file of the current user. If the kubeconfig file doesn't exist, a new one will be created.", + "Creates a kubeconfig for a STACKIT Kubernetes Engine (SKE) cluster. By default an admin kubeconfig is created. Use the `--idp` option to create an IDP kubeconfig that authenticates via the STACKIT IDP.", + "If the config exists in the kubeconfig file the information will be updated. By default, the kubeconfig information of the SKE cluster is merged into the default kubeconfig file of the current user. If the kubeconfig file doesn't exist, a new one will be created.", "You can override this behavior by specifying a custom filepath using the --filepath flag or by setting the KUBECONFIG env variable (fallback).\n", "An expiration time can be set for the kubeconfig. The expiration time is set in seconds(s), minutes(m), hours(h), days(d) or months(M). Default is 1h.\n", "Note that the format is , e.g. 30d for 30 days and you can't combine units."), Args: args.SingleArg(clusterNameArg, nil), Example: examples.Build( examples.NewExample( - `Create or update a kubeconfig for the SKE cluster with name "my-cluster. If the config exits in the kubeconfig file the information will be updated."`, - "$ stackit ske kubeconfig create my-cluster"), - examples.NewExample( - `Get a login kubeconfig for the SKE cluster with name "my-cluster". `+ - "This kubeconfig does not contain any credentials and instead obtains valid credentials via the `stackit ske kubeconfig login` command.", + `Get a short-lived admin kubeconfig for the SKE cluster with name "my-cluster". `+ + "This kubeconfig does not contain any credentials and instead obtains valid admin credentials via the `stackit ske kubeconfig login` command.", "$ stackit ske kubeconfig create my-cluster --login"), examples.NewExample( - `Create a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated.`, + `Get an IDP kubeconfig for the SKE cluster with name "my-cluster". `+ + "This kubeconfig does not grant permissions in the cluster by default and obtains credentials on-demand via the `stackit ske kubeconfig login` command.", + "$ stackit ske kubeconfig create my-cluster --idp"), + examples.NewExample( + `Create or update a short-lived admin kubeconfig for the SKE cluster with name "my-cluster" in a custom filepath. If the config exits in the kubeconfig file the information will be updated.`, + "$ stackit ske kubeconfig create my-cluster --login --filepath /path/to/config"), + examples.NewExample( + `Create or update an admin kubeconfig for the SKE cluster with name "my-cluster". If the config exits in the kubeconfig file the information will be updated."`, + "$ stackit ske kubeconfig create my-cluster"), + examples.NewExample( + `Create an admin kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated.`, "$ stackit ske kubeconfig create my-cluster --expiration 30d"), examples.NewExample( - `Create or update a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 2 months. If the config exits in the kubeconfig file the information will be updated.`, + `Create or update an admin kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 2 months. If the config exits in the kubeconfig file the information will be updated.`, "$ stackit ske kubeconfig create my-cluster --expiration 2M"), examples.NewExample( - `Create or update a kubeconfig for the SKE cluster with name "my-cluster" in a custom filepath. If the config exits in the kubeconfig file the information will be updated.`, - "$ stackit ske kubeconfig create my-cluster --filepath /path/to/config"), - examples.NewExample( - `Get a kubeconfig for the SKE cluster with name "my-cluster" without writing it to a file and format the output as json`, + `Get an admin kubeconfig for the SKE cluster with name "my-cluster" without writing it to a file and format the output as json`, "$ stackit ske kubeconfig create my-cluster --disable-writing --output-format json"), examples.NewExample( - `Create a kubeconfig for the SKE cluster with name "my-cluster. It will OVERWRITE your current kubeconfig file."`, + `Create an admin kubeconfig for the SKE cluster with name "my-cluster". It will OVERWRITE your current kubeconfig file.`, "$ stackit ske kubeconfig create my-cluster --overwrite true"), ), RunE: func(cmd *cobra.Command, args []string) error { @@ -95,7 +101,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if model.Overwrite { prompt = fmt.Sprintf("Are you sure you want to create a kubeconfig for SKE cluster %q? This will OVERWRITE your current kubeconfig file, if it exists.", model.ClusterName) } else { - prompt = fmt.Sprintf("Are you sure you want to update your kubeconfig for SKE cluster %q? This will update your kubeconfig file. \nIf it the kubeconfig file doesn't exists, it will create a new one.", model.ClusterName) + prompt = fmt.Sprintf("Are you sure you want to update your kubeconfig for SKE cluster %q? This will update your kubeconfig file. \nIf the kubeconfig file does not exists, it will create a new one.", model.ClusterName) } err = params.Printer.PromptForConfirmation(prompt) if err != nil { @@ -108,22 +114,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command { kubeconfig string respKubeconfig *ske.Kubeconfig respLogin *ske.LoginKubeconfig + respIDP *ske.IDPKubeconfig ) - if !model.Login { - req, err := buildRequestCreate(ctx, model, apiClient) - if err != nil { - return fmt.Errorf("build kubeconfig create request: %w", err) - } - respKubeconfig, err = req.Execute() - if err != nil { - return fmt.Errorf("create kubeconfig for SKE cluster: %w", err) - } - if respKubeconfig.Kubeconfig == nil { - return fmt.Errorf("no kubeconfig returned from the API") - } - kubeconfig = *respKubeconfig.Kubeconfig - } else { + if model.Login { req, err := buildRequestLogin(ctx, model, apiClient) if err != nil { return fmt.Errorf("build login kubeconfig create request: %w", err) @@ -136,6 +130,32 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("no login kubeconfig returned from the API") } kubeconfig = *respLogin.Kubeconfig + } else if model.IDP { + req, err := buildRequestIDP(ctx, model, apiClient) + if err != nil { + return fmt.Errorf("build idp kubeconfig create request: %w", err) + } + respIDP, err = req.Execute() + if err != nil { + return fmt.Errorf("create idp kubeconfig for SKE cluster: %w", err) + } + if respIDP.Kubeconfig == nil { + return fmt.Errorf("no idp kubeconfig returned from the API") + } + kubeconfig = *respIDP.Kubeconfig + } else { + req, err := buildRequestCreate(ctx, model, apiClient) + if err != nil { + return fmt.Errorf("build kubeconfig create request: %w", err) + } + respKubeconfig, err = req.Execute() + if err != nil { + return fmt.Errorf("create kubeconfig for SKE cluster: %w", err) + } + if respKubeconfig.Kubeconfig == nil { + return fmt.Errorf("no kubeconfig returned from the API") + } + kubeconfig = *respKubeconfig.Kubeconfig } // Create the config file @@ -161,7 +181,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { params.Printer.Outputf("\nSet kubectl context to %s with: kubectl config use-context %s\n", model.ClusterName, model.ClusterName) } - return outputResult(params.Printer, model.OutputFormat, model.ClusterName, kubeconfigPath, respKubeconfig, respLogin) + return outputResult(params.Printer, model.OutputFormat, model.ClusterName, kubeconfigPath, respKubeconfig, respLogin, respIDP) }, } configureFlags(cmd) @@ -170,11 +190,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Bool(disableWritingFlag, false, fmt.Sprintf("Disable the writing of kubeconfig. Set the output format to json or yaml using the --%s flag to display the kubeconfig.", globalflags.OutputFormatFlag)) - cmd.Flags().BoolP(loginFlag, "l", false, "Create a login kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag.") + cmd.Flags().BoolP(loginFlag, "l", false, "Create a short-lived admin kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag.") + cmd.Flags().Bool(idpFlag, false, "Create a non-admin kubeconfig that uses the STACKIT IDP to obtain credentials.") cmd.Flags().String(filepathFlag, "", "Path to create the kubeconfig file. Will fall back to KUBECONFIG env variable if not set. In case both aren't set, the kubeconfig is created as file named 'config' in the .kube folder in the user's home directory.") cmd.Flags().StringP(expirationFlag, "e", "", "Expiration time for the kubeconfig in seconds(s), minutes(m), hours(h), days(d) or months(M). Example: 30d. By default, expiration time is 1h") cmd.Flags().Bool(overwriteFlag, false, "Overwrite the kubeconfig file.") - cmd.MarkFlagsMutuallyExclusive(loginFlag, expirationFlag) + cmd.MarkFlagsMutuallyExclusive(loginFlag, expirationFlag, idpFlag) } func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { @@ -213,6 +234,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu Filepath: flags.FlagToStringPointer(p, cmd, filepathFlag), GlobalFlagModel: globalFlags, Login: flags.FlagToBoolValue(p, cmd, loginFlag), + IDP: flags.FlagToBoolValue(p, cmd, idpFlag), Overwrite: flags.FlagToBoolValue(p, cmd, overwriteFlag), } @@ -232,11 +254,15 @@ func buildRequestCreate(ctx context.Context, model *inputModel, apiClient *ske.A return req.CreateKubeconfigPayload(payload), nil } +func buildRequestIDP(ctx context.Context, model *inputModel, apiClient *ske.APIClient) (ske.ApiGetIDPKubeconfigRequest, error) { + return apiClient.DefaultAPI.GetIDPKubeconfig(ctx, model.ProjectId, model.Region, model.ClusterName), nil +} + func buildRequestLogin(ctx context.Context, model *inputModel, apiClient *ske.APIClient) (ske.ApiGetLoginKubeconfigRequest, error) { return apiClient.DefaultAPI.GetLoginKubeconfig(ctx, model.ProjectId, model.Region, model.ClusterName), nil } -func outputResult(p *print.Printer, outputFormat, clusterName, kubeconfigPath string, respKubeconfig *ske.Kubeconfig, respLogin *ske.LoginKubeconfig) error { +func outputResult(p *print.Printer, outputFormat, clusterName, kubeconfigPath string, respKubeconfig *ske.Kubeconfig, respLogin *ske.LoginKubeconfig, respIDP *ske.IDPKubeconfig) error { switch outputFormat { case print.JSONOutputFormat: var err error @@ -245,6 +271,8 @@ func outputResult(p *print.Printer, outputFormat, clusterName, kubeconfigPath st details, err = json.MarshalIndent(respKubeconfig, "", " ") } else if respLogin != nil { details, err = json.MarshalIndent(respLogin, "", " ") + } else if respIDP != nil { + details, err = json.MarshalIndent(respIDP, "", " ") } if err != nil { return fmt.Errorf("marshal SKE Kubeconfig: %w", err) @@ -259,6 +287,8 @@ func outputResult(p *print.Printer, outputFormat, clusterName, kubeconfigPath st details, err = yaml.MarshalWithOptions(respKubeconfig, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) } else if respLogin != nil { details, err = yaml.MarshalWithOptions(respLogin, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) + } else if respIDP != nil { + details, err = yaml.MarshalWithOptions(respIDP, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) } if err != nil { return fmt.Errorf("marshal SKE Kubeconfig: %w", err) diff --git a/internal/cmd/ske/kubeconfig/create/create_test.go b/internal/cmd/ske/kubeconfig/create/create_test.go index af09214f3..3c3f2cae7 100644 --- a/internal/cmd/ske/kubeconfig/create/create_test.go +++ b/internal/cmd/ske/kubeconfig/create/create_test.go @@ -72,6 +72,14 @@ func fixtureRequest(mods ...func(request *ske.ApiCreateKubeconfigRequest)) ske.A return request } +func fixtureRequestLogin() ske.ApiGetLoginKubeconfigRequest { + return testClient.DefaultAPI.GetLoginKubeconfig(testCtx, testProjectId, testRegion, testClusterName) +} + +func fixtureRequestIDP() ske.ApiGetIDPKubeconfigRequest { + return testClient.DefaultAPI.GetIDPKubeconfig(testCtx, testProjectId, testRegion, testClusterName) +} + func TestParseInput(t *testing.T) { tests := []struct { description string @@ -109,6 +117,17 @@ func TestParseInput(t *testing.T) { model.Login = true }), }, + { + description: "idp", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues["idp"] = "true" + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.IDP = true + }), + }, { description: "custom filepath", argValues: fixtureArgValues(), @@ -238,19 +257,37 @@ func TestBuildRequestCreate(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { request, _ := buildRequestCreate(testCtx, tt.model, testClient) - - diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), - cmpopts.EquateComparable(testClient.DefaultAPI), - ) - if diff != "" { - t.Fatalf("Data does not match: %s", diff) - } + assertNoDiff(t, request, tt.expectedRequest) }) } } +func assertNoDiff(t *testing.T, actual, expected any) { + t.Helper() + diff := cmp.Diff(actual, expected, + cmp.AllowUnexported(expected), + cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testClient.DefaultAPI), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } +} + +func TestBuildRequestLogin(t *testing.T) { + model := fixtureInputModel() + expectedRequest := fixtureRequestLogin() + request, _ := buildRequestLogin(testCtx, model, testClient) + assertNoDiff(t, request, expectedRequest) +} + +func TestBuildRequestIDP(t *testing.T) { + model := fixtureInputModel() + expectedRequest := fixtureRequestIDP() + request, _ := buildRequestIDP(testCtx, model, testClient) + assertNoDiff(t, request, expectedRequest) +} + func Test_outputResult(t *testing.T) { type args struct { outputFormat string @@ -258,6 +295,7 @@ func Test_outputResult(t *testing.T) { kubeconfigPath string respKubeconfig *ske.Kubeconfig respLogin *ske.LoginKubeconfig + respIDP *ske.IDPKubeconfig } tests := []struct { name string @@ -283,12 +321,19 @@ func Test_outputResult(t *testing.T) { }, wantErr: false, }, + { + name: "missing idp", + args: args{ + respIDP: &ske.IDPKubeconfig{}, + }, + wantErr: false, + }, } p := print.NewPrinter() p.Cmd = NewCmd(&types.CmdParams{Printer: p}) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(p, tt.args.outputFormat, tt.args.clusterName, tt.args.kubeconfigPath, tt.args.respKubeconfig, tt.args.respLogin); (err != nil) != tt.wantErr { + if err := outputResult(p, tt.args.outputFormat, tt.args.clusterName, tt.args.kubeconfigPath, tt.args.respKubeconfig, tt.args.respLogin, tt.args.respIDP); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } })