-
Notifications
You must be signed in to change notification settings - Fork 68
feat(23570): Add controller for workspace backup #1530
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?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Allda The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
A new backup controller orchestrates a backup process for workspace PVC. A new configuration option is added to DevWorkspaceOperatorConfig that enables running regular cronjob that is responsible for backup mechanism. The job executes following steps: - Find a workspaces - Finds out that workspace has been recently stopped - Detect a workspace PVC - Execute a job in the same namespace that does the backup The last step is currently not fully implemented as it requires running a buildah inside the container and it will be delivered as a separate feature. Issue: eclipse-che/che#23570 Signed-off-by: Ales Raszka <[email protected]>
|
@Allda : Really appreciate you taking the time to contribute this in such a short time. 🎉 Could you please also fill out the “Is it tested? How?” section in the PR template? It’ll help reviewers and future contributors verify the change more easily. Thanks again for your effort! 🙌 |
|
I tested this PR and it seems to work.
config:
workspace:
backupCronJob:
enable: true
schedule: "*/3 * * * *"
|
d93f34e to
0bc74b1
Compare
A backup of workspace is done using Buildah and storing a content of the workspace PVC into a container image. The image is later stored in a registry and can be used to recover data. A prototype script was updated and stored under project-backup directory and is build alongside the controller. The backup job calls the script and execute following steps: - mount a volume with workspace data - build container image using buildah - push image to registry configured by the operator admin Signed-off-by: Ales Raszka <[email protected]>
A new sub-object was added to the operator config that reflect a current status of the backup controller and stores a last time the backup was executed. This value is used to determine whether a backup of the workspace is needed or if it already has been executed. Signed-off-by: Ales Raszka <[email protected]>
A backup job use a PVC name from a default value or from the config if user configured custom name. Signed-off-by: Ales Raszka <[email protected]>
|
/retest |
| export DWO_BUNDLE_IMG ?= quay.io/devfile/devworkspace-operator-bundle:next | ||
| export DWO_INDEX_IMG ?= quay.io/devfile/devworkspace-operator-index:next | ||
| export PROJECT_CLONE_IMG ?= quay.io/devfile/project-clone:next | ||
| export PROJECT_BACKUP_IMG ?= quay.io/devfile/project-clone:next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export PROJECT_BACKUP_IMG ?= quay.io/devfile/project-clone:next | |
| export PROJECT_BACKUP_IMG ?= quay.io/devfile/project-backup:next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it set incorrectly also for some other places.
| push: true | ||
| platforms: linux/amd64, linux/arm64, linux/ppc64le, linux/s390x | ||
| tags: | | ||
| quay.io/devfile/project-backup:next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repo quay.io/devfile/project-backup doesn't not exist yet
| // A registry where backup images are stored. Images are stored | ||
| // in {registry}/backup-${DEVWORKSPACE_NAMESPACE}-${DEVWORKSPACE_NAME} | ||
| // +kubebuilder:validation:Optional | ||
| Registry string `json:"registry,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if registry is not public and requires authentication and/or certificate to access.
| return err | ||
| } | ||
|
|
||
| job := &batchv1.Job{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do believe we need a dedicated SA for this job and delegate only required permissions.
@dkwon17 ?
| SecurityContext: &corev1.SecurityContext{ | ||
| RunAsUser: ptrInt64(0), | ||
| Capabilities: &corev1.Capabilities{ | ||
| Add: []corev1.Capability{"SYS_ADMIN", "SYS_CHROOT"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any particular reasons to have those capabilities?
| backUpConfig := dwOperatorConfig.Config.Workspace.BackupCronJob | ||
|
|
||
| // Find a PVC with the name "claim-devworkspace" or based on the name from the operator config | ||
| pvcName := "claim-devworkspace" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PVC name will not always be claim-devworkspace,
There are two main types of storage strategies for DevWorkspaces, common (or, per-user), and per-workspace
Here are some more details about the storage strategies: https://eclipse.dev/che/docs/stable/administration-guide/configuring-the-storage-strategy/
For common, the default PVC name is claim-devworkspace, and for per-workspace, the PVC name is storage-<devworkspaceid>
I suggest using for example GetProvisioner to help determine the storage policy,
and to determine the PVC name, the code is currently determining that like so:
devworkspace-operator/pkg/provision/storage/commonStorage.go
Lines 58 to 65 in b61eaed
| usingAlternatePVC, pvcName, err := checkForAlternatePVC(workspace.Namespace, clusterAPI) | |
| if err != nil { | |
| return err | |
| } | |
| if pvcName == "" { | |
| pvcName = workspace.Config.Workspace.PVCName | |
| } |
devworkspace-operator/pkg/provision/storage/perWorkspaceStorage.go
Lines 61 to 65 in b61eaed
| perWorkspacePVC, err := syncPerWorkspacePVC(workspace, clusterAPI) | |
| if err != nil { | |
| return err | |
| } | |
| pvcName := perWorkspacePVC.Name |
A new backup controller orchestrates a backup process for workspace PVC. A new configuration option is added to DevWorkspaceOperatorConfig that enables running regular cronjob that is responsible for backup mechanism. The job executes following steps:
The last step is currently not fully implemented as it requires running a buildah inside the container and it will be delivered as a separate feature.
Issue: eclipse-che/che#23570
What does this PR do?
What issues does this PR fix or reference?
Is it tested? How?
The feature has been tested locally and using integration tests. Following configuration should be added to the config to enable this feature:
After a config is added, stop any workspace and wait till a backup job is created.
The job creates a backup and push image to registry
PR Checklist
/test v8-devworkspace-operator-e2e, v8-che-happy-pathto trigger)v8-devworkspace-operator-e2e: DevWorkspace e2e testv8-che-happy-path: Happy path for verification integration with Che