diff --git a/CHANGELOG.md b/CHANGELOG.md index 24cc399bf..27eccfdcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Release (2025-XX-XX) +- `ske`: [v0.21.0](services/ske/CHANGELOG.md#v0210-2025-01-21) + - **Removal:** The following methods were removed after deprecation (2024-04-16) and [`serviceenablement` SDK](https://github.com/stackitcloud/stackit-sdk-go/tree/main/services/serviceenablement) must be used instead. + - `DisableService` + - `EnableService` + - `GetServiceStatus` - `sqlserverflex`: [v0.9.0](services/sqlserverflex/CHANGELOG.md#v090-2025-01-20) - **Breaking change**: Delete endpoint made private. - `postgresflex`: [0.17.0](services/postgresflex/CHANGELOG.md#v0170-2025-01-20) diff --git a/services/ske/CHANGELOG.md b/services/ske/CHANGELOG.md index d8bd46208..ac427ce14 100644 --- a/services/ske/CHANGELOG.md +++ b/services/ske/CHANGELOG.md @@ -1,3 +1,10 @@ +## v0.21.0 (2025-01-21) + +- **Removal:** The following methods were removed after deprecation (2024-04-16) and [`serviceenablement` SDK](https://github.com/stackitcloud/stackit-sdk-go/tree/main/services/serviceenablement) must be used instead. + - `DisableService` + - `EnableService` + - `GetServiceStatus` + ## v0.20.1 (2024-12-17) - **Bugfix:** Correctly handle nullable attributes in model types diff --git a/services/ske/wait/wait.go b/services/ske/wait/wait.go index 8ec9529a1..3750bb475 100644 --- a/services/ske/wait/wait.go +++ b/services/ske/wait/wait.go @@ -3,10 +3,8 @@ package wait import ( "context" "fmt" - "net/http" "time" - "github.com/stackitcloud/stackit-sdk-go/core/oapierror" "github.com/stackitcloud/stackit-sdk-go/core/wait" "github.com/stackitcloud/stackit-sdk-go/services/ske" ) @@ -26,10 +24,6 @@ const ( InvalidArgusInstanceErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND" ) -type APIClientProjectInterface interface { - GetServiceStatusExecute(ctx context.Context, projectId string) (*ske.ProjectResponse, error) -} - type APIClientClusterInterface interface { GetClusterExecute(ctx context.Context, projectId, name string) (*ske.Cluster, error) ListClustersExecute(ctx context.Context, projectId string) (*ske.ListClustersResponse, error) @@ -85,46 +79,6 @@ func DeleteClusterWaitHandler(ctx context.Context, a APIClientClusterInterface, return handler } -// EnableServiceWaitHandler will wait for service enablement -func EnableServiceWaitHandler(ctx context.Context, a APIClientProjectInterface, projectId string) *wait.AsyncActionHandler[ske.ProjectResponse] { - handler := wait.New(func() (waitFinished bool, response *ske.ProjectResponse, err error) { - s, err := a.GetServiceStatusExecute(ctx, projectId) - if err != nil { - return false, nil, err - } - state := *s.State - switch state { - case StateDeleting, StateFailed: - return false, nil, fmt.Errorf("received state: %s for project Id: %s", state, projectId) - case StateCreated: - return true, s, nil - } - return false, nil, nil - }) - handler.SetTimeout(15 * time.Minute) - return handler -} - -// DisableServiceWaitHandler will wait for service disablement -func DisableServiceWaitHandler(ctx context.Context, a APIClientProjectInterface, projectId string) *wait.AsyncActionHandler[struct{}] { - handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { - _, err = a.GetServiceStatusExecute(ctx, projectId) - if err == nil { - return false, nil, nil - } - oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped - if !ok { - return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError in delete wait.AsyncHandler, %w", err) - } - if oapiErr.StatusCode == http.StatusNotFound || oapiErr.StatusCode == http.StatusForbidden { - return true, nil, nil - } - return false, nil, err - }) - handler.SetTimeout(15 * time.Minute) - return handler -} - // RotateCredentialsWaitHandler will wait for credentials rotation func RotateCredentialsWaitHandler(ctx context.Context, a APIClientClusterInterface, projectId, clusterName string) *wait.AsyncActionHandler[ske.Cluster] { handler := wait.New(func() (waitFinished bool, response *ske.Cluster, err error) { diff --git a/services/ske/wait/wait_test.go b/services/ske/wait/wait_test.go index 36b5103b4..84b644209 100644 --- a/services/ske/wait/wait_test.go +++ b/services/ske/wait/wait_test.go @@ -67,31 +67,6 @@ func (a *apiClientClusterMocked) ListClustersExecute(_ context.Context, _ string }, nil } -// Used for testing cluster operations -type apiClientProjectMocked struct { - getFails bool - getNotFound bool - resourceState string -} - -func (a *apiClientProjectMocked) GetServiceStatusExecute(_ context.Context, _ string) (*ske.ProjectResponse, error) { - if a.getFails { - return nil, &oapierror.GenericOpenAPIError{ - StatusCode: http.StatusInternalServerError, - } - } - if a.getNotFound { - return nil, &oapierror.GenericOpenAPIError{ - StatusCode: http.StatusNotFound, - } - } - rs := ske.ProjectState(a.resourceState) - return &ske.ProjectResponse{ - ProjectId: utils.Ptr("pid"), - State: &rs, - }, nil -} - func TestCreateOrUpdateClusterWaitHandler(t *testing.T) { tests := []struct { desc string @@ -186,115 +161,6 @@ func TestCreateOrUpdateClusterWaitHandler(t *testing.T) { } } -func TestCreateProjectWaitHandler(t *testing.T) { - tests := []struct { - desc string - getFails bool - resourceState string - wantErr bool - wantResp bool - }{ - { - desc: "create_succeeded", - getFails: false, - resourceState: StateCreated, - wantErr: false, - wantResp: true, - }, - { - desc: "create_failed", - getFails: false, - wantErr: true, - wantResp: false, - }, - { - desc: "get_fails", - getFails: true, - wantErr: true, - wantResp: false, - }, - { - desc: "timeout", - getFails: false, - resourceState: "ANOTHER STATE", - wantErr: true, - wantResp: false, - }, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - apiClient := &apiClientProjectMocked{ - getFails: tt.getFails, - resourceState: tt.resourceState, - } - var wantRes *ske.ProjectResponse - rs := ske.ProjectState(tt.resourceState) - if tt.wantResp { - wantRes = &ske.ProjectResponse{ - ProjectId: utils.Ptr("pid"), - State: &rs, - } - } - - handler := EnableServiceWaitHandler(context.Background(), apiClient, "") - - gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) - - if (err != nil) != tt.wantErr { - t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) - } - if !cmp.Equal(gotRes, wantRes) { - t.Fatalf("handler gotRes = %+v, want %+v", gotRes, wantRes) - } - }) - } -} - -func TestDeleteProjectWaitHandler(t *testing.T) { - tests := []struct { - desc string - getFails bool - getNotFound bool - wantErr bool - resourceState string - }{ - { - desc: "delete_succeeded", - getFails: false, - getNotFound: true, - wantErr: false, - }, - { - desc: "get_fails", - getFails: true, - wantErr: true, - }, - { - desc: "timeout", - getFails: false, - wantErr: true, - resourceState: "ANOTHER STATE", - }, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - apiClient := &apiClientProjectMocked{ - getFails: tt.getFails, - getNotFound: tt.getNotFound, - resourceState: tt.resourceState, - } - - handler := DisableServiceWaitHandler(context.Background(), apiClient, "") - - _, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) - - if (err != nil) != tt.wantErr { - t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - func TestRotateCredentialsWaitHandler(t *testing.T) { tests := []struct { desc string