diff --git a/CHANGELOG.md b/CHANGELOG.md index 5558bbc75..53c133381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -210,6 +210,10 @@ - **Dependencies:** Bump STACKIT SDK core module from `v0.24.1` to `v0.25.0` - [v0.28.2](services/mariadb/CHANGELOG.md#v282) - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` + - [v0.29.0](services/mariadb/CHANGELOG.md#v290) + - **Improvement:** Use new WaiterHelper for Logs waiters + - **Breaking Change:** `v1api/wait/DeleteInstanceWaitHandler` now returns a `mariadb.Instance` instead of `struct{}` + - **Breaking Change:** `v1api/wait/DeleteCredentialsWaitHandler` now returns a `mariadb.CredentialsResponse` instead of `struct{}` - `modelserving`: - [v0.8.3](services/modelserving/CHANGELOG.md#v083) - **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1` diff --git a/services/mariadb/CHANGELOG.md b/services/mariadb/CHANGELOG.md index 569b1b632..006811ff1 100644 --- a/services/mariadb/CHANGELOG.md +++ b/services/mariadb/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.29.0 +- **Improvement:** Use new WaiterHelper for Logs waiters +- **Breaking Change:** `v1api/wait/DeleteInstanceWaitHandler` now returns a `mariadb.Instance` instead of `struct{}` +- **Breaking Change:** `v1api/wait/DeleteCredentialsWaitHandler` now returns a `mariadb.CredentialsResponse` instead of `struct{}` + ## v0.28.2 - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` diff --git a/services/mariadb/VERSION b/services/mariadb/VERSION index f53b7bda1..5bc296535 100644 --- a/services/mariadb/VERSION +++ b/services/mariadb/VERSION @@ -1 +1 @@ -v0.28.2 \ No newline at end of file +v0.29.0 \ No newline at end of file diff --git a/services/mariadb/v1api/wait/wait.go b/services/mariadb/v1api/wait/wait.go index 0330dc14f..485a3a74c 100644 --- a/services/mariadb/v1api/wait/wait.go +++ b/services/mariadb/v1api/wait/wait.go @@ -2,9 +2,9 @@ package wait import ( "context" + "errors" "fmt" "net/http" - "strings" "time" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" @@ -23,76 +23,58 @@ const ( // CreateInstanceWaitHandler will wait for instance creation func CreateInstanceWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[mariadb.Instance] { - handler := wait.New(func() (waitFinished bool, response *mariadb.Instance, err error) { - s, err := a.GetInstance(ctx, projectId, instanceId).Execute() - if err != nil { - return false, nil, err - } - if s.Status == nil { - return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status is missing", instanceId) - } - switch *s.Status { - case INSTANCESTATUS_ACTIVE: - return true, s, nil - case INSTANCESTATUS_FAILED: - return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, s.LastOperation.Description) - } - return false, nil, nil - }) + waitConfig := wait.WaiterHelper[mariadb.Instance, string]{ + FetchInstance: a.GetInstance(ctx, projectId, instanceId).Execute, + GetState: func(s *mariadb.Instance) (string, error) { + if s == nil || s.Status == nil { + return "", errors.New("response or status is nil") + } + return *s.Status, nil + }, + ActiveState: []string{INSTANCESTATUS_ACTIVE}, + ErrorState: []string{INSTANCESTATUS_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) handler.SetTimeout(45 * time.Minute) return handler } // PartialUpdateInstanceWaitHandler will wait for instance update func PartialUpdateInstanceWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[mariadb.Instance] { - handler := wait.New(func() (waitFinished bool, response *mariadb.Instance, err error) { - s, err := a.GetInstance(ctx, projectId, instanceId).Execute() - if err != nil { - return false, nil, err - } - if s.Status == nil { - return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id or the status are missing", instanceId) - } - switch *s.Status { - case INSTANCESTATUS_ACTIVE: - return true, s, nil - case INSTANCESTATUS_FAILED: - return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, s.LastOperation.Description) - } - return false, nil, nil - }) + waitConfig := wait.WaiterHelper[mariadb.Instance, string]{ + FetchInstance: a.GetInstance(ctx, projectId, instanceId).Execute, + GetState: func(s *mariadb.Instance) (string, error) { + if s == nil || s.Status == nil { + return "", errors.New("response or status is nil") + } + return *s.Status, nil + }, + ActiveState: []string{INSTANCESTATUS_ACTIVE}, + ErrorState: []string{INSTANCESTATUS_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) handler.SetTimeout(45 * time.Minute) return handler } // DeleteInstanceWaitHandler will wait for instance deletion -func DeleteInstanceWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[struct{}] { - handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { - s, err := a.GetInstance(ctx, projectId, instanceId).Execute() - if err == nil { - if s.Status == nil { - return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status is missing", instanceId) - } - if *s.Status != INSTANCESTATUS_DELETING { - return false, nil, nil +func DeleteInstanceWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[mariadb.Instance] { + waitConfig := wait.WaiterHelper[mariadb.Instance, string]{ + FetchInstance: func() (*mariadb.Instance, error) { + return a.GetInstance(ctx, projectId, instanceId).Execute() + }, + GetState: func(s *mariadb.Instance) (string, error) { + if s == nil || s.Status == nil { + return "", errors.New("response or status is nil") } - if *s.Status == INSTANCESTATUS_ACTIVE { - if strings.Contains(s.LastOperation.Description, "DeleteFailed") || strings.Contains(s.LastOperation.Description, "failed") { - return true, nil, fmt.Errorf("instance was deleted successfully but has errors: %s", s.LastOperation.Description) - } - return true, nil, 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") - } - if oapiErr.StatusCode != http.StatusGone { - return false, nil, err - } - return true, nil, nil - }) + return *s.Status, nil + }, + DeleteHttpErrorStatusCodes: []int{http.StatusNotFound, http.StatusGone}, + } + + handler := wait.New(waitConfig.Wait()) handler.SetTimeout(15 * time.Minute) return handler } @@ -122,21 +104,22 @@ func CreateCredentialsWaitHandler(ctx context.Context, a mariadb.DefaultAPI, pro } // DeleteCredentialsWaitHandler will wait for credentials deletion -func DeleteCredentialsWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId, credentialsId string) *wait.AsyncActionHandler[struct{}] { - handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { - _, err = a.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() - 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") - } - if oapiErr.StatusCode != http.StatusNotFound && oapiErr.StatusCode != http.StatusGone { - return false, nil, err - } - return true, nil, nil - }) +func DeleteCredentialsWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId, credentialsId string) *wait.AsyncActionHandler[mariadb.CredentialsResponse] { + waitConfig := wait.WaiterHelper[mariadb.CredentialsResponse, string]{ + FetchInstance: func() (*mariadb.CredentialsResponse, error) { + return a.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + }, + GetState: func(s *mariadb.CredentialsResponse) (string, error) { + if s == nil || s.Id == "" { + return "", errors.New("response or id is nil") + } + + return s.Id, nil + }, + DeleteHttpErrorStatusCodes: []int{http.StatusNotFound, http.StatusGone}, + } + + handler := wait.New(waitConfig.Wait()) handler.SetTimeout(1 * time.Minute) return handler }