@@ -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 {},
0 commit comments