Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.1` to `v0.25.0`
- [v0.8.2](services/logs/CHANGELOG.md#v082)
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
- [v0.9.0](services/logs/CHANGELOG.md#v090)
- **Improvement:** Use new WaiterHelper for Logs waiters
- `mariadb`:
- [v0.27.3](services/mariadb/CHANGELOG.md#v0273)
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`
Expand Down
3 changes: 3 additions & 0 deletions services/logs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.9.0
- **Improvement:** Use new WaiterHelper for Logs waiters

## v0.8.2
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`

Expand Down
2 changes: 1 addition & 1 deletion services/logs/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.8.2
v0.9.0
56 changes: 29 additions & 27 deletions services/logs/v1api/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"time"

"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/wait"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
)
Expand All @@ -17,39 +16,42 @@ const (
instanceStatusDeleting = "deleting"
)

// CreateLogsInstanceWaitHandler will wait for logs instance creation
func CreateLogsInstanceWaitHandler(ctx context.Context, client logs.DefaultAPI, projectID, region, instanceID string) *wait.AsyncActionHandler[logs.LogsInstance] {
handler := wait.New(func() (waitFinished bool, response *logs.LogsInstance, err error) {
instance, err := client.GetLogsInstance(ctx, projectID, region, instanceID).Execute()
if err != nil {
return false, nil, err
}
if instance.Id == instanceID && instance.Status == instanceStatusActive {
return true, instance, nil
}
if instance.Status == instanceStatusDeleting {
return true, nil, fmt.Errorf("creating log instance failed, instance is being deleted")
}
return false, nil, nil
})
waitConfig := wait.WaiterHelper[logs.LogsInstance, string]{
FetchInstance: client.GetLogsInstance(ctx, projectID, region, instanceID).Execute,
GetState: func(l *logs.LogsInstance) (string, error) {
if l == nil {
return "", fmt.Errorf("empty response")
}
if l.Status == "" {
return "", fmt.Errorf("instance status is empty")
}
return l.Status, nil
},
ActiveState: []string{instanceStatusActive},
ErrorState: []string{instanceStatusDeleting},
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(10 * time.Minute)
return handler
}

// DeleteLogsInstanceWaitHandler will wait for logs instance deletion
func DeleteLogsInstanceWaitHandler(ctx context.Context, client logs.DefaultAPI, projectID, region, instanceID string) *wait.AsyncActionHandler[logs.LogsInstance] {
handler := wait.New(func() (waitFinished bool, response *logs.LogsInstance, err error) {
_, err = client.GetLogsInstance(ctx, projectID, region, instanceID).Execute()
// the instances is still gettable, e.g. not deleted, when the errors is null
if err == nil {
return false, nil, nil
}
var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound {
return true, nil, nil
waitConfig := wait.WaiterHelper[logs.LogsInstance, string]{
FetchInstance: client.GetLogsInstance(ctx, projectID, region, instanceID).Execute,
GetState: func(l *logs.LogsInstance) (string, error) {
if l == nil {
return "", errors.New("empty response")
}
}
return false, nil, err
})
return l.Status, nil
},
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(10 * time.Minute)
return handler
}
12 changes: 1 addition & 11 deletions services/logs/v1api/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ func TestCreateLogsInstanceWaitHandler(t *testing.T) {
Status: instanceStatusActive,
},
},
{
description: "create without id",
getFails: false,
wantErr: true,
wantResp: false,
returnInstance: true,
getLogsResponse: &logs.LogsInstance{
Status: instanceStatusActive,
},
},
{
description: "create without status",
getFails: false,
Expand All @@ -99,7 +89,7 @@ func TestCreateLogsInstanceWaitHandler(t *testing.T) {
getFails: false,
wantErr: true,
wantResp: false,
returnInstance: true,
returnInstance: false,
getLogsResponse: &logs.LogsInstance{
Id: instanceId,
Status: instanceStatusDeleting,
Expand Down
Loading