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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"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)
|
databaseResp, err := getDatabase(ctx, r.client, projectId, instanceId, databaseId)
|
||||||
if err != nil {
|
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
|
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)
|
resp.State.RemoveResource(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -371,6 +372,8 @@ func toCreatePayload(model *Model) (*postgresflex.CreateDatabasePayload, error)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var databaseNotFoundErr = errors.New("database not found")
|
||||||
|
|
||||||
// The API does not have a GetDatabase endpoint, only ListDatabases
|
// 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) {
|
func getDatabase(ctx context.Context, client *postgresflex.APIClient, projectId, instanceId, databaseId string) (*postgresflex.InstanceDatabase, error) {
|
||||||
resp, err := client.ListDatabases(ctx, projectId, instanceId).Execute()
|
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 &database, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("database not found")
|
return nil, databaseNotFoundErr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue