Skip to content

Commit b79d90d

Browse files
Alldadkwon17
authored andcommitted
Skip backup if the workspace is missing volumes
Workspace with no storage failed in the backup process. This commit fixes it by checking if the volumes are present and skip the job if no pvc is available. fixes: 1555 Signed-off-by: Ales Raszka <araszka@redhat.com>
1 parent d787aeb commit b79d90d

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

controllers/backupcronjob/backupcronjob_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,9 @@ func (r *BackupCronJobReconciler) createBackupJob(
357357
return err
358358
}
359359
if pvcName == "" {
360-
log.Error(err, "No PVC found for DevWorkspace", "id", dwID)
361-
return err
360+
// No PVC to back up
361+
log.Info("No workspace PVC found, skipping backup", "devworkspace", workspace.Name)
362+
return nil
362363
}
363364

364365
pvc := &corev1.PersistentVolumeClaim{}

controllers/backupcronjob/backupcronjob_controller_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,39 @@ var _ = Describe("BackupCronJobReconciler", func() {
522522
Expect(fakeClient.List(ctx, jobList, &client.ListOptions{Namespace: dw.Namespace})).To(Succeed())
523523
Expect(jobList.Items).To(HaveLen(1))
524524
})
525+
It("It doesn't create a Job for a DevWorkspace with no PVC", func() {
526+
enabled := true
527+
schedule := "* * * * *"
528+
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
529+
ObjectMeta: metav1.ObjectMeta{Name: nameNamespace.Name, Namespace: nameNamespace.Namespace},
530+
Config: &controllerv1alpha1.OperatorConfiguration{
531+
Workspace: &controllerv1alpha1.WorkspaceConfig{
532+
BackupCronJob: &controllerv1alpha1.BackupCronJobConfig{
533+
Enable: &enabled,
534+
Schedule: schedule,
535+
Registry: &controllerv1alpha1.RegistryConfig{
536+
Path: "fake-registry",
537+
},
538+
OrasConfig: &controllerv1alpha1.OrasConfig{
539+
ExtraArgs: "--extra-arg1",
540+
},
541+
},
542+
},
543+
},
544+
}
545+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
546+
dw := createDevWorkspace("dw-recent", "ns-a", false, metav1.NewTime(time.Now().Add(-10*time.Minute)))
547+
dw.Spec.Template.Components = []dwv2.Component{} // No volume component, so no PVC
548+
dw.Status.Phase = dwv2.DevWorkspaceStatusStopped
549+
dw.Status.DevWorkspaceId = "id-recent"
550+
Expect(fakeClient.Create(ctx, dw)).To(Succeed())
551+
552+
Expect(reconciler.executeBackupSync(ctx, dwoc, log)).To(Succeed())
553+
554+
jobList := &batchv1.JobList{}
555+
Expect(fakeClient.List(ctx, jobList, &client.ListOptions{Namespace: dw.Namespace})).To(Succeed())
556+
Expect(jobList.Items).To(HaveLen(0))
557+
})
525558
})
526559
Context("ensureJobRunnerRBAC", func() {
527560
It("creates ServiceAccount for Job runner", func() {
@@ -907,6 +940,28 @@ func createDevWorkspace(name, namespace string, started bool, lastTransitionTime
907940
},
908941
Spec: dwv2.DevWorkspaceSpec{
909942
Started: started,
943+
Template: dwv2.DevWorkspaceTemplateSpec{
944+
DevWorkspaceTemplateSpecContent: dwv2.DevWorkspaceTemplateSpecContent{
945+
Components: []dwv2.Component{
946+
{
947+
Name: "test-container",
948+
ComponentUnion: dwv2.ComponentUnion{
949+
Container: &dwv2.ContainerComponent{
950+
Container: dwv2.Container{
951+
Image: "test-image:latest",
952+
},
953+
},
954+
Volume: &dwv2.VolumeComponent{
955+
Volume: dwv2.Volume{
956+
Ephemeral: pointer.BoolPtr(true),
957+
Size: "1Mi",
958+
},
959+
},
960+
},
961+
},
962+
},
963+
},
964+
},
910965
},
911966
Status: dwv2.DevWorkspaceStatus{
912967
Conditions: []dwv2.DevWorkspaceCondition{},

pkg/library/storage/storage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func GetWorkspacePVCInfo(
4949
if err != nil {
5050
return "", "", err
5151
}
52+
if !storageProvisioner.NeedsStorage(&workspace.Spec.Template) {
53+
// No storage provisioned for this workspace
54+
return "", "", nil
55+
}
5256

5357
if _, ok := storageProvisioner.(*storage.PerWorkspaceStorageProvisioner); ok {
5458
pvcName := common.PerWorkspacePVCName(workspace.Status.DevWorkspaceId)

0 commit comments

Comments
 (0)