Skip to content

Conversation

@Allda
Copy link
Collaborator

@Allda Allda commented Jan 14, 2026

What does this PR do?

Add init container for workspace restoration

A new init container is added to the workspace deployment in case user choose to restore the workspace from backup.

By setting the workspace attribute "controller.devfile.io/restore-workspace" the controller sets a new init container instead of cloning data from git repository.

By default an automated path to restore image is used based on cluster settings. However user is capable overwrite that value using another attribute "controller.devfile.io/restore-source-image".

The restore container runs a wokspace-recovery.sh script that pull an image using oras an extract files to a /project directory.

What issues does this PR fix or reference?

#1525

Is it tested? How?

No automated tests are available in the first phase. I will add tests once I get the first approval that the concept is ok.

How to test:

  • Configure a cluster to enable backups
  • Create a new workspace and make changes in any of its files and save it.
  • Stop the workspace `kubectl patch devworkspace restore-workspace-2 --type=merge -p '{"spec": {"started": false}}'
  • Wait till it is stopped, and backup is executed for the workspace (verify the backup image exists in the registry)
  • Delete a workspace from cluster kubectl delete devworkspace restore-workspace-2
  • Add an attribute to the workspace CRD as shown below (controller.devfile.io/restore-workspace)
  • Create a workspace
  • Wait till it boots up and verify the changed file is present
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  labels:
    controller.devfile.io/creator: ""
  name: restore-workspace-2
spec:
  started: true
  routingClass: 'basic'
  template:
    attributes:
      controller.devfile.io/storage-type: common
      controller.devfile.io/restore-workspace: 'true'

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

What's missing:

  • integration with registry authentication
  • integration with build in OCP registry

Allda added 2 commits January 14, 2026 13:05
The function will be used across both backup and restore features and
should be accessed multiple places.

Signed-off-by: Ales Raszka <[email protected]>
A new init container is added to the workspace deployment in case user
choose to restore the workspace from backup.

By setting workspace attribute "controller.devfile.io/restore-workspace"
the controller sets a new init container instead of cloning data from
git repository.

By default an automated path to restore image is used based on cluster
settings. However user is capable overwrite that value using another
attribute "controller.devfile.io/restore-source-image".

The restore container runs a wokspace-recovery.sh script that pull an
image using oras an extract files to a /project directory.

Signed-off-by: Ales Raszka <[email protected]>
@openshift-ci
Copy link

openshift-ci bot commented Jan 14, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Allda
Once this PR has been reviewed and has the lgtm label, please assign dkwon17 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

return nil
}

func GetErnvinmentVariablesForProjectRestore(workspace *common.DevWorkspaceWithConfig) []corev1.EnvVar {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func GetErnvinmentVariablesForProjectRestore(workspace *common.DevWorkspaceWithConfig) []corev1.EnvVar {
func GetEnvironmentVariablesForProjectRestore(workspace *common.DevWorkspaceWithConfig) []corev1.EnvVar {

{Name: "BACKUP_IMAGE", Value: restoreSourceImage},
}...)

return &corev1.Container{
Copy link
Contributor

Choose a reason for hiding this comment

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

We need some default resources specified for this container

}

// Add init container to clone projects only if restore container wasn't created
if !workspaceRestoreCreated {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate please, why do we need fall back on this?
cc @dkwon17

) (*corev1.Container, error) {
wokrspaceTempplate := &workspace.Spec.Template
// Check if restore is requested via workspace attribute
if !wokrspaceTempplate.Attributes.Exists(constants.WorkspaceRestoreAttribute) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO I think it would be more readable if this check was done by the caller in devworkspace_controller.go

Copy link
Collaborator

Choose a reason for hiding this comment

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

In the example presented in the Is it tested? How? section of this PR, the example has:

controller.devfile.io/restore-workspace: 'true'

which made me assume that:

controller.devfile.io/restore-workspace: 'false'

would disable the restore functionality for the devworkspace.

Could we also check for "false" string here?

@@ -0,0 +1,65 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Copyright (c) 2019-2025 Red Hat, Inc.
// Copyright (c) 2019-2026 Red Hat, Inc.

@@ -0,0 +1,129 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Copyright (c) 2019-2025 Red Hat, Inc.
// Copyright (c) 2019-2026 Red Hat, Inc.

// from the DevWorkspace
BootstrapDevWorkspaceAttribute = "controller.devfile.io/bootstrap-devworkspace"

// WorkspaceRestoreAttribute defines whether workspace restore should be performed when creating a DevWorkspace.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// WorkspaceRestoreAttribute defines whether workspace restore should be performed when creating a DevWorkspace.
// WorkspaceRestoreAttribute defines whether workspace restore should be performed for a DevWorkspace.

Small suggestion

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants