@@ -88,6 +88,17 @@ func RunHostPreflights(c *cli.Context) error {
8888 if err != nil {
8989 return fmt .Errorf ("unable to read host preflights: %w" , err )
9090 }
91+
92+ chpfs , err := preflights .GetClusterHostPreflights (c .Context )
93+ if err != nil {
94+ return fmt .Errorf ("unable to get cluster host preflights: %w" , err )
95+ }
96+
97+ for _ , h := range chpfs {
98+ hpf .Collectors = append (hpf .Collectors , h .Spec .Collectors ... )
99+ hpf .Analyzers = append (hpf .Analyzers , h .Spec .Analyzers ... )
100+ }
101+
91102 return runHostPreflights (c , hpf )
92103}
93104
@@ -96,25 +107,61 @@ func runHostPreflights(c *cli.Context, hpf *v1beta2.HostPreflightSpec) error {
96107 return nil
97108 }
98109 pb := spinner .Start ()
99- pb .Infof ("Running host preflights on node" )
110+ if c .Bool ("skip-host-preflights" ) {
111+ pb .Infof ("Skipping host preflights" )
112+ pb .Close ()
113+ return nil
114+ }
115+ pb .Infof ("Running host preflights" )
100116 output , err := preflights .Run (c .Context , hpf )
101117 if err != nil {
102118 pb .CloseWithError ()
103119 return fmt .Errorf ("host preflights failed: %w" , err )
104120 }
121+
122+ err = output .SaveToDisk ()
123+ if err != nil {
124+ pb .CloseWithError ()
125+ return fmt .Errorf ("failed to save preflights output: %w" , err )
126+ }
127+
105128 if output .HasFail () {
129+ s := "failures"
130+ if len (output .Fail ) == 1 {
131+ s = "failure"
132+ }
133+ msg := fmt .Sprintf ("Host preflights have %d %s" , len (output .Fail ), s )
134+ if output .HasWarn () {
135+ s = "warnings"
136+ if len (output .Warn ) == 1 {
137+ s = "warning"
138+ }
139+ msg += fmt .Sprintf (" and %d %s" , len (output .Warn ), s )
140+ }
141+
142+ pb .Errorf (msg )
106143 pb .CloseWithError ()
107- output .PrintTable ()
144+ output .PrintTableWithoutInfo ()
108145 return fmt .Errorf ("preflights haven't passed on the host" )
109146 }
110- if ! output .HasWarn () || c . Bool ( "no-prompt" ) {
147+ if ! output .HasWarn () {
111148 pb .Close ()
112- output .PrintTable ()
113149 return nil
114150 }
151+ if c .Bool ("no-prompt" ) {
152+ // We have warnings but we are not in interactive mode
153+ // so we just print the warnings and continue
154+ pb .Close ()
155+ output .PrintTableWithoutInfo ()
156+ return nil
157+ }
158+ s := "warnings"
159+ if len (output .Warn ) == 1 {
160+ s = "warning"
161+ }
162+ pb .Warnf ("Host preflights have %d %s" , len (output .Warn ), s )
115163 pb .CloseWithError ()
116- output .PrintTable ()
117- logrus .Infof ("Host preflights have warnings" )
164+ output .PrintTableWithoutInfo ()
118165 if ! prompts .New ().Confirm ("Do you want to continue ?" , false ) {
119166 return fmt .Errorf ("user aborted" )
120167 }
@@ -390,7 +437,7 @@ func waitForK0s() error {
390437}
391438
392439// runOutro calls Outro() in all enabled addons by means of Applier.
393- func runOutro (c * cli.Context ) error {
440+ func runOutro (c * cli.Context , adminConsolePwd string ) error {
394441 os .Setenv ("KUBECONFIG" , defaults .PathToKubeConfig ())
395442 opts := []addons.Option {}
396443
@@ -413,12 +460,33 @@ func runOutro(c *cli.Context) error {
413460 if ab := c .String ("airgap-bundle" ); ab != "" {
414461 opts = append (opts , addons .WithAirgapBundle (ab ))
415462 }
463+ opts = append (opts , addons .WithAdminConsolePassword (adminConsolePwd ))
416464 if c .String ("http-proxy" ) != "" || c .String ("https-proxy" ) != "" || c .String ("no-proxy" ) != "" {
417465 opts = append (opts , addons .WithProxyFromArgs (c .String ("http-proxy" ), c .String ("https-proxy" ), c .String ("no-proxy" )))
418466 }
419467 return addons .NewApplier (opts ... ).Outro (c .Context )
420468}
421469
470+ func askAdminConsolePassword (c * cli.Context ) (string , error ) {
471+ defaultPass := "password"
472+ if c .Bool ("no-prompt" ) {
473+ logrus .Infof ("Admin Console password set to: %s" , defaultPass )
474+ return defaultPass , nil
475+ }
476+ maxTries := 3
477+ for i := 0 ; i < maxTries ; i ++ {
478+ promptA := prompts .New ().Password ("Enter an Admin Console password:" )
479+ promptB := prompts .New ().Password ("Confirm password:" )
480+
481+ if promptA == promptB {
482+ // TODO: Should we add extra password validation here? e.g length, complexity etc
483+ return promptA , nil
484+ }
485+ logrus .Info ("Passwords don't match, please try again." )
486+ }
487+ return "" , fmt .Errorf ("unable to set Admin Console password after %d tries" , maxTries )
488+ }
489+
422490// installCommands executes the "install" command. This will ensure that a k0s.yaml file exists
423491// and then run `k0s install` to apply the cluster. Once this is finished then a "kubeconfig"
424492// file is created. Resulting kubeconfig is stored in the configuration dir.
@@ -476,6 +544,11 @@ var installCommand = &cli.Command{
476544 Usage : "Use the system proxy settings for the install operation. These variables are currently only passed through to Velero and the Admin Console." ,
477545 Hidden : true ,
478546 },
547+ & cli.BoolFlag {
548+ Name : "skip-host-preflights" ,
549+ Usage : "Skip host preflight checks. This is not recommended unless you are sure your system is compatible." ,
550+ Value : false ,
551+ },
479552 },
480553 Action : func (c * cli.Context ) error {
481554 logrus .Debugf ("checking if %s is already installed" , binName )
@@ -510,6 +583,11 @@ var installCommand = &cli.Command{
510583 metrics .ReportApplyFinished (c , err )
511584 return err
512585 }
586+ adminConsolePwd , err := askAdminConsolePassword (c )
587+ if err != nil {
588+ metrics .ReportApplyFinished (c , err )
589+ return err
590+ }
513591 logrus .Debugf ("running host preflights" )
514592 if err := RunHostPreflights (c ); err != nil {
515593 err := fmt .Errorf ("unable to finish preflight checks: %w" , err )
@@ -549,7 +627,7 @@ var installCommand = &cli.Command{
549627 return err
550628 }
551629 logrus .Debugf ("running outro" )
552- if err := runOutro (c ); err != nil {
630+ if err := runOutro (c , adminConsolePwd ); err != nil {
553631 metrics .ReportApplyFinished (c , err )
554632 return err
555633 }
0 commit comments