fix(postgresflex): continue if database is not found during read (#629)
Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud>
This commit is contained in:
parent
1e0f33b759
commit
a1e7890d86
1 changed files with 5 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package postgresflex
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
|
@ -234,7 +235,7 @@ func (r *databaseResource) Read(ctx context.Context, req resource.ReadRequest, r
|
|||
databaseResp, err := getDatabase(ctx, r.client, projectId, instanceId, databaseId)
|
||||
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 && oapiErr.StatusCode == http.StatusNotFound {
|
||||
if (ok && oapiErr.StatusCode == http.StatusNotFound) || errors.Is(err, databaseNotFoundErr) {
|
||||
resp.State.RemoveResource(ctx)
|
||||
return
|
||||
}
|
||||
|
|
@ -371,6 +372,8 @@ func toCreatePayload(model *Model) (*postgresflex.CreateDatabasePayload, error)
|
|||
}, nil
|
||||
}
|
||||
|
||||
var databaseNotFoundErr = errors.New("database not found")
|
||||
|
||||
// The API does not have a GetDatabase endpoint, only ListDatabases
|
||||
func getDatabase(ctx context.Context, client *postgresflex.APIClient, projectId, instanceId, databaseId string) (*postgresflex.InstanceDatabase, error) {
|
||||
resp, err := client.ListDatabases(ctx, projectId, instanceId).Execute()
|
||||
|
|
@ -385,5 +388,5 @@ func getDatabase(ctx context.Context, client *postgresflex.APIClient, projectId,
|
|||
return &database, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("database not found")
|
||||
return nil, databaseNotFoundErr
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue