Skip to content

Commit

Permalink
Automatically fall back to client-side preview if server-side preview…
Browse files Browse the repository at this point in the history
… fails

Server-side apply previews currently require "patch" permission to run. For cases where the user doesn't have permission to perform a "patch" operation, attempt a graceful fallback to Client-side preview. The Client-side preview may not be 100% accurate, but is preferable to failing with a permission error.
  • Loading branch information
lblackstone committed May 19, 2023
1 parent eb991f3 commit 0de9d61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Breaking changes:

## Unreleased

- Automatically fall back to client-side preview if server-side preview fails (https://github.com/pulumi/pulumi-kubernetes/pull/2419)

## 3.28.0 (May 19, 2023)

Breaking changes:
Expand Down
7 changes: 6 additions & 1 deletion provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ func (k *kubeProvider) Update(
// Apply update.
initialized, awaitErr := await.Update(config)
if awaitErr != nil {
if req.GetPreview() && k.isDryRunDisabledError(err) {
if req.GetPreview() && apierrors.IsForbidden(awaitErr) {
logger.V(9).Infof("could not preview Update(%v): %v", urn, err)
return &pulumirpc.UpdateResponse{Properties: req.News}, nil
}
Expand Down Expand Up @@ -2732,6 +2732,11 @@ func (k *kubeProvider) tryServerSidePatch(
return ssPatch, ssPatchBase, true, nil
}

if apierrors.IsForbidden(err) {
// If the user doesn't have permission to run a Server-side preview, compute the patch using inputs
logger.V(1).Infof("unable to compute Server-side patch: %s", err)
return nil, nil, false, nil
}
if k.isDryRunDisabledError(err) {
return nil, nil, false, err
}
Expand Down

0 comments on commit 0de9d61

Please sign in to comment.