diff --git a/controllers/workspace/devworkspace_controller.go b/controllers/workspace/devworkspace_controller.go index af22707e2..2565d353e 100644 --- a/controllers/workspace/devworkspace_controller.go +++ b/controllers/workspace/devworkspace_controller.go @@ -125,6 +125,12 @@ func (r *DevWorkspaceReconciler) Reconcile(req ctrl.Request) (reconcileResult ct // Stop failed workspaces if workspace.Status.Phase == devworkspacePhaseFailing && workspace.Spec.Started { + // If debug annotation is present, leave the deployment in place to let users + // view logs. + if workspace.Annotations[constants.DevWorkspaceDebugStartAnnotation] == "true" { + return reconcile.Result{}, nil + } + patch := []byte(`{"spec":{"started": false}}`) err := r.Client.Patch(context.Background(), workspace, client.RawPatch(types.MergePatchType, patch)) if err != nil { diff --git a/pkg/constants/metadata.go b/pkg/constants/metadata.go index 04a25755d..aab78bf6a 100644 --- a/pkg/constants/metadata.go +++ b/pkg/constants/metadata.go @@ -47,6 +47,10 @@ const ( // this annotation will be cleared DevWorkspaceStopReasonAnnotation = "controller.devfile.io/stopped-by" + // DevWorkspaceDebugStartAnnotation enables debugging workspace startup if set to "true". If a workspace with this annotation + // fails to start (i.e. enters the "Failed" phase), its deployment will not be scaled down in order to allow viewing logs, etc. + DevWorkspaceDebugStartAnnotation = "controller.devfile.io/debug-start" + // WebhookRestartedAtAnnotation holds the the time (unixnano) of when the webhook server was forced to restart by controller WebhookRestartedAtAnnotation = "controller.devfile.io/restarted-at"