-
Notifications
You must be signed in to change notification settings - Fork 67
Restore workspace from backup #1572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9a876c1
214b762
728f107
5480c1c
9db9b7c
dcbc7b3
1c706fe
83e8ac8
8fcc091
3b4676a
da714b3
15346d3
72dc09e
1dbe84b
500c993
27ee785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # | ||
| # Copyright (c) 2019-2026 Red Hat, Inc. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Devtools backup build | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
|
|
||
| build-project-backup-imgs: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| outputs: | ||
| git-sha: ${{ steps.git-sha.outputs.sha }} | ||
|
|
||
| steps: | ||
| - name: Checkout devworkspace-operator source code | ||
| uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | ||
|
|
||
| - name: Set output for Git short SHA | ||
| id: git-sha | ||
| run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Login to quay.io | ||
| uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc #v2.2.0 | ||
| with: | ||
| username: ${{ secrets.QUAY_USERNAME }} | ||
| password: ${{ secrets.QUAY_PASSWORD }} | ||
| registry: quay.io | ||
|
|
||
| - uses: oras-project/setup-oras@22ce207df3b08e061f537244349aac6ae1d214f6 #v1.2.4 | ||
| - run: | | ||
| cd project-backup/test-data | ||
| make run | ||
| oras push quay.io/devfile/project-backup-test:latest \ | ||
| --artifact-type application/vnd.devworkspace.backup.artifact.v1+json \ | ||
| --annotation devworkspace.name="sample" \ | ||
| --annotation devworkspace.namespace="sample" \ | ||
| --disable-path-validation \ | ||
| devworkspace-backup.tar.gz | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ import ( | |
| "github.com/devfile/devworkspace-operator/pkg/library/home" | ||
| kubesync "github.com/devfile/devworkspace-operator/pkg/library/kubernetes" | ||
| "github.com/devfile/devworkspace-operator/pkg/library/projects" | ||
| "github.com/devfile/devworkspace-operator/pkg/library/restore" | ||
| "github.com/devfile/devworkspace-operator/pkg/library/status" | ||
| "github.com/devfile/devworkspace-operator/pkg/provision/automount" | ||
| "github.com/devfile/devworkspace-operator/pkg/provision/metadata" | ||
|
|
@@ -353,21 +354,51 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request | |
| if err := projects.ValidateAllProjects(&workspace.Spec.Template); err != nil { | ||
| return r.failWorkspace(workspace, fmt.Sprintf("Invalid devfile: %s", err), metrics.ReasonBadRequest, reqLogger, &reconcileStatus), nil | ||
| } | ||
| // Add init container to clone projects | ||
| projectCloneOptions := projects.Options{ | ||
| Image: workspace.Config.Workspace.ProjectCloneConfig.Image, | ||
| Env: env.GetEnvironmentVariablesForProjectClone(workspace), | ||
| Resources: workspace.Config.Workspace.ProjectCloneConfig.Resources, | ||
| } | ||
| if workspace.Config.Workspace.ProjectCloneConfig.ImagePullPolicy != "" { | ||
| projectCloneOptions.PullPolicy = config.Workspace.ProjectCloneConfig.ImagePullPolicy | ||
| if restore.IsWorkspaceRestoreRequested(&workspace.Spec.Template) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see every reconcile checks The restore attribute should be automatically removed after successful completion. |
||
| // Add init container to restore workspace from backup if requested | ||
| restoreOptions := restore.Options{ | ||
| Env: env.GetEnvironmentVariablesForProjectRestore(workspace), | ||
| Resources: workspace.Config.Workspace.RestoreConfig.Resources, | ||
| } | ||
| if config.Workspace.ImagePullPolicy != "" { | ||
| restoreOptions.PullPolicy = corev1.PullPolicy(config.Workspace.ImagePullPolicy) | ||
| } else { | ||
| restoreOptions.PullPolicy = corev1.PullIfNotPresent | ||
| } | ||
| if workspaceRestore, registryAuthSecret, err := restore.GetWorkspaceRestoreInitContainer(ctx, workspace, r.Client, restoreOptions, r.Scheme, reqLogger); err != nil { | ||
| return r.failWorkspace(workspace, fmt.Sprintf("Failed to set up workspace-restore init container: %s", err), metrics.ReasonInfrastructureFailure, reqLogger, &reconcileStatus), nil | ||
| } else if workspaceRestore != nil { | ||
| devfilePodAdditions.InitContainers = append([]corev1.Container{*workspaceRestore}, devfilePodAdditions.InitContainers...) | ||
| if registryAuthSecret != nil { | ||
| // Add the registry auth secret volume | ||
| devfilePodAdditions.Volumes = append(devfilePodAdditions.Volumes, corev1.Volume{ | ||
| Name: constants.RegistryAuthVolumeName, | ||
| VolumeSource: corev1.VolumeSource{ | ||
| Secret: &corev1.SecretVolumeSource{ | ||
| SecretName: registryAuthSecret.Name, // You may want to make this configurable | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| } | ||
| } else { | ||
| projectCloneOptions.PullPolicy = corev1.PullPolicy(config.Workspace.ImagePullPolicy) | ||
| } | ||
| if projectClone, err := projects.GetProjectCloneInitContainer(&workspace.Spec.Template, projectCloneOptions, workspace.Config.Routing.ProxyConfig); err != nil { | ||
| return r.failWorkspace(workspace, fmt.Sprintf("Failed to set up project-clone init container: %s", err), metrics.ReasonInfrastructureFailure, reqLogger, &reconcileStatus), nil | ||
| } else if projectClone != nil { | ||
| devfilePodAdditions.InitContainers = append([]corev1.Container{*projectClone}, devfilePodAdditions.InitContainers...) | ||
| // Add init container to clone projects only if restore container wasn't created | ||
| projectCloneOptions := projects.Options{ | ||
| Image: workspace.Config.Workspace.ProjectCloneConfig.Image, | ||
| Env: env.GetEnvironmentVariablesForProjectClone(workspace), | ||
| Resources: workspace.Config.Workspace.ProjectCloneConfig.Resources, | ||
| } | ||
| if workspace.Config.Workspace.ProjectCloneConfig.ImagePullPolicy != "" { | ||
| projectCloneOptions.PullPolicy = config.Workspace.ProjectCloneConfig.ImagePullPolicy | ||
| } else { | ||
| projectCloneOptions.PullPolicy = corev1.PullPolicy(config.Workspace.ImagePullPolicy) | ||
| } | ||
| if projectClone, err := projects.GetProjectCloneInitContainer(&workspace.Spec.Template, projectCloneOptions, workspace.Config.Routing.ProxyConfig); err != nil { | ||
| return r.failWorkspace(workspace, fmt.Sprintf("Failed to set up project-clone init container: %s", err), metrics.ReasonInfrastructureFailure, reqLogger, &reconcileStatus), nil | ||
| } else if projectClone != nil { | ||
| devfilePodAdditions.InitContainers = append([]corev1.Container{*projectClone}, devfilePodAdditions.InitContainers...) | ||
| } | ||
| } | ||
|
|
||
| // Inject operator-configured init containers | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.