Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/e2e/pkg/client/devws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
14 changes: 11 additions & 3 deletions test/e2e/pkg/tests/devworkspace_debug_poststart_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this cleanup block also be required for other tests?

})

ginkgo.It("Wait DevWorkspace Webhook Server Pod", func() {
controllerLabel := "app.kubernetes.io/name=devworkspace-webhook-server"

Expand All @@ -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))
}
Expand Down
Loading