Skip to content

Commit 0c41608

Browse files
committed
examples, waiters, changelogs
1 parent f1be149 commit 0c41608

File tree

9 files changed

+562
-15
lines changed

9 files changed

+562
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
- `v2api`: New package which should be used for communication with the STACKIT authorization API in the future
124124
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new `v2api` package instead.
125125
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
126+
- `opensearch`: [v0.25.0](services/opensearch/CHANGELOG.md#v0250)
127+
- **Feature:** Introduction of multi API version support for the opensearch SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
128+
- `v1api`: New package which should be used for communication with the STACKIT opensearch API in the future
129+
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new `v1api` package instead.
130+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
126131

127132
## Release (2026-02-20)
128133
- `core`: [v0.21.1](core/CHANGELOG.md#v0211)

examples/opensearch/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ module github.com/stackitcloud/stackit-sdk-go/examples/opensearch
22

33
go 1.21
44

5+
// This is not needed in production. This is only here to point the golangci linter to the local version instead of the last release on GitHub.
6+
replace github.com/stackitcloud/stackit-sdk-go/services/opensearch => ../../services/opensearch
7+
58
require (
6-
github.com/stackitcloud/stackit-sdk-go/core v0.21.1
9+
github.com/stackitcloud/stackit-sdk-go/core v0.22.0
710
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6
811
)
912

examples/opensearch/go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
44
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
55
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
66
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7-
github.com/stackitcloud/stackit-sdk-go/core v0.21.1 h1:Y/PcAgM7DPYMNqum0MLv4n1mF9ieuevzcCIZYQfm3Ts=
8-
github.com/stackitcloud/stackit-sdk-go/core v0.21.1/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI=
9-
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6 h1:oTVx1+O177Ojn8OvXIOUbRSwtx7L59jhxDPrZEQFOfQ=
10-
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6/go.mod h1:6ZBeCCY6qG8w1oK7osf61Egyv3mp7Ahv6GDGxiarDGo=
7+
github.com/stackitcloud/stackit-sdk-go/core v0.22.0 h1:6rViz7GnNwXSh51Lur5xuDzO8EWSZfN9J0HvEkBKq6c=
8+
github.com/stackitcloud/stackit-sdk-go/core v0.22.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI=

examples/opensearch/opensearch.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"os"
77

88
"github.com/stackitcloud/stackit-sdk-go/core/config"
9-
"github.com/stackitcloud/stackit-sdk-go/core/utils"
10-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
9+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api"
1110
)
1211

1312
func main() {
@@ -24,15 +23,15 @@ func main() {
2423
}
2524

2625
// Get the opensearch instances for your project
27-
getInstancesResp, err := opensearchClient.ListInstances(context.Background(), projectId).Execute()
26+
getInstancesResp, err := opensearchClient.DefaultAPI.ListInstances(context.Background(), projectId).Execute()
2827
if err != nil {
2928
fmt.Fprintf(os.Stderr, "Error when calling `GetInstances`: %v\n", err)
3029
} else {
31-
fmt.Printf("Number of instances: %v\n", len(*getInstancesResp.Instances))
30+
fmt.Printf("Number of instances: %v\n", len(getInstancesResp.Instances))
3231
}
3332

3433
// Get the opensearch offerings for your project
35-
getOfferingsResp, err := opensearchClient.ListOfferings(context.Background(), projectId).Execute()
34+
getOfferingsResp, err := opensearchClient.DefaultAPI.ListOfferings(context.Background(), projectId).Execute()
3635
if err != nil {
3736
fmt.Fprintf(os.Stderr, "Error when calling `GetOfferings`: %v\n", err)
3837
} else {
@@ -41,14 +40,14 @@ func main() {
4140

4241
// Create a opensearch Instance
4342
createInstancePayload := opensearch.CreateInstancePayload{
44-
InstanceName: utils.Ptr("exampleInstance"),
43+
InstanceName: "exampleInstance",
4544
Parameters: &opensearch.InstanceParameters{},
46-
PlanId: utils.Ptr(planId),
45+
PlanId: planId,
4746
}
48-
createInstanceResp, err := opensearchClient.CreateInstance(context.Background(), projectId).CreateInstancePayload(createInstancePayload).Execute()
47+
createInstanceResp, err := opensearchClient.DefaultAPI.CreateInstance(context.Background(), projectId).CreateInstancePayload(createInstancePayload).Execute()
4948
if err != nil {
5049
fmt.Fprintf(os.Stderr, "Error when calling `CreateInstance`: %v\n", err)
5150
} else {
52-
fmt.Printf("Created instance with instance id \"%s\".\n", *createInstanceResp.InstanceId)
51+
fmt.Printf("Created instance with instance id \"%s\".\n", createInstanceResp.InstanceId)
5352
}
5453
}

services/opensearch/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v0.25.0
2+
- **Feature:** Introduction of multi API version support for the opensearch SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
3+
- `v1api`: New package which should be used for communication with the STACKIT opensearch API in the future
4+
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new `v1api` package instead.
5+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
6+
17
## v0.24.6
28
- Bump STACKIT SDK core module from `v0.21.0` to `v0.21.1`
39

services/opensearch/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.24.6
1+
v0.25.0
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package wait
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"strings"
8+
"time"
9+
10+
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
11+
"github.com/stackitcloud/stackit-sdk-go/core/wait"
12+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api"
13+
)
14+
15+
const (
16+
INSTANCESTATUS_ACTIVE = "active"
17+
INSTANCESTATUS_FAILED = "failed"
18+
INSTANCESTATUS_STOPPED = "stopped"
19+
INSTANCESTATUS_CREATING = "creating"
20+
INSTANCESTATUS_DELETING = "deleting"
21+
INSTANCESTATUS_UPDATING = "updating"
22+
23+
INSTANCELASTOPERATIONTYPE_CREATE = "create"
24+
INSTANCELASTOPERATIONTYPE_UPDATE = "update"
25+
INSTANCELASTOPERATIONTYPE_DELETE = "delete"
26+
)
27+
28+
// CreateInstanceWaitHandler will wait for instance creation
29+
func CreateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
30+
handler := wait.New(func() (waitFinished bool, response *opensearch.Instance, err error) {
31+
s, err := a.GetInstance(ctx, projectId, instanceId).Execute()
32+
if err != nil {
33+
return false, nil, err
34+
}
35+
if s.Status == nil {
36+
return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status are missing", instanceId)
37+
}
38+
switch *s.Status {
39+
case INSTANCESTATUS_ACTIVE:
40+
return true, s, nil
41+
case INSTANCESTATUS_FAILED:
42+
return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, s.LastOperation.Description)
43+
}
44+
return false, nil, nil
45+
})
46+
handler.SetTimeout(45 * time.Minute)
47+
return handler
48+
}
49+
50+
// PartialUpdateInstanceWaitHandler will wait for instance update
51+
func PartialUpdateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
52+
handler := wait.New(func() (waitFinished bool, response *opensearch.Instance, err error) {
53+
s, err := a.GetInstance(ctx, projectId, instanceId).Execute()
54+
if err != nil {
55+
return false, nil, err
56+
}
57+
if s.Status == nil {
58+
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)
59+
}
60+
switch *s.Status {
61+
case INSTANCESTATUS_ACTIVE:
62+
return true, s, nil
63+
case INSTANCESTATUS_FAILED:
64+
return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, s.LastOperation.Description)
65+
}
66+
return false, nil, nil
67+
})
68+
handler.SetTimeout(45 * time.Minute)
69+
return handler
70+
}
71+
72+
// DeleteInstanceWaitHandler will wait for instance deletion
73+
func DeleteInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[struct{}] {
74+
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
75+
s, err := a.GetInstance(ctx, projectId, instanceId).Execute()
76+
if err == nil {
77+
if s.Status == nil {
78+
return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status is missing", instanceId)
79+
}
80+
if *s.Status != INSTANCESTATUS_DELETING {
81+
return false, nil, nil
82+
}
83+
if *s.Status == INSTANCESTATUS_ACTIVE {
84+
if strings.Contains(s.LastOperation.Description, "DeleteFailed") || strings.Contains(s.LastOperation.Description, "failed") {
85+
return true, nil, fmt.Errorf("instance was deleted successfully but has errors: %s", s.LastOperation.Description)
86+
}
87+
return true, nil, nil
88+
}
89+
return false, nil, nil
90+
}
91+
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
92+
if !ok {
93+
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
94+
}
95+
if oapiErr.StatusCode != http.StatusGone {
96+
return false, nil, err
97+
}
98+
return true, nil, nil
99+
})
100+
handler.SetTimeout(15 * time.Minute)
101+
return handler
102+
}
103+
104+
// CreateCredentialsWaitHandler will wait for credentials creation
105+
func CreateCredentialsWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId, credentialsId string) *wait.AsyncActionHandler[opensearch.CredentialsResponse] {
106+
handler := wait.New(func() (waitFinished bool, response *opensearch.CredentialsResponse, err error) {
107+
s, err := a.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute()
108+
if err != nil {
109+
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
110+
if !ok {
111+
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
112+
}
113+
// If the request returns 404, the credentials have not been created yet
114+
if oapiErr.StatusCode == http.StatusNotFound {
115+
return false, nil, nil
116+
}
117+
return false, nil, err
118+
}
119+
if s.Id == credentialsId {
120+
return true, s, nil
121+
}
122+
return false, nil, nil
123+
})
124+
handler.SetTimeout(1 * time.Minute)
125+
return handler
126+
}
127+
128+
// DeleteCredentialsWaitHandler will wait for credentials deletion
129+
func DeleteCredentialsWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId, credentialsId string) *wait.AsyncActionHandler[struct{}] {
130+
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
131+
_, err = a.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute()
132+
if err == nil {
133+
return false, nil, nil
134+
}
135+
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
136+
if !ok {
137+
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
138+
}
139+
if oapiErr.StatusCode != http.StatusNotFound && oapiErr.StatusCode != http.StatusGone {
140+
return false, nil, err
141+
}
142+
return true, nil, nil
143+
})
144+
handler.SetTimeout(1 * time.Minute)
145+
return handler
146+
}

0 commit comments

Comments
 (0)