@@ -109,6 +109,7 @@ type newnotebookrequest struct {
109
109
ServerType string `json:"serverType"`
110
110
AffinityConfig string `json:"affinityConfig"`
111
111
TolerationGroup string `json:"tolerationGroup"`
112
+ DefaultNotebook bool `json:"defaultNotebook"`
112
113
}
113
114
114
115
type gpuresponse struct {
@@ -447,6 +448,131 @@ func (s *server) handleVolume(ctx context.Context, req volrequest, notebook *kub
447
448
return nil
448
449
}
449
450
451
+ // Sets default values to notebook request if missing
452
+ func (s * server ) createDefaultNotebook (namespace string ) (newnotebookrequest , error ) {
453
+ var notebook newnotebookrequest
454
+ notebookname := namespace + "-notebook"
455
+ cpuvalue , err := resource .ParseQuantity (s .Config .SpawnerFormDefaults .CPU .Value )
456
+ if err != nil {
457
+ return notebook , err
458
+ }
459
+
460
+ cpulimitvalue , err := resource .ParseQuantity (s .Config .SpawnerFormDefaults .CPU .LimitValue )
461
+ if err != nil {
462
+ return notebook , err
463
+ }
464
+
465
+ memoryvalue , err := resource .ParseQuantity (s .Config .SpawnerFormDefaults .Memory .Value + "Gi" )
466
+ if err != nil {
467
+ return notebook , err
468
+ }
469
+
470
+ memorylimitvalue , err := resource .ParseQuantity (s .Config .SpawnerFormDefaults .Memory .LimitValue + "Gi" )
471
+ if err != nil {
472
+ return notebook , err
473
+ }
474
+
475
+ size , err := resource .ParseQuantity (s .Config .SpawnerFormDefaults .WorkspaceVolume .Value .NewPvc .Spec .Resources .Requests .Storage )
476
+ if err != nil {
477
+ return notebook , err
478
+ }
479
+ workspacevolumename := notebookname + "-workspace"
480
+ workspaceVol := volrequest {
481
+ Mount : s .Config .SpawnerFormDefaults .WorkspaceVolume .Value .Mount ,
482
+ NewPvc : NewPvc {
483
+ NewPvcMetadata : NewPvcMetadata {
484
+ Name : & workspacevolumename ,
485
+ },
486
+ NewPvcSpec : NewPvcSpec {
487
+ Resources : Resources {
488
+ Requests : Requests {
489
+ Storage : size ,
490
+ },
491
+ },
492
+ AccessModes : s .Config .SpawnerFormDefaults .WorkspaceVolume .Value .NewPvc .Spec .AccessModes ,
493
+ StorageClassName : "" ,
494
+ },
495
+ },
496
+ }
497
+
498
+ var datavols []volrequest
499
+ for _ , volreq := range s .Config .SpawnerFormDefaults .DataVolumes .Value {
500
+ size , err := resource .ParseQuantity (s .Config .SpawnerFormDefaults .WorkspaceVolume .Value .NewPvc .Spec .Resources .Requests .Storage )
501
+ if err != nil {
502
+ return notebook , err
503
+ }
504
+ vol := volrequest {
505
+ Mount : volreq .Value .Mount ,
506
+ NewPvc : NewPvc {
507
+ NewPvcMetadata : NewPvcMetadata {
508
+ Name : & volreq .Value .NewPvc .Metadata .Name ,
509
+ },
510
+ NewPvcSpec : NewPvcSpec {
511
+ Resources : Resources {
512
+ Requests : Requests {
513
+ Storage : size ,
514
+ },
515
+ },
516
+ AccessModes : workspaceVol .NewPvc .NewPvcSpec .AccessModes ,
517
+ StorageClassName : "" ,
518
+ },
519
+ },
520
+ }
521
+ datavols = append (datavols , vol )
522
+ }
523
+
524
+ notebook = newnotebookrequest {
525
+ Name : notebookname ,
526
+ Namespace : namespace ,
527
+ Image : s .Config .SpawnerFormDefaults .Image .Value ,
528
+ CustomImage : "" ,
529
+ CustomImageCheck : false ,
530
+ CPU : cpuvalue ,
531
+ CPULimit : cpulimitvalue ,
532
+ Memory : memoryvalue ,
533
+ MemoryLimit : memorylimitvalue ,
534
+ GPUs : gpurequest {
535
+ Quantity : s .Config .SpawnerFormDefaults .GPUs .Value .Num ,
536
+ Vendor : s .Config .SpawnerFormDefaults .GPUs .Value .Vendor ,
537
+ },
538
+ NoWorkspace : false ,
539
+ Workspace : workspaceVol ,
540
+ DataVolumes : datavols ,
541
+ EnableSharedMemory : s .Config .SpawnerFormDefaults .Shm .Value ,
542
+ Configurations : s .Config .SpawnerFormDefaults .Configurations .Value ,
543
+ Protb : false ,
544
+ Language : "en" ,
545
+ ImagePullPolicy : s .Config .SpawnerFormDefaults .ImagePullPolicy .Value ,
546
+ ServerType : "jupyter" ,
547
+ AffinityConfig : s .Config .SpawnerFormDefaults .AffinityConfig .Value ,
548
+ TolerationGroup : s .Config .SpawnerFormDefaults .TolerationGroup .Value ,
549
+ DefaultNotebook : true ,
550
+ }
551
+
552
+ return notebook , nil
553
+ }
554
+
555
+ func (s * server ) NewDefaultNotebook (w http.ResponseWriter , r * http.Request ) {
556
+ vars := mux .Vars (r )
557
+ namespace := vars ["namespace" ]
558
+
559
+ req , err := s .createDefaultNotebook (namespace )
560
+ if err != nil {
561
+ s .error (w , r , err )
562
+ return
563
+ }
564
+
565
+ newnotebook , err := json .Marshal (req )
566
+ if err != nil {
567
+ s .error (w , r , err )
568
+ return
569
+ }
570
+
571
+ r .Body = io .NopCloser (bytes .NewBuffer (newnotebook ))
572
+
573
+ s .NewNotebook (w , r )
574
+ }
575
+
450
576
func (s * server ) NewNotebook (w http.ResponseWriter , r * http.Request ) {
451
577
vars := mux .Vars (r )
452
578
namespace := vars ["namespace" ]
@@ -469,8 +595,7 @@ func (s *server) NewNotebook(w http.ResponseWriter, r *http.Request) {
469
595
image := req .Image
470
596
if req .CustomImageCheck {
471
597
image = req .CustomImage
472
- }
473
- if s .Config .SpawnerFormDefaults .Image .ReadOnly {
598
+ } else if s .Config .SpawnerFormDefaults .Image .ReadOnly {
474
599
image = s .Config .SpawnerFormDefaults .Image .Value
475
600
}
476
601
image = strings .TrimSpace (image )
@@ -540,6 +665,11 @@ func (s *server) NewNotebook(w http.ResponseWriter, r *http.Request) {
540
665
notebook .ObjectMeta .Labels ["notebook.statcan.gc.ca/protected-b" ] = "true"
541
666
}
542
667
668
+ // AAW Customization Creating default notebook
669
+ if req .DefaultNotebook {
670
+ notebook .ObjectMeta .Labels ["notebook.statcan.gc.ca/default-notebook" ] = "true"
671
+ }
672
+
543
673
// Add configuration items
544
674
if s .Config .SpawnerFormDefaults .Configurations .ReadOnly {
545
675
for _ , config := range s .Config .SpawnerFormDefaults .Configurations .Value {
0 commit comments