@@ -263,8 +263,8 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
263
263
_ , createPVC = pod .Labels [pvcWorkspaceFeatureLabel ]
264
264
265
265
if createPVC {
266
+ var volumeSnapshot volumesnapshotv1.VolumeSnapshot
266
267
if startContext .VolumeSnapshot != nil && startContext .VolumeSnapshot .VolumeSnapshotName != "" {
267
- var volumeSnapshot volumesnapshotv1.VolumeSnapshot
268
268
err = m .Clientset .Get (ctx , types.NamespacedName {Namespace : m .Config .Namespace , Name : startContext .VolumeSnapshot .VolumeSnapshotName }, & volumeSnapshot )
269
269
if k8serr .IsNotFound (err ) {
270
270
// restore volume snapshot from handle
@@ -273,12 +273,31 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
273
273
clog .WithError (err ).Error ("was unable to restore volume snapshot" )
274
274
return nil , err
275
275
}
276
+
277
+ // update the volumeSnapshot variable
278
+ if err := m .Clientset .Get (ctx , types.NamespacedName {Namespace : m .Config .Namespace , Name : startContext .VolumeSnapshot .VolumeSnapshotName }, & volumeSnapshot ); err != nil {
279
+ return nil , err
280
+ }
276
281
} else if err != nil {
277
282
clog .WithError (err ).Error ("was unable to get volume snapshot" )
278
283
return nil , err
279
284
}
285
+
286
+ // check the PVC size is not less than the volume snapshot size
287
+ PVCConfig := m .Config .WorkspaceClasses [config .DefaultWorkspaceClass ].PVC
288
+ if startContext .Class != nil {
289
+ PVCConfig = startContext .Class .PVC
290
+ }
291
+
292
+ if volumeSnapshot .Status != nil &&
293
+ volumeSnapshot .Status .RestoreSize != nil &&
294
+ PVCConfig .Size .Cmp (* volumeSnapshot .Status .RestoreSize ) == - 1 {
295
+ return nil , xerrors .Errorf ("cannot restore volume snapshot from size %s to pvc size %s" , volumeSnapshot .Status .RestoreSize .String (), PVCConfig .Size .String ())
296
+ }
280
297
}
281
- pvc , err = m .createPVCForWorkspacePod (startContext )
298
+
299
+ // create PVC object
300
+ pvc , err = m .createPVCForWorkspacePod (ctx , startContext )
282
301
if err != nil {
283
302
return nil , xerrors .Errorf ("cannot create pvc for workspace pod: %w" , err )
284
303
}
0 commit comments