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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Release (2026-MM-DD)


- `alb`
- [v0.16.0](services/alb/CHANGELOG.md#v0160)
- **Breaking change**: Remove `v2beta2api` API
Expand Down Expand Up @@ -37,6 +36,9 @@
- [v0.2.0](services/modelexperiments/CHANGELOG.md#v020)
- **New**: STACKIT Model Experiments module wait handler added.
- `opensearch`:
- [v1.1.0](services/opensearch/CHANGELOG.md#v110)
- `v2api`
- **Feature**: Add `wait` handlers
- [v1.0.1](services/opensearch/CHANGELOG.md#v101)
- `v1api`:
- **Improvement**: Improve http error handling
Expand Down
4 changes: 4 additions & 0 deletions services/opensearch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.1.0
- `v2api`
- **Feature**: Add `wait` handlers

## v1.0.1
- `v1api`:
- **Improvement**: Improve http error handling
Expand Down
2 changes: 1 addition & 1 deletion services/opensearch/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.1
v1.1.0
121 changes: 121 additions & 0 deletions services/opensearch/v2api/wait/wait.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package wait

import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/wait"
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api"
)

// CreateInstanceWaitHandler will wait for instance creation
func CreateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
return createOrUpdateInstanceWaitHandler(ctx, a, projectId, region, instanceId)
}

// PartialUpdateInstanceWaitHandler will wait for instance update
func PartialUpdateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
return createOrUpdateInstanceWaitHandler(ctx, a, projectId, region, instanceId)
}

// DeleteInstanceWaitHandler will wait for instance deletion
func DeleteInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[struct{}] {
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
s, err := a.GetInstance(ctx, projectId, region, 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 != opensearch.INSTANCESTATUS_DELETING {
return false, nil, nil
}
if *s.Status == opensearch.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
})
handler.SetTimeout(15 * time.Minute)
return handler
}

// CreateCredentialsWaitHandler will wait for credentials creation
func CreateCredentialsWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, region, instanceId, credentialsId string) *wait.AsyncActionHandler[opensearch.CredentialsResponse] {
handler := wait.New(func() (waitFinished bool, response *opensearch.CredentialsResponse, err error) {
s, err := a.GetCredentials(ctx, projectId, region, instanceId, credentialsId).Execute()
if err != 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 the request returns 404, the credentials have not been created yet
if oapiErr.StatusCode == http.StatusNotFound {
return false, nil, nil
}
return false, nil, err
}
if s.Id == credentialsId {
return true, s, nil
}
return false, nil, nil
})
handler.SetTimeout(1 * time.Minute)
return handler
}

// DeleteCredentialsWaitHandler will wait for credentials deletion
func DeleteCredentialsWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, region, instanceId, credentialsId string) *wait.AsyncActionHandler[struct{}] {
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
_, err = a.GetCredentials(ctx, projectId, region, 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
})
handler.SetTimeout(1 * time.Minute)
return handler
}

func createOrUpdateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
waitConfig := wait.WaiterHelper[opensearch.Instance, opensearch.InstanceStatus]{
FetchInstance: a.GetInstance(ctx, projectId, region, instanceId).Execute,
GetState: func(s *opensearch.Instance) (opensearch.InstanceStatus, error) {
if s == nil {
return "", errors.New("empty response")
}
if s.Status == nil {
return "", errors.New("status is missing")
}
return *s.Status, nil
},
ActiveState: []opensearch.InstanceStatus{opensearch.INSTANCESTATUS_ACTIVE},
ErrorState: []opensearch.InstanceStatus{opensearch.INSTANCESTATUS_FAILED},
}

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