diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd595e20..e167141ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,26 @@ ## Release (2025-XX-YY) - `cdn`: [v0.2.0](services/cdn/CHANGELOG.md#v020-2025-04-01) - **API enhancement:** Provide waiter infrastructure +- `logme`: [v0.21.2](services/logme/CHANGELOG.md#v0212-2025-04-02) + - **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded + - **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 +- `mariadb`: [v0.21.2](services/mariadb/CHANGELOG.md#v0212-2025-04-02) + - **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded + - **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 +- `opensearch`: [v0.20.2](services/opensearch/CHANGELOG.md#v0202-2025-04-02) + - **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded + - **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 +- `redis`: [v0.21.2](services/redis/CHANGELOG.md#v0212-2025-04-02) + - **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded + - **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 +- `rabbitmq`: [v0.21.2](services/rabbitmq/CHANGELOG.md#v0212-2025-04-02) + - **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded + - **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 + + ## Release (2025-03-27) + - `alb`: [v0.2.1](services/alb/CHANGELOG.md#v021-2025-03-27) - **Bugfix:** Removed ConfigureRegion() from API client - `cdn`: [v0.1.1](services/cdn/CHANGELOG.md#v011-2025-03-27) diff --git a/services/logme/CHANGELOG.md b/services/logme/CHANGELOG.md index b55972915..935510863 100644 --- a/services/logme/CHANGELOG.md +++ b/services/logme/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.21.2 (2025-04-02) +- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded +- **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 + ## v0.21.1 (2025-03-19) - **Internal:** Backwards compatible change to generated code diff --git a/services/logme/wait/wait.go b/services/logme/wait/wait.go index 92594c6f7..8f0e5947c 100644 --- a/services/logme/wait/wait.go +++ b/services/logme/wait/wait.go @@ -13,11 +13,23 @@ import ( ) const ( + InstanceStatusActive = "active" + InstanceStatusFailed = "failed" + InstanceStatusStopped = "stopped" + InstanceStatusCreating = "creating" + InstanceStatusDeleting = "deleting" + InstanceStatusUpdating = "updating" + + // Deprecated: InstanceStateSuccess is deprecated and will be removed after 2nd October 2025. InstanceStateSuccess = "succeeded" - InstanceStateFailed = "failed" - InstanceTypeCreate = "create" - InstanceTypeUpdate = "update" - InstanceTypeDelete = "delete" + // Deprecated: InstanceStateFailed is deprecated and will be removed after 2nd October 2025. + InstanceStateFailed = "failed" + // Deprecated: InstanceTypeCreate is deprecated and will be removed after 2nd October 2025. + InstanceTypeCreate = "create" + // Deprecated: InstanceTypeUpdate is deprecated and will be removed after 2nd October 2025. + InstanceTypeUpdate = "update" + // Deprecated: InstanceTypeDelete is deprecated and will be removed after 2nd October 2025. + InstanceTypeDelete = "delete" ) // Interface needed for tests @@ -37,14 +49,18 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status is missing", instanceId) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -59,14 +75,18 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + 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) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -79,13 +99,13 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { s, err := a.GetInstanceExecute(ctx, projectId, instanceId) if err == nil { - if s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil { - return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The last operation type, description or the state are missing", instanceId) + if s.LastOperation == nil || s.LastOperation.Description == nil || s.Status == nil { + return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status or last operation description are missing", instanceId) } - if *s.LastOperation.Type != InstanceTypeDelete { + if *s.Status != InstanceStatusDeleting { return false, nil, nil } - if *s.LastOperation.State == InstanceStateSuccess { + if *s.Status == InstanceStatusActive { 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) } diff --git a/services/logme/wait/wait_test.go b/services/logme/wait/wait_test.go index 87316d849..1d93cd921 100644 --- a/services/logme/wait/wait_test.go +++ b/services/logme/wait/wait_test.go @@ -21,11 +21,7 @@ type apiClientInstanceMocked struct { resourceDescription string } -var ( - instanceTypeCreate = InstanceTypeCreate - instanceTypeUpdate = InstanceTypeUpdate - instanceTypeDelete = InstanceTypeDelete -) +const deleteOperation = "delete" func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*logme.Instance, error) { if a.getFails { @@ -33,14 +29,13 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str StatusCode: 500, } } - if *a.resourceOperation == InstanceTypeDelete && a.resourceState == InstanceStateSuccess { + if a.resourceOperation != nil && *a.resourceOperation == deleteOperation && a.resourceState == InstanceStatusActive { if a.deletionSucceedsWithErrors { return &logme.Instance{ InstanceId: &a.resourceId, + Status: &a.resourceState, LastOperation: &logme.InstanceLastOperation{ Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, }, }, nil } @@ -51,11 +46,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str return &logme.Instance{ InstanceId: &a.resourceId, - LastOperation: &logme.InstanceLastOperation{ - Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, - }, + Status: utils.Ptr(a.resourceState), }, nil } @@ -96,14 +87,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) { { desc: "create_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "create_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -126,21 +117,16 @@ func TestCreateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeCreate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *logme.Instance if tt.wantResp { wantRes = &logme.Instance{ InstanceId: &instanceId, - LastOperation: &logme.InstanceLastOperation{ - Type: &instanceTypeCreate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -170,14 +156,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { { desc: "update_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "update_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -200,21 +186,16 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeUpdate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *logme.Instance if tt.wantResp { wantRes = &logme.Instance{ InstanceId: &instanceId, - LastOperation: &logme.InstanceLastOperation{ - Type: &instanceTypeUpdate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -246,7 +227,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { desc: "delete_succeeded", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, @@ -254,14 +235,14 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { desc: "delete_failed", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, { desc: "delete_succeeds_with_errors", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, deleteSucceeedsWithErrors: true, resourceDescription: "Deleting resource: cf failed with error: DeleteFailed", wantErr: true, @@ -283,7 +264,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { getFails: tt.getFails, deletionSucceedsWithErrors: tt.deleteSucceeedsWithErrors, resourceId: instanceId, - resourceOperation: &instanceTypeDelete, + resourceOperation: utils.Ptr(deleteOperation), resourceDescription: tt.resourceDescription, resourceState: tt.resourceState, } diff --git a/services/mariadb/CHANGELOG.md b/services/mariadb/CHANGELOG.md index 8a36b7227..fc7f23e66 100644 --- a/services/mariadb/CHANGELOG.md +++ b/services/mariadb/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.21.2 (2025-04-02) +- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded +- **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 + ## v0.21.1 (2025-03-19) - **Internal:** Backwards compatible change to generated code diff --git a/services/mariadb/wait/wait.go b/services/mariadb/wait/wait.go index 14a4177ec..56919283f 100644 --- a/services/mariadb/wait/wait.go +++ b/services/mariadb/wait/wait.go @@ -13,11 +13,23 @@ import ( ) const ( + InstanceStatusActive = "active" + InstanceStatusFailed = "failed" + InstanceStatusStopped = "stopped" + InstanceStatusCreating = "creating" + InstanceStatusDeleting = "deleting" + InstanceStatusUpdating = "updating" + + // Deprecated: InstanceStateSuccess is deprecated and will be removed after 2nd October 2025. InstanceStateSuccess = "succeeded" - InstanceStateFailed = "failed" - InstanceTypeCreate = "create" - InstanceTypeUpdate = "update" - InstanceTypeDelete = "delete" + // Deprecated: InstanceStateFailed is deprecated and will be removed after 2nd October 2025. + InstanceStateFailed = "failed" + // Deprecated: InstanceTypeCreate is deprecated and will be removed after 2nd October 2025. + InstanceTypeCreate = "create" + // Deprecated: InstanceTypeUpdate is deprecated and will be removed after 2nd October 2025. + InstanceTypeUpdate = "update" + // Deprecated: InstanceTypeDelete is deprecated and will be removed after 2nd October 2025. + InstanceTypeDelete = "delete" ) // Interface needed for tests @@ -37,14 +49,18 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status is missing", instanceId) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -59,14 +75,18 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + 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) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -79,13 +99,13 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { s, err := a.GetInstanceExecute(ctx, projectId, instanceId) if err == nil { - if s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil { - return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The last operation type, description or the state are missing", instanceId) + if s.LastOperation == nil || s.LastOperation.Description == nil || s.Status == nil { + return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status or last operation description are missing", instanceId) } - if *s.LastOperation.Type != InstanceTypeDelete { + if *s.Status != InstanceStatusDeleting { return false, nil, nil } - if *s.LastOperation.State == InstanceStateSuccess { + if *s.Status == InstanceStatusActive { 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) } diff --git a/services/mariadb/wait/wait_test.go b/services/mariadb/wait/wait_test.go index 2900018fa..ed03d33a4 100644 --- a/services/mariadb/wait/wait_test.go +++ b/services/mariadb/wait/wait_test.go @@ -21,11 +21,7 @@ type apiClientInstanceMocked struct { resourceDescription string } -var ( - instanceTypeCreate = InstanceTypeCreate - instanceTypeUpdate = InstanceTypeUpdate - instanceTypeDelete = InstanceTypeDelete -) +const deleteOperation = "delete" func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*mariadb.Instance, error) { if a.getFails { @@ -33,14 +29,13 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str StatusCode: 500, } } - if *a.resourceOperation == InstanceTypeDelete && a.resourceState == InstanceStateSuccess { + if a.resourceOperation != nil && *a.resourceOperation == deleteOperation && a.resourceState == InstanceStatusActive { if a.deletionSucceedsWithErrors { return &mariadb.Instance{ InstanceId: &a.resourceId, + Status: &a.resourceState, LastOperation: &mariadb.InstanceLastOperation{ Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, }, }, nil } @@ -51,11 +46,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str return &mariadb.Instance{ InstanceId: &a.resourceId, - LastOperation: &mariadb.InstanceLastOperation{ - Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, - }, + Status: &a.resourceState, }, nil } @@ -96,14 +87,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) { { desc: "create_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "create_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -126,21 +117,16 @@ func TestCreateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeCreate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *mariadb.Instance if tt.wantResp { wantRes = &mariadb.Instance{ InstanceId: &instanceId, - LastOperation: &mariadb.InstanceLastOperation{ - Type: &instanceTypeCreate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -170,14 +156,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { { desc: "update_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "update_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -200,21 +186,16 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeUpdate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *mariadb.Instance if tt.wantResp { wantRes = &mariadb.Instance{ InstanceId: &instanceId, - LastOperation: &mariadb.InstanceLastOperation{ - Type: &instanceTypeUpdate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -245,20 +226,20 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { desc: "delete_succeeded", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, }, { desc: "delete_failed", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, }, { desc: "delete_succeeds_with_errors", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, deleteSucceeedsWithErrors: true, resourceDescription: "Deleting resource: cf failed with error: DeleteFailed", wantErr: true, @@ -278,7 +259,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { getFails: tt.getFails, deletionSucceedsWithErrors: tt.deleteSucceeedsWithErrors, resourceId: instanceId, - resourceOperation: &instanceTypeDelete, + resourceOperation: utils.Ptr(deleteOperation), resourceDescription: tt.resourceDescription, resourceState: tt.resourceState, } diff --git a/services/opensearch/CHANGELOG.md b/services/opensearch/CHANGELOG.md index 3a112f01b..452db6e5f 100644 --- a/services/opensearch/CHANGELOG.md +++ b/services/opensearch/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.20.2 (2025-04-02) +- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded +- **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 + ## v0.20.1 (2025-03-19) - **Internal:** Backwards compatible change to generated code diff --git a/services/opensearch/wait/wait.go b/services/opensearch/wait/wait.go index e166462c7..a194456a1 100644 --- a/services/opensearch/wait/wait.go +++ b/services/opensearch/wait/wait.go @@ -13,11 +13,23 @@ import ( ) const ( + InstanceStatusActive = "active" + InstanceStatusFailed = "failed" + InstanceStatusStopped = "stopped" + InstanceStatusCreating = "creating" + InstanceStatusDeleting = "deleting" + InstanceStatusUpdating = "updating" + + // Deprecated: InstanceStateSuccess is deprecated and will be removed after 2nd October 2025. InstanceStateSuccess = "succeeded" - InstanceStateFailed = "failed" - InstanceTypeCreate = "create" - InstanceTypeUpdate = "update" - InstanceTypeDelete = "delete" + // Deprecated: InstanceStateFailed is deprecated and will be removed after 2nd October 2025. + InstanceStateFailed = "failed" + // Deprecated: InstanceTypeCreate is deprecated and will be removed after 2nd October 2025. + InstanceTypeCreate = "create" + // Deprecated: InstanceTypeUpdate is deprecated and will be removed after 2nd October 2025. + InstanceTypeUpdate = "update" + // Deprecated: InstanceTypeDelete is deprecated and will be removed after 2nd October 2025. + InstanceTypeDelete = "delete" ) // Interface needed for tests @@ -37,14 +49,18 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status are missing", instanceId) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -59,14 +75,18 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + 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) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -79,13 +99,13 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { s, err := a.GetInstanceExecute(ctx, projectId, instanceId) if err == nil { - if s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil { - return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The last operation type, description or the state are missing", instanceId) + if s.LastOperation == nil || s.LastOperation.Description == nil || s.Status == nil { + return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status or last operation description are missing", instanceId) } - if *s.LastOperation.Type != InstanceTypeDelete { + if *s.Status != InstanceStatusDeleting { return false, nil, nil } - if *s.LastOperation.State == InstanceStateSuccess { + if *s.Status == InstanceStatusActive { 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) } diff --git a/services/opensearch/wait/wait_test.go b/services/opensearch/wait/wait_test.go index 39ec03bbc..0980d61a1 100644 --- a/services/opensearch/wait/wait_test.go +++ b/services/opensearch/wait/wait_test.go @@ -21,11 +21,7 @@ type apiClientInstanceMocked struct { resourceDescription string } -var ( - instanceTypeCreate = InstanceTypeCreate - instanceTypeUpdate = InstanceTypeUpdate - instanceTypeDelete = InstanceTypeDelete -) +const deleteOperation = "delete" func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*opensearch.Instance, error) { if a.getFails { @@ -33,10 +29,11 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str StatusCode: 500, } } - if *a.resourceOperation == InstanceTypeDelete && a.resourceState == InstanceStateSuccess { + if a.resourceOperation != nil && *a.resourceOperation == deleteOperation && a.resourceState == InstanceStatusActive { if a.deletionSucceedsWithErrors { return &opensearch.Instance{ InstanceId: &a.resourceId, + Status: &a.resourceState, LastOperation: &opensearch.InstanceLastOperation{ Description: &a.resourceDescription, Type: a.resourceOperation, @@ -51,11 +48,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str return &opensearch.Instance{ InstanceId: &a.resourceId, - LastOperation: &opensearch.InstanceLastOperation{ - Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, - }, + Status: utils.Ptr(a.resourceState), }, nil } @@ -96,14 +89,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) { { desc: "create_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "create_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -126,21 +119,16 @@ func TestCreateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeCreate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *opensearch.Instance if tt.wantResp { wantRes = &opensearch.Instance{ InstanceId: &instanceId, - LastOperation: &opensearch.InstanceLastOperation{ - Type: &instanceTypeCreate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -170,14 +158,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { { desc: "update_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "update_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -200,21 +188,16 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeUpdate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *opensearch.Instance if tt.wantResp { wantRes = &opensearch.Instance{ InstanceId: &instanceId, - LastOperation: &opensearch.InstanceLastOperation{ - Type: &instanceTypeUpdate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -245,20 +228,20 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { desc: "delete_succeeded", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, }, { desc: "delete_failed", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, }, { desc: "delete_succeeds_with_errors", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, deleteSucceeedsWithErrors: true, resourceDescription: "Deleting resource: cf failed with error: DeleteFailed", wantErr: true, @@ -278,7 +261,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { getFails: tt.getFails, deletionSucceedsWithErrors: tt.deleteSucceeedsWithErrors, resourceId: instanceId, - resourceOperation: &instanceTypeDelete, + resourceOperation: utils.Ptr(deleteOperation), resourceDescription: tt.resourceDescription, resourceState: tt.resourceState, } diff --git a/services/rabbitmq/CHANGELOG.md b/services/rabbitmq/CHANGELOG.md index c7c649f0e..555a19e7e 100644 --- a/services/rabbitmq/CHANGELOG.md +++ b/services/rabbitmq/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.21.2 (2025-04-02) +- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded +- **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 + ## v0.21.1 (2025-03-19) - **Internal:** Backwards compatible change to generated code diff --git a/services/rabbitmq/wait/wait.go b/services/rabbitmq/wait/wait.go index cf355d586..32066a0b2 100644 --- a/services/rabbitmq/wait/wait.go +++ b/services/rabbitmq/wait/wait.go @@ -13,11 +13,23 @@ import ( ) const ( + InstanceStatusActive = "active" + InstanceStatusFailed = "failed" + InstanceStatusStopped = "stopped" + InstanceStatusCreating = "creating" + InstanceStatusDeleting = "deleting" + InstanceStatusUpdating = "updating" + + // Deprecated: InstanceStateSuccess is deprecated and will be removed after 2nd October 2025. InstanceStateSuccess = "succeeded" - InstanceStateFailed = "failed" - InstanceTypeCreate = "create" - InstanceTypeUpdate = "update" - InstanceTypeDelete = "delete" + // Deprecated: InstanceStateFailed is deprecated and will be removed after 2nd October 2025. + InstanceStateFailed = "failed" + // Deprecated: InstanceTypeCreate is deprecated and will be removed after 2nd October 2025. + InstanceTypeCreate = "create" + // Deprecated: InstanceTypeUpdate is deprecated and will be removed after 2nd October 2025. + InstanceTypeUpdate = "update" + // Deprecated: InstanceTypeDelete is deprecated and will be removed after 2nd October 2025. + InstanceTypeDelete = "delete" ) // Interface needed for tests @@ -37,14 +49,18 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status is missing", instanceId) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -59,14 +75,18 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + 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) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -79,13 +99,13 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { s, err := a.GetInstanceExecute(ctx, projectId, instanceId) if err == nil { - if s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil { - return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The last operation type, description or the state are missing", instanceId) + if s.LastOperation == nil || s.LastOperation.Description == nil || s.Status == nil { + return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status or last operation description are missing", instanceId) } - if *s.LastOperation.Type != InstanceTypeDelete { + if *s.Status != InstanceStatusDeleting { return false, nil, nil } - if *s.LastOperation.State == InstanceStateSuccess { + if *s.Status == InstanceStatusActive { 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) } diff --git a/services/rabbitmq/wait/wait_test.go b/services/rabbitmq/wait/wait_test.go index 09670f009..b0cc964d9 100644 --- a/services/rabbitmq/wait/wait_test.go +++ b/services/rabbitmq/wait/wait_test.go @@ -21,11 +21,7 @@ type apiClientInstanceMocked struct { resourceDescription string } -var ( - instanceTypeCreate = InstanceTypeCreate - instanceTypeUpdate = InstanceTypeUpdate - instanceTypeDelete = InstanceTypeDelete -) +const deleteOperation = "delete" func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*rabbitmq.Instance, error) { if a.getFails { @@ -33,10 +29,11 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str StatusCode: 500, } } - if *a.resourceOperation == InstanceTypeDelete && a.resourceState == InstanceStateSuccess { + if a.resourceOperation != nil && *a.resourceOperation == deleteOperation && a.resourceState == InstanceStatusActive { if a.deletionSucceedsWithErrors { return &rabbitmq.Instance{ InstanceId: &a.resourceId, + Status: &a.resourceState, LastOperation: &rabbitmq.InstanceLastOperation{ Description: &a.resourceDescription, Type: a.resourceOperation, @@ -51,11 +48,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str return &rabbitmq.Instance{ InstanceId: &a.resourceId, - LastOperation: &rabbitmq.InstanceLastOperation{ - Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, - }, + Status: utils.Ptr(a.resourceState), }, nil } @@ -96,14 +89,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) { { desc: "create_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "create_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -126,21 +119,16 @@ func TestCreateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeCreate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *rabbitmq.Instance if tt.wantResp { wantRes = &rabbitmq.Instance{ InstanceId: &instanceId, - LastOperation: &rabbitmq.InstanceLastOperation{ - Type: &instanceTypeCreate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -170,14 +158,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { { desc: "update_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "update_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -200,21 +188,16 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeUpdate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *rabbitmq.Instance if tt.wantResp { wantRes = &rabbitmq.Instance{ InstanceId: &instanceId, - LastOperation: &rabbitmq.InstanceLastOperation{ - Type: &instanceTypeUpdate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -245,20 +228,20 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { desc: "delete_succeeded", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, }, { desc: "delete_failed", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, }, { desc: "delete_succeeds_with_errors", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, deleteSucceeedsWithErrors: true, resourceDescription: "Deleting resource: cf failed with error: DeleteFailed", wantErr: true, @@ -278,7 +261,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { getFails: tt.getFails, deletionSucceedsWithErrors: tt.deleteSucceeedsWithErrors, resourceId: instanceId, - resourceOperation: &instanceTypeDelete, + resourceOperation: utils.Ptr(deleteOperation), resourceDescription: tt.resourceDescription, resourceState: tt.resourceState, } diff --git a/services/redis/CHANGELOG.md b/services/redis/CHANGELOG.md index 201c3d643..1af4f8232 100644 --- a/services/redis/CHANGELOG.md +++ b/services/redis/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.21.2 (2025-04-02) +- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded +- **Deprecation:** Deprecated `InstanceStateSuccess`, `InstanceStateFailed`, `InstanceTypeCreate`, `InstanceTypeUpdate`, `InstanceTypeDelete` and will be removed after 2nd October 2025 + ## v0.21.1 (2025-03-19) - **Internal:** Backwards compatible change to generated code diff --git a/services/redis/wait/wait.go b/services/redis/wait/wait.go index 98d2cebaf..890f82011 100644 --- a/services/redis/wait/wait.go +++ b/services/redis/wait/wait.go @@ -13,11 +13,23 @@ import ( ) const ( + InstanceStatusActive = "active" + InstanceStatusFailed = "failed" + InstanceStatusStopped = "stopped" + InstanceStatusCreating = "creating" + InstanceStatusDeleting = "deleting" + InstanceStatusUpdating = "updating" + + // Deprecated: InstanceStateSuccess is deprecated and will be removed after 2nd October 2025. InstanceStateSuccess = "succeeded" - InstanceStateFailed = "failed" - InstanceTypeCreate = "create" - InstanceTypeUpdate = "update" - InstanceTypeDelete = "delete" + // Deprecated: InstanceStateFailed is deprecated and will be removed after 2nd October 2025. + InstanceStateFailed = "failed" + // Deprecated: InstanceTypeCreate is deprecated and will be removed after 2nd October 2025. + InstanceTypeCreate = "create" + // Deprecated: InstanceTypeUpdate is deprecated and will be removed after 2nd October 2025. + InstanceTypeUpdate = "update" + // Deprecated: InstanceTypeDelete is deprecated and will be removed after 2nd October 2025. + InstanceTypeDelete = "delete" ) // Interface needed for tests @@ -37,14 +49,18 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status is missing", instanceId) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -59,14 +75,18 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn if err != nil { return false, nil, err } - if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil { - return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId) + if s.Status == nil { + 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) } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateSuccess { + switch *s.Status { + case InstanceStatusActive: return true, s, nil - } - if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateFailed { - return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, *s.LastOperation.Description) + case InstanceStatusFailed: + var failedDescription string + if s.LastOperation != nil && s.LastOperation.Description != nil { + failedDescription = *s.LastOperation.Description + } + return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, failedDescription) } return false, nil, nil }) @@ -79,13 +99,13 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface handler := wait.New(func() (waitFinished bool, response *struct{}, err error) { s, err := a.GetInstanceExecute(ctx, projectId, instanceId) if err == nil { - if s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil { - return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The last operation type, description or the state are missing", instanceId) + if s.LastOperation == nil || s.LastOperation.Description == nil || s.Status == nil { + return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status or last operation description are missing", instanceId) } - if *s.LastOperation.Type != InstanceTypeDelete { + if *s.Status != InstanceStatusDeleting { return false, nil, nil } - if *s.LastOperation.State == InstanceStateSuccess { + if *s.Status == InstanceStatusActive { 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) } diff --git a/services/redis/wait/wait_test.go b/services/redis/wait/wait_test.go index 5c1fe110c..52c49fb2c 100644 --- a/services/redis/wait/wait_test.go +++ b/services/redis/wait/wait_test.go @@ -21,11 +21,7 @@ type apiClientInstanceMocked struct { resourceDescription string } -var ( - instanceTypeCreate = InstanceTypeCreate - instanceTypeUpdate = InstanceTypeUpdate - instanceTypeDelete = InstanceTypeDelete -) +const deleteOperation = "delete" func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*redis.Instance, error) { if a.getFails { @@ -33,10 +29,11 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str StatusCode: 500, } } - if *a.resourceOperation == InstanceTypeDelete && a.resourceState == InstanceStateSuccess { + if a.resourceOperation != nil && *a.resourceOperation == deleteOperation && a.resourceState == InstanceStatusActive { if a.deletionSucceedsWithErrors { return &redis.Instance{ InstanceId: &a.resourceId, + Status: &a.resourceState, LastOperation: &redis.InstanceLastOperation{ Description: &a.resourceDescription, Type: a.resourceOperation, @@ -51,11 +48,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str return &redis.Instance{ InstanceId: &a.resourceId, - LastOperation: &redis.InstanceLastOperation{ - Description: &a.resourceDescription, - Type: a.resourceOperation, - State: &a.resourceState, - }, + Status: utils.Ptr(a.resourceState), }, nil } @@ -96,14 +89,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) { { desc: "create_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "create_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -126,21 +119,16 @@ func TestCreateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeCreate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *redis.Instance if tt.wantResp { wantRes = &redis.Instance{ InstanceId: &instanceId, - LastOperation: &redis.InstanceLastOperation{ - Type: &instanceTypeCreate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -170,14 +158,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { { desc: "update_succeeded", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, wantResp: true, }, { desc: "update_failed", getFails: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, wantResp: true, }, @@ -200,21 +188,16 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { instanceId := "foo-bar" apiClient := &apiClientInstanceMocked{ - getFails: tt.getFails, - resourceId: instanceId, - resourceOperation: &instanceTypeUpdate, - resourceState: tt.resourceState, + getFails: tt.getFails, + resourceId: instanceId, + resourceState: tt.resourceState, } var wantRes *redis.Instance if tt.wantResp { wantRes = &redis.Instance{ InstanceId: &instanceId, - LastOperation: &redis.InstanceLastOperation{ - Type: &instanceTypeUpdate, - State: utils.Ptr(tt.resourceState), - Description: utils.Ptr(""), - }, + Status: utils.Ptr(tt.resourceState), } } @@ -245,20 +228,20 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { desc: "delete_succeeded", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, wantErr: false, }, { desc: "delete_failed", getFails: false, deleteSucceeedsWithErrors: false, - resourceState: InstanceStateFailed, + resourceState: InstanceStatusFailed, wantErr: true, }, { desc: "delete_succeeds_with_errors", getFails: false, - resourceState: InstanceStateSuccess, + resourceState: InstanceStatusActive, deleteSucceeedsWithErrors: true, resourceDescription: "Deleting resource: cf failed with error: DeleteFailed", wantErr: true, @@ -278,7 +261,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) { getFails: tt.getFails, deletionSucceedsWithErrors: tt.deleteSucceeedsWithErrors, resourceId: instanceId, - resourceOperation: &instanceTypeDelete, + resourceOperation: utils.Ptr(deleteOperation), resourceDescription: tt.resourceDescription, resourceState: tt.resourceState, }