@@ -58,7 +58,6 @@ type DeployWorkshopConfig struct {
5858 Registry string
5959 Environ []string
6060 Labels []string
61- OpenBrowser bool
6261}
6362
6463type UpdateWorkshopResourceConfig struct {
@@ -84,6 +83,10 @@ type DeleteWorkshopResourceConfig struct {
8483 Portal string
8584}
8685
86+ type OpenBrowserConfig struct {
87+ Portal string
88+ }
89+
8790func (m * WorkshopManager ) DeployWorkshopResource (o * DeployWorkshopConfig ) error {
8891 trainingPortalClient := m .Client .Resource (educatesTypes .TrainingPortalResource )
8992
@@ -344,75 +347,6 @@ func (m *WorkshopManager) DeployWorkshopResource(o *DeployWorkshopConfig) error
344347
345348 fmt .Print ("Workshop added to training portal.\n " )
346349
347- if o .OpenBrowser {
348- // Need to refetch training portal because if was just created the URL
349- // for access may not have been set yet.
350-
351- var targetUrl string
352-
353- fmt .Print ("Checking training portal is ready.\n " )
354-
355- spinner := func (iteration int ) string {
356- spinners := `|/-\`
357- return string (spinners [iteration % len (spinners )])
358- }
359-
360- for i := 1 ; i < 60 ; i ++ {
361- fmt .Printf ("\r [%s] Waiting..." , spinner (i ))
362-
363- time .Sleep (time .Second )
364-
365- trainingPortal , err = trainingPortalClient .Get (context .TODO (), o .Portal , metav1.GetOptions {})
366-
367- if err != nil {
368- return errors .Wrapf (err , "unable to fetch training portal %q in cluster" , o .Portal )
369- }
370-
371- var found bool
372-
373- targetUrl , found , _ = unstructured .NestedString (trainingPortal .Object , "status" , "educates" , "url" )
374-
375- if found {
376- break
377- }
378- }
379-
380- rootUrl := targetUrl
381-
382- password , _ , _ := unstructured .NestedString (trainingPortal .Object , "spec" , "portal" , "password" )
383-
384- if password != "" {
385- values := url.Values {}
386- values .Add ("redirect_url" , "/" )
387- values .Add ("password" , password )
388-
389- targetUrl = fmt .Sprintf ("%s/workshops/access/?%s" , targetUrl , values .Encode ())
390- }
391-
392- for i := 1 ; i < 300 ; i ++ {
393- fmt .Printf ("\r [%s] Waiting..." , spinner (i ))
394-
395- time .Sleep (time .Second )
396-
397- resp , err := http .Get (rootUrl )
398-
399- if err != nil || resp .StatusCode == 503 {
400- continue
401- }
402-
403- defer resp .Body .Close ()
404- io .ReadAll (resp .Body )
405-
406- break
407- }
408-
409- fmt .Print ("\r \r " )
410-
411- fmt .Printf ("Opening training portal %s.\n " , targetUrl )
412-
413- return utils .OpenBrowser (targetUrl )
414- }
415-
416350 return nil
417351}
418352
@@ -538,6 +472,82 @@ func (m *WorkshopManager) DeleteWorkshopResource(o *DeleteWorkshopResourceConfig
538472 return nil
539473}
540474
475+ func (m * WorkshopManager ) OpenBrowser (o * OpenBrowserConfig ) error {
476+ trainingPortalClient := m .Client .Resource (educatesTypes .TrainingPortalResource )
477+
478+ // Need to refetch training portal because if was just created the URL
479+ // for access may not have been set yet.
480+
481+ var targetUrl string
482+
483+ fmt .Print ("Checking training portal is ready.\n " )
484+
485+ spinner := func (iteration int ) string {
486+ spinners := `|/-\`
487+ return string (spinners [iteration % len (spinners )])
488+ }
489+
490+ var trainingPortal * unstructured.Unstructured
491+ var found bool
492+ var err error
493+
494+ for i := 1 ; i < 60 ; i ++ {
495+ fmt .Printf ("\r [%s] Waiting..." , spinner (i ))
496+
497+ time .Sleep (time .Second )
498+
499+ trainingPortal , err = trainingPortalClient .Get (context .TODO (), o .Portal , metav1.GetOptions {})
500+
501+ if err != nil {
502+ return errors .Wrapf (err , "unable to fetch training portal %q in cluster" , o .Portal )
503+ }
504+
505+ targetUrl , found , _ = unstructured .NestedString (trainingPortal .Object , "status" , "educates" , "url" )
506+
507+ if found {
508+ break
509+ }
510+ }
511+ if ! found {
512+ return errors .New ("training portal not found" )
513+ }
514+
515+ rootUrl := targetUrl
516+
517+ password , _ , _ := unstructured .NestedString (trainingPortal .Object , "spec" , "portal" , "password" )
518+
519+ if password != "" {
520+ values := url.Values {}
521+ values .Add ("redirect_url" , "/" )
522+ values .Add ("password" , password )
523+
524+ targetUrl = fmt .Sprintf ("%s/workshops/access/?%s" , targetUrl , values .Encode ())
525+ }
526+
527+ for i := 1 ; i < 300 ; i ++ {
528+ fmt .Printf ("\r [%s] Waiting..." , spinner (i ))
529+
530+ time .Sleep (time .Second )
531+
532+ resp , err := http .Get (rootUrl )
533+
534+ if err != nil || resp .StatusCode == 503 {
535+ continue
536+ }
537+
538+ defer resp .Body .Close ()
539+ io .ReadAll (resp .Body )
540+
541+ break
542+ }
543+
544+ fmt .Print ("\r \r " )
545+
546+ fmt .Printf ("Opening training portal %s.\n " , targetUrl )
547+
548+ return utils .OpenBrowser (targetUrl )
549+ }
550+
541551func LoadWorkshopDefinition (o * WorkshopDefinitionConfig ) (* unstructured.Unstructured , error ) {
542552 // Parse the workshop location so we can determine if it is a local file
543553 // or accessible using a HTTP/HTTPS URL.
0 commit comments