Skip to content

Commit 5e37fd1

Browse files
authored
fix(sqlserverflex): waiter handler fails in unknown state "pending" (#3873)
1 parent 2b4b998 commit 5e37fd1

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@
7878
- **Feature:** Add new enum `GetProviderOptionsRequestVersionState`
7979
- [v1.4.1](services/ske/CHANGELOG.md#v141)
8080
- Bump STACKIT SDK core module from `v0.19.0` to `v0.20.0`
81-
- `sqlserverflex`: [v1.3.2](services/sqlserverflex/CHANGELOG.md#v132)
82-
- Bump STACKIT SDK core module from `v0.19.0` to `v0.20.0`
81+
- `sqlserverflex`:
82+
- [v1.3.3](services/sqlserverflex/CHANGELOG.md#v133)
83+
- **Bugfix:** Adjust waiters to fail only in `Failure` or `Unknown` state
84+
- [v1.3.2](services/sqlserverflex/CHANGELOG.md#v132)
85+
- Bump STACKIT SDK core module from `v0.19.0` to `v0.20.0`
8386
- `stackitmarketplace`: [v1.17.1](services/stackitmarketplace/CHANGELOG.md#v1171)
8487
- Bump STACKIT SDK core module from `v0.19.0` to `v0.20.0`
8588
- `core`: [v0.20.0](core/CHANGELOG.md#v0200)

services/sqlserverflex/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v1.3.3
2+
- **Bugfix:** Adjust waiters to fail only in `Failure` or `Unknown` state
3+
14
## v1.3.2
25
- Bump STACKIT SDK core module from `v0.19.0` to `v0.20.0`
36

services/sqlserverflex/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.3.2
1+
v1.3.3

services/sqlserverflex/wait/wait.go

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package wait
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
8+
"strings"
79
"time"
810

911
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
@@ -34,19 +36,13 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
3436
if s == nil || s.Item == nil || s.Item.Id == nil || *s.Item.Id != instanceId || s.Item.Status == nil {
3537
return false, nil, nil
3638
}
37-
switch *s.Item.Status {
38-
default:
39-
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Item.Status)
40-
case InstanceStateEmpty:
41-
return false, s, nil
42-
case InstanceStateProcessing:
43-
return false, s, nil
44-
case InstanceStateUnknown:
45-
return false, s, nil
46-
case InstanceStateSuccess:
39+
switch strings.ToLower(*s.Item.Status) {
40+
case strings.ToLower(InstanceStateSuccess):
4741
return true, s, nil
48-
case InstanceStateFailed:
42+
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
4943
return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
44+
default:
45+
return false, s, nil
5046
}
5147
})
5248
handler.SetTimeout(45 * time.Minute)
@@ -64,19 +60,13 @@ func UpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
6460
if s == nil || s.Item == nil || s.Item.Id == nil || *s.Item.Id != instanceId || s.Item.Status == nil {
6561
return false, nil, nil
6662
}
67-
switch *s.Item.Status {
68-
default:
69-
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Item.Status)
70-
case InstanceStateEmpty:
71-
return false, s, nil
72-
case InstanceStateProcessing:
73-
return false, s, nil
74-
case InstanceStateUnknown:
75-
return false, s, nil
76-
case InstanceStateSuccess:
63+
switch strings.ToLower(*s.Item.Status) {
64+
case strings.ToLower(InstanceStateSuccess):
7765
return true, s, nil
78-
case InstanceStateFailed:
66+
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
7967
return true, s, fmt.Errorf("update failed for instance with id %s", instanceId)
68+
default:
69+
return false, s, nil
8070
}
8171
})
8272
handler.SetSleepBeforeWait(2 * time.Second)
@@ -96,7 +86,8 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
9686
if err == nil {
9787
return false, nil, nil
9888
}
99-
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
89+
var oapiErr *oapierror.GenericOpenAPIError
90+
ok := errors.As(err, &oapiErr)
10091
if !ok {
10192
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
10293
}

0 commit comments

Comments
 (0)