Skip to content

Commit b6678d2

Browse files
rohanKanojiadkwon17
authored andcommitted
fix (controller) : update DevWorkspace status with different message for debug start
When DevWorkspace contains 'controller.devfile.io/debug-start' annotation, set a different message for DevWorkspace Starting phase to give user indication that debug start mode is activated and they need to monitor DevWorkspace pod's logs or exec into it for debugging. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
1 parent af31133 commit b6678d2

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

controllers/workspace/devworkspace_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
324324
}
325325

326326
postStartDebugTrapSleepDuration := ""
327+
deploymentReadyConditionMessage := "Waiting for workspace deployment"
327328
if workspace.Annotations[constants.DevWorkspaceDebugStartAnnotation] == "true" {
329+
deploymentReadyConditionMessage = "Debug mode: failed postStart commands will be trapped; inspect logs/exec to debug"
330+
reconcileStatus.setConditionTrue(conditions.Started, "DevWorkspace is starting in debug mode")
328331
postStartDebugTrapSleepDuration = workspace.Config.Workspace.ProgressTimeout
329332
}
330333
devfilePodAdditions, err := containerlib.GetKubeContainersFromDevfile(
@@ -494,7 +497,7 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
494497
if err := wsprovision.SyncDeploymentToCluster(workspace, allPodAdditions, serviceAcctName, clusterAPI); err != nil {
495498
if shouldReturn, reconcileResult, reconcileErr := r.checkDWError(workspace, err, "Error creating DevWorkspace deployment", metrics.DetermineProvisioningFailureReason(err.Error()), reqLogger, &reconcileStatus); shouldReturn {
496499
reqLogger.Info("Waiting on deployment to be ready")
497-
reconcileStatus.setConditionFalse(conditions.DeploymentReady, "Waiting for workspace deployment")
500+
reconcileStatus.setConditionFalse(conditions.DeploymentReady, deploymentReadyConditionMessage)
498501
return reconcileResult, reconcileErr
499502
}
500503
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) 2019-2025 Red Hat, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package tests
15+
16+
import (
17+
"fmt"
18+
"strings"
19+
20+
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
21+
"github.com/devfile/devworkspace-operator/test/e2e/pkg/config"
22+
"github.com/onsi/ginkgo/v2"
23+
)
24+
25+
var _ = ginkgo.Describe("[DevWorkspace Debug Start Mode]", func() {
26+
defer ginkgo.GinkgoRecover()
27+
28+
ginkgo.It("Wait DevWorkspace Webhook Server Pod", func() {
29+
controllerLabel := "app.kubernetes.io/name=devworkspace-webhook-server"
30+
31+
deploy, err := config.AdminK8sClient.WaitForPodRunningByLabel(config.OperatorNamespace, controllerLabel)
32+
if err != nil {
33+
ginkgo.Fail(fmt.Sprintf("cannot get the DevWorkspace Webhook Server Pod status with label %s: %s", controllerLabel, err.Error()))
34+
return
35+
}
36+
37+
if !deploy {
38+
ginkgo.Fail("Devworkspace webhook didn't start properly")
39+
}
40+
})
41+
42+
ginkgo.It("Add Debug DevWorkspace to cluster and wait starting status", func() {
43+
commandResult, err := config.DevK8sClient.OcApplyWorkspace(config.DevWorkspaceNamespace, "test/resources/simple-devworkspace-debug-start-annotation.yaml")
44+
if err != nil {
45+
ginkgo.Fail(fmt.Sprintf("Failed to create DevWorkspace: %s %s", err.Error(), commandResult))
46+
return
47+
}
48+
49+
deploy, err := config.DevK8sClient.WaitDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace, dw.DevWorkspaceStatusStarting)
50+
if !deploy {
51+
ginkgo.Fail(fmt.Sprintf("DevWorkspace didn't start properly. Error: %s", err))
52+
}
53+
})
54+
55+
ginkgo.It("Check DevWorkspace Conditions for Debug Start message", func() {
56+
devWorkspaceStatus, err := config.DevK8sClient.GetDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace)
57+
if err != nil {
58+
ginkgo.Fail(fmt.Sprintf("Failure in fetching DevWorkspace status. Error: %s", err))
59+
}
60+
61+
expectedSubstring := "Debug mode: failed postStart commands will be trapped; inspect logs/exec to debug"
62+
63+
found := false
64+
for _, cond := range devWorkspaceStatus.Conditions {
65+
if cond.Message != "" && strings.Contains(cond.Message, expectedSubstring) {
66+
found = true
67+
break
68+
}
69+
}
70+
71+
if !found {
72+
ginkgo.Fail(fmt.Sprintf(
73+
"DevWorkspace status does not contain expected debug message.\nExpected substring: %q\nGot conditions: %+v",
74+
expectedSubstring, devWorkspaceStatus.Conditions,
75+
))
76+
}
77+
})
78+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
kind: DevWorkspace
2+
apiVersion: workspace.devfile.io/v1alpha2
3+
metadata:
4+
name: code-latest-with-debug-start
5+
annotations:
6+
controller.devfile.io/debug-start: "true"
7+
spec:
8+
started: true
9+
template:
10+
projects:
11+
- name: web-nodejs-sample
12+
git:
13+
remotes:
14+
origin: "https://github.com/che-samples/web-nodejs-sample.git"
15+
components:
16+
- name: dev
17+
container:
18+
image: quay.io/wto/web-terminal-tooling:latest
19+
args: ["tail", "-f", "/dev/null"]

0 commit comments

Comments
 (0)