From c37f95c05f0754f5086dafd025949e561fdfb31a Mon Sep 17 00:00:00 2001 From: Oleksii Kurinnyi Date: Mon, 29 Dec 2025 20:28:29 +0200 Subject: [PATCH] test(e2e): fix debug mode test timing and add PVC cleanup Signed-off-by: Oleksii Kurinnyi --- test/e2e/pkg/client/devws.go | 34 +++++++++++++++++++ .../devworkspace_debug_poststart_tests.go | 14 ++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/test/e2e/pkg/client/devws.go b/test/e2e/pkg/client/devws.go index ab7d48020..dc9fdd98e 100644 --- a/test/e2e/pkg/client/devws.go +++ b/test/e2e/pkg/client/devws.go @@ -26,7 +26,9 @@ import ( dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" k8sErrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/wait" ) func (w *K8sClient) UpdateDevWorkspaceStarted(name, namespace string, started bool) error { @@ -105,3 +107,35 @@ func (w *K8sClient) DeleteDevWorkspace(name, namespace string) error { } return nil } + +// WaitForPVCDeleted waits for a PVC to be fully deleted from the cluster. +// Returns true if deleted successfully, false if timeout occurred. +func (w *K8sClient) WaitForPVCDeleted(pvcName, namespace string, timeout time.Duration) (bool, error) { + deleted := false + err := wait.PollImmediate(2*time.Second, timeout, func() (bool, error) { + _, err := w.Kube().CoreV1().PersistentVolumeClaims(namespace). + Get(context.TODO(), pvcName, metav1.GetOptions{}) + + if k8sErrors.IsNotFound(err) { + deleted = true + return true, nil + } + if err != nil { + return false, err + } + return false, nil + }) + return deleted, err +} + +// DeleteDevWorkspaceAndWait deletes a workspace and waits for its PVC to be fully removed. +// This ensures proper cleanup and prevents PVC conflicts in subsequent tests. +func (w *K8sClient) DeleteDevWorkspaceAndWait(name, namespace string) error { + if err := w.DeleteDevWorkspace(name, namespace); err != nil { + return err + } + + // Wait for shared PVC to be deleted (may take time in cloud environments) + _, err := w.WaitForPVCDeleted("claim-devworkspace", namespace, 2*time.Minute) + return err +} diff --git a/test/e2e/pkg/tests/devworkspace_debug_poststart_tests.go b/test/e2e/pkg/tests/devworkspace_debug_poststart_tests.go index 06edf0fed..b69611fb2 100644 --- a/test/e2e/pkg/tests/devworkspace_debug_poststart_tests.go +++ b/test/e2e/pkg/tests/devworkspace_debug_poststart_tests.go @@ -25,6 +25,14 @@ import ( var _ = ginkgo.Describe("[DevWorkspace Debug Start Mode]", func() { defer ginkgo.GinkgoRecover() + const workspaceName = "code-latest-with-debug-start" + + ginkgo.AfterEach(func() { + // Clean up workspace and wait for PVC to be fully deleted + // This prevents PVC conflicts in subsequent tests, especially in CI environments + _ = config.DevK8sClient.DeleteDevWorkspaceAndWait(workspaceName, config.DevWorkspaceNamespace) + }) + ginkgo.It("Wait DevWorkspace Webhook Server Pod", func() { controllerLabel := "app.kubernetes.io/name=devworkspace-webhook-server" @@ -39,21 +47,21 @@ var _ = ginkgo.Describe("[DevWorkspace Debug Start Mode]", func() { } }) - ginkgo.It("Add Debug DevWorkspace to cluster and wait starting status", func() { + ginkgo.It("Add Debug DevWorkspace to cluster and wait running status", func() { commandResult, err := config.DevK8sClient.OcApplyWorkspace(config.DevWorkspaceNamespace, "test/resources/simple-devworkspace-debug-start-annotation.yaml") if err != nil { ginkgo.Fail(fmt.Sprintf("Failed to create DevWorkspace: %s %s", err.Error(), commandResult)) return } - deploy, err := config.DevK8sClient.WaitDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace, dw.DevWorkspaceStatusStarting) + deploy, err := config.DevK8sClient.WaitDevWsStatus(workspaceName, config.DevWorkspaceNamespace, dw.DevWorkspaceStatusRunning) if !deploy { ginkgo.Fail(fmt.Sprintf("DevWorkspace didn't start properly. Error: %s", err)) } }) ginkgo.It("Check DevWorkspace Conditions for Debug Start message", func() { - devWorkspaceStatus, err := config.DevK8sClient.GetDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace) + devWorkspaceStatus, err := config.DevK8sClient.GetDevWsStatus(workspaceName, config.DevWorkspaceNamespace) if err != nil { ginkgo.Fail(fmt.Sprintf("Failure in fetching DevWorkspace status. Error: %s", err)) }