@@ -201,6 +201,13 @@ const (
201
201
// - make sure the regular workspace PVC object should exist or not
202
202
// - make sure the file foobar.txt exists
203
203
func TestOpenWorkspaceFromPrebuild (t * testing.T ) {
204
+ var (
205
+ snapshotcontrollerDeployment string = "snapshot-controller"
206
+ snapshotcontrollerNamespace string = "kube-system"
207
+ wsmanagerDeployment string = "ws-manager"
208
+ wsmanagerNamespace string = "default"
209
+ )
210
+
204
211
f := features .New ("prebuild" ).
205
212
WithLabel ("component" , "ws-manager" ).
206
213
Assess ("it should open workspace from prebuild successfully" , func (_ context.Context , t * testing.T , cfg * envconf.Config ) context.Context {
@@ -231,6 +238,8 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
231
238
232
239
for _ , test := range tests {
233
240
t .Run (test .Name , func (t * testing.T ) {
241
+ isPVCEnable := reflect .DeepEqual (test .FF , []wsmanapi.WorkspaceFeatureFlag {wsmanapi .WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM })
242
+
234
243
api := integration .NewComponentAPI (ctx , cfg .Namespace (), kubeconfig , cfg .Client ())
235
244
t .Cleanup (func () {
236
245
api .Done (t )
@@ -268,8 +277,28 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
268
277
}
269
278
270
279
t .Logf ("prebuild snapshot: %s" , prebuildSnapshot )
271
- if vsInfo != nil {
272
- t .Logf ("vsName: %s, vsHandle: %s" , vsInfo .VolumeSnapshotName , vsInfo .VolumeSnapshotHandle )
280
+ checkSnapshot (t , vsInfo , isPVCEnable )
281
+
282
+ // restart the ws-manager and volume snapshot after the volume snapshot is finished
283
+ if isPVCEnable {
284
+ t .Logf ("rollout restart deployment %s/%s after the volume snapshot is finished" , wsmanagerDeployment , wsmanagerNamespace )
285
+ if err := api .RestartDeployment (wsmanagerDeployment , wsmanagerNamespace , true ); err != nil {
286
+ t .Errorf ("cannot restart deployment %s/%s" , wsmanagerDeployment , wsmanagerNamespace )
287
+ }
288
+ t .Logf ("rollout restart deployment %s/%s is finished" , wsmanagerDeployment , wsmanagerNamespace )
289
+
290
+ t .Logf ("rollout restart deployment %s/%s after the volume snapshot is finished" , snapshotcontrollerDeployment , snapshotcontrollerNamespace )
291
+ if err := api .RestartDeployment (snapshotcontrollerDeployment , snapshotcontrollerNamespace , true ); err != nil {
292
+ t .Errorf ("cannot restart deployment %s/%s" , snapshotcontrollerDeployment , snapshotcontrollerNamespace )
293
+ }
294
+ t .Logf ("rollout restart deployment %s/%s is finished" , snapshotcontrollerDeployment , snapshotcontrollerNamespace )
295
+
296
+ // recreate a new API because the ws-manager restarted
297
+ api1 := integration .NewComponentAPI (ctx , cfg .Namespace (), kubeconfig , cfg .Client ())
298
+ api = api1
299
+ t .Cleanup (func () {
300
+ api1 .Done (t )
301
+ })
273
302
}
274
303
275
304
// launch the workspace from prebuild
@@ -282,7 +311,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
282
311
Prebuild : & csapi.PrebuildInitializer {
283
312
Prebuild : & csapi.SnapshotInitializer {
284
313
Snapshot : prebuildSnapshot ,
285
- FromVolumeSnapshot : reflect . DeepEqual ( test . FF , []wsmanapi. WorkspaceFeatureFlag { wsmanapi . WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM }) ,
314
+ FromVolumeSnapshot : isPVCEnable ,
286
315
},
287
316
Git : []* csapi.GitInitializer {
288
317
{
@@ -303,7 +332,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
303
332
}
304
333
305
334
// check the PVC object should exist or not
306
- checkPVCObject (t , api , test . FF , regularPrefix + ws .Req .Id )
335
+ checkPVCObject (t , api , isPVCEnable , regularPrefix + ws .Req .Id )
307
336
308
337
defer func () {
309
338
// stop workspace in defer function to prevent we forget to stop the workspace
@@ -352,12 +381,32 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
352
381
t .Fatal (err )
353
382
}
354
383
355
- if vsInfo != nil {
356
- t .Logf ("vsName: %s, vsHandle: %s" , vsInfo .VolumeSnapshotName , vsInfo .VolumeSnapshotHandle )
384
+ checkSnapshot (t , vsInfo , isPVCEnable )
385
+
386
+ // restart the ws-manager and volume snapshot after the volume snapshot is finished
387
+ if isPVCEnable {
388
+ t .Logf ("rollout restart deployment %s/%s after the volume snapshot is finished" , wsmanagerDeployment , wsmanagerNamespace )
389
+ if err := api .RestartDeployment (wsmanagerDeployment , wsmanagerNamespace , true ); err != nil {
390
+ t .Errorf ("cannot restart deployment %s/%s" , wsmanagerDeployment , wsmanagerNamespace )
391
+ }
392
+ t .Logf ("rollout restart deployment %s/%s is finished" , wsmanagerDeployment , wsmanagerNamespace )
393
+
394
+ t .Logf ("rollout restart deployment %s/%s after the volume snapshot is finished" , snapshotcontrollerDeployment , snapshotcontrollerNamespace )
395
+ if err := api .RestartDeployment (snapshotcontrollerDeployment , snapshotcontrollerNamespace , true ); err != nil {
396
+ t .Errorf ("cannot restart deployment %s/%s" , snapshotcontrollerDeployment , snapshotcontrollerNamespace )
397
+ }
398
+ t .Logf ("rollout restart deployment %s/%s is finished" , snapshotcontrollerDeployment , snapshotcontrollerNamespace )
399
+
400
+ // recreate a new API because the ws-manager restarted
401
+ sapi1 := integration .NewComponentAPI (ctx , cfg .Namespace (), kubeconfig , cfg .Client ())
402
+ sapi = sapi1
403
+ t .Cleanup (func () {
404
+ sapi .Done (t )
405
+ })
357
406
}
358
407
359
408
// reopen the workspace and make sure the file foobar.txt exists
360
- ws1 , stopWs1 , err := integration .LaunchWorkspaceDirectly (t , ctx , api , integration .WithRequestModifier (func (req * wsmanapi.StartWorkspaceRequest ) error {
409
+ ws1 , stopWs1 , err := integration .LaunchWorkspaceDirectly (t , ctx , sapi , integration .WithRequestModifier (func (req * wsmanapi.StartWorkspaceRequest ) error {
361
410
req .ServicePrefix = ws .Req .ServicePrefix
362
411
req .Metadata .MetaId = ws .Req .Metadata .MetaId
363
412
req .Metadata .Owner = ws .Req .Metadata .Owner
@@ -366,7 +415,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
366
415
Spec : & csapi.WorkspaceInitializer_Backup {
367
416
Backup : & csapi.FromBackupInitializer {
368
417
CheckoutLocation : test .CheckoutLocation ,
369
- FromVolumeSnapshot : reflect . DeepEqual ( test . FF , []wsmanapi. WorkspaceFeatureFlag { wsmanapi . WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM }) ,
418
+ FromVolumeSnapshot : isPVCEnable ,
370
419
},
371
420
},
372
421
}
@@ -379,7 +428,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
379
428
}
380
429
381
430
// check the PVC object should exist or not
382
- checkPVCObject (t , api , test . FF , regularPrefix + ws1 .Req .Id )
431
+ checkPVCObject (t , sapi , isPVCEnable , regularPrefix + ws1 .Req .Id )
383
432
384
433
defer func () {
385
434
// stop workspace in defer function to prevent we forget to stop the workspace
@@ -447,6 +496,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
447
496
ContextURL string
448
497
WorkspaceRoot string
449
498
CheckoutLocation string
499
+ FF []wsmanapi.WorkspaceFeatureFlag
450
500
ShouldFailToOpenRegularWorkspace bool
451
501
}{
452
502
{
@@ -458,6 +508,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
458
508
ContextURL : "https://github.com/gitpod-io/empty" ,
459
509
CheckoutLocation : "empty" ,
460
510
WorkspaceRoot : "/workspace/empty" ,
511
+ FF : []wsmanapi.WorkspaceFeatureFlag {wsmanapi .WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM },
461
512
},
462
513
{
463
514
Name : "prebuild-large-regular-small-workspace-class" ,
@@ -468,6 +519,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
468
519
ContextURL : "https://github.com/gitpod-io/empty" ,
469
520
CheckoutLocation : "empty" ,
470
521
WorkspaceRoot : "/workspace/empty" ,
522
+ FF : []wsmanapi.WorkspaceFeatureFlag {wsmanapi .WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM },
471
523
ShouldFailToOpenRegularWorkspace : true ,
472
524
},
473
525
}
@@ -477,6 +529,8 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
477
529
478
530
for _ , test := range tests {
479
531
t .Run (test .Name , func (t * testing.T ) {
532
+ isPVCEnable := reflect .DeepEqual (test .FF , []wsmanapi.WorkspaceFeatureFlag {wsmanapi .WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM })
533
+
480
534
api := integration .NewComponentAPI (ctx , cfg .Namespace (), kubeconfig , cfg .Client ())
481
535
t .Cleanup (func () {
482
536
api .Done (t )
@@ -490,7 +544,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
490
544
Name : "GITPOD_TASKS" ,
491
545
Value : fmt .Sprintf (`[{ "init": %q }]` , initTask ),
492
546
})
493
- req .Spec .FeatureFlags = []wsmanapi. WorkspaceFeatureFlag { wsmanapi . WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM }
547
+ req .Spec .FeatureFlags = test . FF
494
548
req .Spec .Initializer = & csapi.WorkspaceInitializer {
495
549
Spec : & csapi.WorkspaceInitializer_Git {
496
550
Git : & csapi.GitInitializer {
@@ -513,14 +567,12 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
513
567
}
514
568
515
569
t .Logf ("prebuild snapshot: %s" , prebuildSnapshot )
516
- if vsInfo != nil {
517
- t .Logf ("vsName: %s, vsHandle: %s" , vsInfo .VolumeSnapshotName , vsInfo .VolumeSnapshotHandle )
518
- }
570
+ checkSnapshot (t , vsInfo , isPVCEnable )
519
571
520
572
// launch the workspace from prebuild
521
573
ws , stopWs , err := integration .LaunchWorkspaceDirectly (t , ctx , api , integration .WithRequestModifier (func (req * wsmanapi.StartWorkspaceRequest ) error {
522
574
req .Spec .Class = test .RegularWorkspaceClass
523
- req .Spec .FeatureFlags = []wsmanapi. WorkspaceFeatureFlag { wsmanapi . WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM }
575
+ req .Spec .FeatureFlags = test . FF
524
576
req .Spec .Initializer = & csapi.WorkspaceInitializer {
525
577
Spec : & csapi.WorkspaceInitializer_Prebuild {
526
578
Prebuild : & csapi.PrebuildInitializer {
@@ -585,9 +637,31 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
585
637
testEnv .Test (t , f )
586
638
}
587
639
640
+ // checkSnapshot checks the volume snapshot information is valid or not
641
+ func checkSnapshot (t * testing.T , vsInfo * wsmanapi.VolumeSnapshotInfo , isPVCEnable bool ) {
642
+ if ! isPVCEnable {
643
+ if vsInfo == nil {
644
+ return
645
+ }
646
+ if vsInfo .VolumeSnapshotName == "" && vsInfo .VolumeSnapshotHandle == "" {
647
+ return
648
+ }
649
+ t .Fatalf ("it should not contain volume snapshot name %s and volume snapshot handle %s without PVC" , vsInfo .VolumeSnapshotName , vsInfo .VolumeSnapshotHandle )
650
+ } else {
651
+ if vsInfo == nil {
652
+ t .Fatal ("it should contain volume snapshot info with PVC" )
653
+ }
654
+ if vsInfo .VolumeSnapshotName != "" && vsInfo .VolumeSnapshotHandle != "" {
655
+ t .Logf ("vsName: %s, vsHandle: %s" , vsInfo .VolumeSnapshotName , vsInfo .VolumeSnapshotHandle )
656
+ return
657
+ }
658
+ t .Fatalf ("it should contain volume snapshot name %s and volume snapshot handle %s without PVC" , vsInfo .VolumeSnapshotName , vsInfo .VolumeSnapshotHandle )
659
+ }
660
+ }
661
+
588
662
// checkPVCObject checks the PVC object should exist or not
589
- func checkPVCObject (t * testing.T , api * integration.ComponentAPI , ff []wsmanapi. WorkspaceFeatureFlag , pvcName string ) {
590
- if reflect . DeepEqual ( ff , []wsmanapi. WorkspaceFeatureFlag { wsmanapi . WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM }) {
663
+ func checkPVCObject (t * testing.T , api * integration.ComponentAPI , isPVCEnable bool , pvcName string ) {
664
+ if isPVCEnable {
591
665
// check the PVC object exist
592
666
if ! api .IsPVCExist (pvcName ) {
593
667
t .Fatal ("prebuild PVC object should exist" )
0 commit comments