Skip to content

Add user home mount for ephemeral storage when init-persistent-home i…#1649

Open
dkwon17 wants to merge 1 commit into
devfile:mainfrom
dkwon17:ephemeral-mount
Open

Add user home mount for ephemeral storage when init-persistent-home i…#1649
dkwon17 wants to merge 1 commit into
devfile:mainfrom
dkwon17:ephemeral-mount

Conversation

@dkwon17

@dkwon17 dkwon17 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

…s explicitly configured

What does this PR do?

If an init-persistent-home init container is explicitly defined in the DWOC's config.workspaces.initContainers field and if persistUserHome is enabled, a /user/home empty dir volume mount will be added to the workspace pod.

This is to allow consistent behaviour between ephemeral and non-ephemeral workspaces when persistUserHome is enabled and a custom init-persistent-home init container is defined.

What issues does this PR fix or reference?

https://redhat.atlassian.net/browse/CRW-11010

Is it tested? How?

Install DWO with the following catalog source:

apiVersion: operators.coreos.com/v1alpha1
  kind: CatalogSource
  metadata:
    name: dwo-custom
    namespace: openshift-marketplace
  spec:
    sourceType: grpc
    image: quay.io/dkwon17/devworkspace-operator-index:ephemeral-mount
    displayName: DWO Custom
    updateStrategy:   
      registryPoll:
        interval: 5m

For both cases, ensure that the global DWOC has persistUserHome enabled:

apiVersion: controller.devfile.io/v1alpha1
  kind: DevWorkspaceOperatorConfig
  metadata:
    name: devworkspace-operator-config
    namespace: openshift-operators
  config:   
    workspace:
      persistUserHome:
        enabled: true
Test case 1
  1. Create an Empty Workspace with ephemeral storage:
apiVersion: workspace.devfile.io/v1alpha2
  kind: DevWorkspace
  metadata:
    name: my-workspace
  spec:
    started: true
    template:
      attributes:
        controller.devfile.io/storage-type: ephemeral
      components:
        - name: tooling-container
          container:
            image: quay.io/devspaces/udi-rhel9:latest
  1. Verify pod has no init-persistent-home init container and no PVC created
Test case 2
  1. Update global DWOC such that init-persistent-home explicitly configured:
apiVersion: controller.devfile.io/v1alpha1
  kind: DevWorkspaceOperatorConfig
  metadata:
    name: devworkspace-operator-config
    namespace: openshift-operators
  config:
    workspace:
      initContainers:
        - name: init-persistent-home
          image: registry.access.redhat.com/ubi9/ubi-minimal:latest
          command: ["/bin/sh", "-c", "echo custom-init-ran"]
  1. Create an Empty Workspace with ephemeral storage:
apiVersion: workspace.devfile.io/v1alpha2
  kind: DevWorkspace
  metadata:
    name: my-workspace
  spec:
    started: true
    template:
      attributes:
        controller.devfile.io/storage-type: ephemeral
      components:
        - name: tooling-container
          container:
            image: quay.io/devspaces/udi-rhel9:latest
  1. Wait until workspace starts. Verify init-persistent-home ran, persistent-home volume is emptyDir (not PVC), no PVC created.

For example:

image image

PR Checklist

  • E2E tests pass (when PR is ready, comment /test v8-devworkspace-operator-e2e, v8-che-happy-path to trigger)
    • v8-devworkspace-operator-e2e: DevWorkspace e2e test
    • v8-che-happy-path: Happy path for verification integration with Che

Summary by CodeRabbit

Release Notes

  • New Features

    • Refined persistent home directory logic with enhanced support for ephemeral workspaces and improved initialization detection.
  • Tests

    • Added test scenarios validating persistent home functionality across ephemeral storage configurations and edge cases.

…s explicitly configured

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: dkwon17 <dakwon@redhat.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

NeedsPersistentHomeDirectory drops storage-strategy-based gating and adds ephemeral workspace handling: it now checks for existing /home/user/ mounts, requires at least one container component, and for ephemeral storage delegates to a new hasInitPersistentHomeInConfig helper. Two new test fixtures cover the ephemeral paths, and one fixture corrects an error message from "command" to "event".

Changes

Persistent Home Eligibility Rework

Layer / File(s) Summary
NeedsPersistentHomeDirectory: ephemeral-aware eligibility logic
pkg/library/home/persistentHome.go
Removes pkg/provision/storage import. Rewrites eligibility checks to iterate containers for existing /home/user/ mounts, short-circuits when no containers are found, and for ephemeral storage calls the new hasInitPersistentHomeInConfig helper instead of the former storageStrategySupportsPersistentHome path.
Test fixtures for new ephemeral branches and error message fix
pkg/library/home/testdata/persistent-home/creates-home-vm-with-ephemeral-storage.yaml, pkg/library/home/testdata/persistent-home/noop-ephemeral-storage-without-init-container.yaml, pkg/library/home/testdata/persistent-home/noop-if-init-prestartevent-already-defined.yaml
Adds two fixtures: one asserting a persistent-home volume and mount are added when init-persistent-home is configured in ephemeral mode, and one asserting no volume is added when it is absent. Updates the duplicate-prestart-event fixture's expected error from "command" to "event".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, the strategy's gone,
No more storage checks to lean on!
Ephemeral homes now need a hint—
an init container, clear as flint.
Two new fixtures seal the deal,
and "event" replaces "command"'s spiel! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a user home mount for ephemeral storage when the init-persistent-home container is present.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/library/home/persistentHome.go (1)

2-2: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the copyright header year to match the current guideline.

Line 2 still uses 2019-2025; the guideline requires 2019-{CURRENT_YEAR}.

As per coding guidelines, **/*.go: "All Go source files MUST start with the copyright header: '// Copyright (c) 2019-{CURRENT_YEAR} Red Hat, Inc.' followed by Apache License 2.0 license text".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/library/home/persistentHome.go` at line 2, Update the copyright header
year in the copyright comment to reflect the current year. Change the copyright
line from "Copyright (c) 2019-2025 Red Hat, Inc." to "Copyright (c)
2019-{CURRENT_YEAR} Red Hat, Inc." where {CURRENT_YEAR} is replaced with the
actual current year, as required by the coding guidelines for Go source files.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/library/home/persistentHome.go`:
- Line 2: Update the copyright header year in the copyright comment to reflect
the current year. Change the copyright line from "Copyright (c) 2019-2025 Red
Hat, Inc." to "Copyright (c) 2019-{CURRENT_YEAR} Red Hat, Inc." where
{CURRENT_YEAR} is replaced with the actual current year, as required by the
coding guidelines for Go source files.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db651927-8b6f-4f94-90d1-d0ecaa655bc4

📥 Commits

Reviewing files that changed from the base of the PR and between 32c3d0a and 05b7c9c.

📒 Files selected for processing (4)
  • pkg/library/home/persistentHome.go
  • pkg/library/home/testdata/persistent-home/creates-home-vm-with-ephemeral-storage.yaml
  • pkg/library/home/testdata/persistent-home/noop-ephemeral-storage-without-init-container.yaml
  • pkg/library/home/testdata/persistent-home/noop-if-init-prestartevent-already-defined.yaml

@tolusha

tolusha commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Hi! I'm che-ai-assistant — I help with your pull requests.

Available commands:

  • /che-ai-assistant generate-che-doc — Generate a documentation PR based on this PR's changes
  • /che-ai-assistant ok-pr-review — Run a comprehensive PR review (summary, code review, deep review, impact analysis)
  • /che-ai-assistant help — Show this help message

@rohanKanojia

rohanKanojia commented Jun 17, 2026

Copy link
Copy Markdown
Member

/che-ai-assistant ok-pr-review

Review is complete. Please check the review comments below.

@tolusha tolusha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

🎯 Overall Assessment: APPROVE

This PR successfully implements support for persistent home directories in ephemeral storage workspaces when a custom init-persistent-home init container is explicitly configured. The changes are well-structured, properly tested, and solve a real consistency problem between ephemeral and non-ephemeral workspaces.


✅ Strengths

  1. Clean Architecture - Removed coupling with storage package, making the home logic more self-contained and maintainable
  2. Proper Test Coverage - Added 2 comprehensive test cases covering both new behavior and backward compatibility
  3. Clear Logic - The special handling for ephemeral storage is explicit and easy to understand
  4. Backward Compatible - Existing workspaces without custom init containers maintain current behavior
  5. Good Error Fix - Corrected error message from "command" to "event" for accuracy

🔍 Key Observations

1. Behavioral Change for Non-Ephemeral Storage (Medium Priority)

The removal of storage.WorkspaceNeedsStorage() check simplifies the logic but changes behavior:

Before:

return storage.WorkspaceNeedsStorage(&workspace.Spec.Template)

After:

return true  // for all non-ephemeral storage

Impact: A workspace with non-ephemeral storage type but only ephemeral volumes will now get persistent home (previously wouldn't).

Question: Is this intentional? If so, consider adding a clarifying comment:

// For ephemeral storage, only add persistent home if init-persistent-home is configured
storageType := workspace.Spec.Template.Attributes.GetString(constants.DevWorkspaceStorageTypeAttribute, nil)
if storageType == constants.EphemeralStorageClassType {
    return hasInitPersistentHomeInConfig(workspace)
}

// For non-ephemeral storage types, always create persistent home if enabled.
// This includes workspaces with all ephemeral volumes but non-ephemeral storage type.
return true

2. Container Component Validation (Low Priority)

Good addition of the hasContainerComponents check - prevents edge cases where workspaces without containers would incorrectly trigger home creation.


💡 Suggestions for Improvement

  1. Additional Test Case (Optional)

    • Test workspace with non-ephemeral storage type but all volumes marked ephemeral
    • Validates the behavioral change mentioned above
  2. Documentation Update (Recommended)

    • Update operator docs to explain the new ephemeral + custom init behavior
    • Add example configuration showing this capability

📋 Pre-Merge Checklist

  • Code quality - Clean, maintainable changes
  • Unit tests - New tests added and passing
  • Logic correctness - Functions as designed
  • E2E tests - Waiting for /test v8-devworkspace-operator-e2e, v8-che-happy-path
  • Manual testing - Per test plan in PR description
  • Documentation - Consider updating user-facing docs

🎬 Recommendation

Approve and merge after E2E tests pass. The code changes are solid, well-tested, and implement the requested functionality correctly.

Technical Details Reviewed

  • ✅ Logic refactoring in NeedsPersistentHomeDirectory()
  • ✅ New helper function hasInitPersistentHomeInConfig()
  • ✅ Test coverage for new behavior
  • ✅ Backward compatibility maintained
  • ✅ Error message correction
  • ✅ Dependency reduction (removed storage import)

Review conducted: 2026-06-17
Files analyzed: 4 files (126 changed lines + context)
Test coverage: 2 new test cases added
Risk assessment: Low-Medium (E2E validation recommended)

@rohanKanojia

Copy link
Copy Markdown
Member

I tested as per abovementioned comment and can confirm it's working as expected:

When no init-persistent-home init container, ephemeral workspace starts without any init container

workspaceb387c01a8fb64a18-7ccd758878-h5r8t   0/1     ContainerCreating   0          2s
workspaceb387c01a8fb64a18-7ccd758878-h5r8t   1/1     Running             0          4s

When init-persistent-home init container is in DWOC, workspace has extra init init-persistent-home container

workspace8828788e71074dbc-8df88b6b6-hmwpj   0/1     Init:0/1      0          0s
workspace8828788e71074dbc-8df88b6b6-hmwpj   0/1     PodInitializing   0          19s
workspace8828788e71074dbc-8df88b6b6-hmwpj   1/1     Running           0          22s


output:
error: "failed to add init container for home persistence setup: command with id init-persistent-home already exists in the devworkspace"
error: "failed to add init container for home persistence setup: event with id init-persistent-home already exists in the devworkspace"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Umm, why is this change required?

@openshift-ci

openshift-ci Bot commented Jun 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dkwon17, rohanKanojia, tolusha

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants