Skip to content

Commit 7b2f293

Browse files
committed
fix: do not delete workspace pod on authz errors
1 parent a3788c0 commit 7b2f293

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

agent/pkg/server/pulumi_errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ var knownErrors = knownPulumiErrors{
3131
Reason: "UpdateConflict",
3232
Code: 409,
3333
},
34+
"invalid access token": {
35+
Message: "Invalid access token used to authenticate with Pulumi Cloud",
36+
Reason: "InvalidAccessToken",
37+
Code: 401,
38+
},
3439
}
3540

3641
// withPulumiErrorInfo iterates over known errors and checks if the provided error matches any of them.

agent/pkg/server/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ func (s *Server) Cancel() {
175175
func (s *Server) WhoAmI(ctx context.Context, in *pb.WhoAmIRequest) (*pb.WhoAmIResult, error) {
176176
whoami, err := s.ws.WhoAmIDetails(ctx)
177177
if err != nil {
178-
return nil, err
178+
st := status.Newf(codes.Unknown, "whoami failed: %v", err)
179+
return nil, addStructuredErr(st, err).Err()
179180
}
180181
resp := &pb.WhoAmIResult{
181182
User: whoami.User,

operator/internal/controller/auto/workspace_controller.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
autov1alpha1 "github.com/pulumi/pulumi-kubernetes-operator/v2/operator/api/auto/v1alpha1"
3131
autov1alpha1webhook "github.com/pulumi/pulumi-kubernetes-operator/v2/operator/internal/webhook/auto/v1alpha1"
3232
"github.com/pulumi/pulumi-kubernetes-operator/v2/operator/version"
33+
"google.golang.org/grpc/status"
3334
appsv1 "k8s.io/api/apps/v1"
3435
corev1 "k8s.io/api/core/v1"
3536
"k8s.io/apimachinery/pkg/api/meta"
@@ -242,6 +243,31 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
242243
initializedV, ok := pod.Annotations[PodAnnotationInitialized]
243244
initialized, _ := strconv.ParseBool(initializedV)
244245
if !ok || !initialized {
246+
l.Info("Running whoami to ensure authentication is setup correctly with the workspace pod")
247+
_, err = wc.WhoAmI(ctx, &agentpb.WhoAmIRequest{})
248+
if err != nil {
249+
l.Error(err, "unable to run whoami; retaining the workspace pod to retry later")
250+
st := status.Convert(err)
251+
252+
ready.Status = metav1.ConditionFalse
253+
ready.Reason = st.Code().String()
254+
ready.Message = st.Message()
255+
256+
// Override with structured error from PulumiErrorInfo if provided.
257+
if len(st.Details()) > 0 {
258+
if info, ok := st.Details()[0].(*agentpb.PulumiErrorInfo); ok {
259+
ready.Reason = info.Reason
260+
ready.Message = info.Message
261+
}
262+
}
263+
264+
if statusErr := updateStatus(); statusErr != nil {
265+
return ctrl.Result{}, statusErr
266+
}
267+
268+
return ctrl.Result{}, err
269+
}
270+
245271
l.Info("Running pulumi install")
246272
ready.Status = metav1.ConditionFalse
247273
ready.Reason = "Installing"

0 commit comments

Comments
 (0)