Skip to content

Commit

Permalink
Do not propagate the error + fix webhoooks and teams too
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Aug 4, 2023
1 parent c3d27ac commit 48b27b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
5 changes: 2 additions & 3 deletions provider/pkg/internal/pulumiapi/deployment_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ func (c *Client) GetDeploymentSettings(ctx context.Context, stack StackName) (*D
if err != nil {
statusCode := GetErrorStatusCode(err)
if statusCode == http.StatusNotFound {
// Important: do now wrap this error so the provider knows to handle it as a
// deleted resource
return nil, err
// Important: we return nil here to hint it was not found
return nil, nil
}
return nil, fmt.Errorf("failed to get deployment settings for stack (%s): %w", stack.String(), err)
}
Expand Down
5 changes: 5 additions & 0 deletions provider/pkg/internal/pulumiapi/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func (c *Client) GetTeam(ctx context.Context, orgName string, teamName string) (
var team Team
_, err := c.do(ctx, http.MethodGet, apiPath, nil, &team)
if err != nil {
statusCode := GetErrorStatusCode(err)
if statusCode == http.StatusNotFound {
// Important: we return nil here to hint it was not found
return nil, nil
}
return nil, fmt.Errorf("failed to get team: %w", err)
}

Expand Down
5 changes: 5 additions & 0 deletions provider/pkg/internal/pulumiapi/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (c *Client) GetWebhook(ctx context.Context,
var webhook Webhook
_, err := c.do(ctx, http.MethodGet, apiPath, nil, &webhook)
if err != nil {
statusCode := GetErrorStatusCode(err)
if statusCode == http.StatusNotFound {
// Important: we return nil here to hint it was not found
return nil, nil
}
return nil, fmt.Errorf("failed to get webhook: %w", err)
}
return &webhook, nil
Expand Down
12 changes: 4 additions & 8 deletions provider/pkg/provider/deployment_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package provider
import (
"context"
"fmt"
"net/http"
"path"

pbempty "github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -530,15 +529,12 @@ func (ds *PulumiServiceDeploymentSettingsResource) Read(req *pulumirpc.ReadReque
}
settings, err := ds.client.GetDeploymentSettings(ctx, stack)
if err != nil {
statusCode := pulumiapi.GetErrorStatusCode(err)
if statusCode == http.StatusNotFound {
// deleteResponse causes the resource to be deleted from the state.
var deleteResponse = &pulumirpc.ReadResponse{Id: "", Properties: nil}
// If it's a 404 error, this resource was probably deleted.
return deleteResponse, nil
}
return nil, err
}

if settings == nil {
// Empty response causes the resource to be deleted from the state.
return &pulumirpc.ReadResponse{Id: "", Properties: nil}, nil
}

dsInput := PulumiServiceDeploymentSettingsInput{
Expand Down
4 changes: 4 additions & 0 deletions provider/pkg/provider/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ func (wh *PulumiServiceWebhookResource) Read(req *pulumirpc.ReadRequest) (*pulum
return nil, err
}

if webhook == nil {
return &pulumirpc.ReadResponse{}, nil
}

hookID, err := splitWebhookID(req.Id)
if err != nil {
return nil, err
Expand Down

0 comments on commit 48b27b6

Please sign in to comment.