@@ -250,8 +250,11 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
250
250
251
251
flags .isAirgap = flags .airgapBundle != ""
252
252
253
- if err := ensureAdminConsolePassword (flags ); err != nil {
254
- return err
253
+ // restore command doesn't have a password flag
254
+ if cmd .Flags ().Lookup ("admin-console-password" ) != nil {
255
+ if err := ensureAdminConsolePassword (flags ); err != nil {
256
+ return err
257
+ }
255
258
}
256
259
257
260
if flags .guidedUI {
@@ -449,11 +452,88 @@ func waitForInstallAPI(ctx context.Context, addr string) error {
449
452
}
450
453
}
451
454
455
+ func newAPIClient (flags InstallCmdFlags ) (apiclient.Client , error ) {
456
+ apiClient := apiclient .New (fmt .Sprintf ("http://localhost:%d" , flags .managerPort ))
457
+ if err := apiClient .Login (flags .adminConsolePassword ); err != nil {
458
+ return nil , fmt .Errorf ("unable to login to api: %w" , err )
459
+ }
460
+ return apiClient , nil
461
+ }
462
+
463
+ func setupStatusUpdates (ctx context.Context , flags InstallCmdFlags , successChan <- chan struct {}) (chan spinner.GlobalMessage , error ) {
464
+ if ! flags .guidedUI {
465
+ return nil , nil
466
+ }
467
+
468
+ statusChan := make (chan spinner.GlobalMessage )
469
+ spinner .SetGlobalChannel (statusChan )
470
+
471
+ apiClient , err := newAPIClient (flags )
472
+ if err != nil {
473
+ return nil , fmt .Errorf ("unable to create api client: %w" , err )
474
+ }
475
+
476
+ // start a goroutine to handle status updates
477
+ go func (apiClient apiclient.Client ) {
478
+ for {
479
+ select {
480
+ case <- ctx .Done ():
481
+ return
482
+ case <- successChan :
483
+ status := apitypes.InstallationStatus {
484
+ State : apitypes .InstallationStateSucceeded ,
485
+ Description : "Install Complete" ,
486
+ LastUpdated : time .Now (),
487
+ }
488
+ if _ , err := apiClient .SetInstallStatus (status ); err != nil {
489
+ logrus .Errorf ("Unable to update installation status: %v" , err )
490
+ }
491
+ return
492
+ case msg := <- statusChan :
493
+ status := apitypes.InstallationStatus {
494
+ State : apitypes .InstallationStateRunning ,
495
+ Description : msg .Message ,
496
+ LastUpdated : time .Now (),
497
+ }
498
+ if msg .Err {
499
+ status .State = apitypes .InstallationStateFailed
500
+ }
501
+ if _ , err := apiClient .SetInstallStatus (status ); err != nil {
502
+ logrus .Errorf ("Unable to update installation status: %v" , err )
503
+ }
504
+ }
505
+ }
506
+ }(apiClient )
507
+
508
+ return statusChan , nil
509
+ }
510
+
511
+ func markUIInstallComplete (statusChan chan spinner.GlobalMessage ) {
512
+ // Send final success message before closing
513
+ statusChan <- spinner.GlobalMessage {
514
+ Message : "Install Complete" ,
515
+ Err : false ,
516
+ }
517
+ close (statusChan )
518
+ }
519
+
452
520
func runInstall (ctx context.Context , name string , flags InstallCmdFlags , metricsReporter preflights.MetricsReporter ) error {
453
521
if err := runInstallVerifyAndPrompt (ctx , name , & flags ); err != nil {
454
522
return err
455
523
}
456
524
525
+ apiClient , err := newAPIClient (flags )
526
+ if err != nil {
527
+ return fmt .Errorf ("unable to create api client: %w" , err )
528
+ }
529
+
530
+ // set up status update channel for guided UI mode
531
+ statusChan , err := setupStatusUpdates (flags , apiClient )
532
+ if err != nil {
533
+ return fmt .Errorf ("unable to setup status updates: %w" , err )
534
+ }
535
+ defer close (statusChan )
536
+
457
537
logrus .Debug ("initializing install" )
458
538
if err := initializeInstall (ctx , flags ); err != nil {
459
539
return fmt .Errorf ("unable to initialize install: %w" , err )
@@ -571,9 +651,7 @@ func runInstall(ctx context.Context, name string, flags InstallCmdFlags, metrics
571
651
}
572
652
573
653
if flags .guidedUI {
574
- if err := markUIInstallComplete (flags .adminConsolePassword , flags .managerPort ); err != nil {
575
- return fmt .Errorf ("unable to mark ui install complete: %w" , err )
576
- }
654
+ markUIInstallComplete (statusChan )
577
655
} else {
578
656
if err := printSuccessMessage (flags .license , flags .networkInterface ); err != nil {
579
657
return err
@@ -583,22 +661,6 @@ func runInstall(ctx context.Context, name string, flags InstallCmdFlags, metrics
583
661
return nil
584
662
}
585
663
586
- func markUIInstallComplete (password string , managerPort int ) error {
587
- apiClient := apiclient .New (fmt .Sprintf ("http://localhost:%d" , managerPort ))
588
- if err := apiClient .Login (password ); err != nil {
589
- return fmt .Errorf ("unable to login: %w" , err )
590
- }
591
- _ , err := apiClient .SetInstallStatus (apitypes.InstallationStatus {
592
- State : apitypes .InstallationStateSucceeded ,
593
- Description : "Install Complete" ,
594
- LastUpdated : time .Now (),
595
- })
596
- if err != nil {
597
- return fmt .Errorf ("unable to set install status: %w" , err )
598
- }
599
- return nil
600
- }
601
-
602
664
func runInstallVerifyAndPrompt (ctx context.Context , name string , flags * InstallCmdFlags ) error {
603
665
logrus .Debugf ("checking if k0s is already installed" )
604
666
err := verifyNoInstallation (name , "reinstall" )
0 commit comments