Skip to content

Commit ce02b9c

Browse files
committed
examples, waiters, changelogs
1 parent a12f10e commit ce02b9c

File tree

9 files changed

+558
-15
lines changed

9 files changed

+558
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
- `v1betaapi`: New package which can be used for communication with the kms v1 beta API
100100
- **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 packages for the available API versions instead.
101101
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
102+
- `mariadb`: [v0.26.0](services/mariadb/CHANGELOG.md#v0260)
103+
- **Feature:** Introduction of multi API version support for the mariadb SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
104+
- `v1api`: New package which should be used for communication with the STACKIT mariadb API in the future
105+
- **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 `v0api` package instead.
106+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
102107

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

examples/mariadb/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/mariadb
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/mariadb => ../../services/mariadb
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/mariadb v0.25.6
811
)
912

examples/mariadb/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/mariadb v0.25.6 h1:Y/byRjX2u/OZl0gKS/Rau6ob2bDyv26xnw6A6JNkKJk=
10-
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.6/go.mod h1:sY66ZgCgBc1mScPV95ek5WtUEGYizdP1RMsGaqbdbhw=
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/mariadb/mariadb.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/mariadb"
9+
mariadb "github.com/stackitcloud/stackit-sdk-go/services/mariadb/v1api"
1110
)
1211

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

2625
// Get the mariadb instances for your project
27-
getInstancesResp, err := mariadbClient.ListInstances(context.Background(), projectId).Execute()
26+
getInstancesResp, err := mariadbClient.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 mariadb offerings for your project
35-
getOfferingsResp, err := mariadbClient.ListOfferings(context.Background(), projectId).Execute()
34+
getOfferingsResp, err := mariadbClient.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 mariadb Instance
4342
createInstancePayload := mariadb.CreateInstancePayload{
44-
InstanceName: utils.Ptr("exampleInstance"),
43+
InstanceName: "exampleInstance",
4544
Parameters: &mariadb.InstanceParameters{},
46-
PlanId: utils.Ptr(planId),
45+
PlanId: planId,
4746
}
48-
createInstanceResp, err := mariadbClient.CreateInstance(context.Background(), projectId).CreateInstancePayload(createInstancePayload).Execute()
47+
createInstanceResp, err := mariadbClient.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/mariadb/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v0.26.0
2+
- **Feature:** Introduction of multi API version support for the mariadb 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 mariadb 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 `v0api` package instead.
5+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
6+
17
## v0.25.6
28
- Bump STACKIT SDK core module from `v0.21.0` to `v0.21.1`
39

services/mariadb/VERSION

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

0 commit comments

Comments
 (0)