@@ -12,7 +12,6 @@ import (
1212 "strings"
1313 "time"
1414
15- "github.com/AlecAivazis/survey/v2"
1615 "github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
1716 "github.com/k0sproject/rig"
1817 "github.com/k0sproject/rig/log"
@@ -26,6 +25,7 @@ import (
2625 "github.com/replicatedhq/helmvm/pkg/goods"
2726 "github.com/replicatedhq/helmvm/pkg/infra"
2827 pb "github.com/replicatedhq/helmvm/pkg/progressbar"
28+ "github.com/replicatedhq/helmvm/pkg/prompts"
2929)
3030
3131// runPostApply is meant to run things that can't be run automatically with
@@ -150,25 +150,19 @@ func copyUserProvidedConfig(c *cli.Context) error {
150150
151151// overwriteExistingConfig asks user if they want to overwrite the existing cluster
152152// configuration file.
153- func overwriteExistingConfig () (bool , error ) {
154- var useCurrent = & survey.Confirm {
155- Message : "Do you want to create a new cluster configuration ?" ,
156- Default : false ,
157- }
153+ func overwriteExistingConfig () bool {
158154 logrus .Warn ("A cluster configuration file was found. This means you already" )
159- logrus .Warn ("have created a cluster configured. You can either use the existing" )
160- logrus .Warn ("configuration or create a new one (the original configuration will" )
161- logrus .Warn ("be backed up)." )
162- var answer bool
163- if err := survey .AskOne (useCurrent , & answer ); err != nil {
164- return false , err
165- }
166- return answer , nil
155+ logrus .Warn ("have created and configured a cluster. You can either use the" )
156+ logrus .Warn ("existing configuration or create a new one (the original config" )
157+ logrus .Warn ("will be backed up)." )
158+ return prompts .New ().Confirm (
159+ "Do you want to create a new cluster configuration ?" , false ,
160+ )
167161}
168162
169163// ensureK0sctlConfig ensures that a k0sctl.yaml file exists in the configuration
170164// directory. If none exists then this directs the user to a wizard to create one.
171- func ensureK0sctlConfig (c * cli.Context , nodes []infra.Node , prompt bool ) error {
165+ func ensureK0sctlConfig (c * cli.Context , nodes []infra.Node , useprompt bool ) error {
172166 multi := c .Bool ("multi-node" ) || len (nodes ) > 0
173167 if ! multi && runtime .GOOS != "linux" {
174168 return fmt .Errorf ("single node clusters only supported on linux" )
@@ -182,12 +176,10 @@ func ensureK0sctlConfig(c *cli.Context, nodes []infra.Node, prompt bool) error {
182176 }
183177 if _ , err := os .Stat (cfgpath ); err == nil {
184178 if len (nodes ) == 0 {
185- if ! prompt {
179+ if ! useprompt {
186180 return updateConfigBundle (c .Context , bundledir )
187181 }
188- if over , err := overwriteExistingConfig (); err != nil {
189- return fmt .Errorf ("unable to process answers: %w" , err )
190- } else if ! over {
182+ if ! overwriteExistingConfig () {
191183 return updateConfigBundle (c .Context , bundledir )
192184 }
193185 }
@@ -276,26 +268,20 @@ func dumpApplyLogs() {
276268
277269// applyK0sctl runs the k0sctl apply command and waits for it to finish. If
278270// no configuration is found one is generated.
279- func applyK0sctl (c * cli.Context , prompt bool , nodes []infra.Node ) error {
271+ func applyK0sctl (c * cli.Context , useprompt bool , nodes []infra.Node ) error {
280272 logrus .Infof ("Processing cluster configuration" )
281- if err := ensureK0sctlConfig (c , nodes , prompt ); err != nil {
273+ if err := ensureK0sctlConfig (c , nodes , useprompt ); err != nil {
282274 return fmt .Errorf ("unable to create config file: %w" , err )
283275 }
284276 logrus .Infof ("Applying cluster configuration" )
285277 if err := runK0sctlApply (c .Context ); err != nil {
286278 logrus .Errorf ("Installation or upgrade failed." )
287- if ! prompt {
279+ if ! useprompt {
288280 dumpApplyLogs ()
289281 return fmt .Errorf ("unable to apply cluster: %w" , err )
290282 }
291- var useCurrent = & survey.Confirm {
292- Message : "Do you wish to visualize the logs?" ,
293- Default : true ,
294- }
295- var answer bool
296- if err := survey .AskOne (useCurrent , & answer ); err != nil {
297- return fmt .Errorf ("unable to process answers: %w" , err )
298- } else if answer {
283+ msg := "Do you wish to visualize the logs?"
284+ if prompts .New ().Confirm (msg , true ) {
299285 dumpApplyLogs ()
300286 }
301287 return fmt .Errorf ("unable to apply cluster: %w" , err )
@@ -348,7 +334,7 @@ var installCommand = &cli.Command{
348334 logrus .Warnf ("Run '%s node --help' for more information." , defaults .BinaryName ())
349335 return fmt .Errorf ("decentralized install detected" )
350336 }
351- prompt := ! c .Bool ("no-prompt" )
337+ useprompt := ! c .Bool ("no-prompt" )
352338 logrus .Infof ("Materializing binaries" )
353339 if err := goods .Materialize (); err != nil {
354340 return fmt .Errorf ("unable to materialize binaries: %w" , err )
@@ -358,11 +344,11 @@ var installCommand = &cli.Command{
358344 var nodes []infra.Node
359345 if dir := c .String ("infra" ); dir != "" {
360346 logrus .Infof ("Processing infrastructure manifests" )
361- if nodes , err = infra .Apply (c .Context , dir , prompt ); err != nil {
347+ if nodes , err = infra .Apply (c .Context , dir , useprompt ); err != nil {
362348 return fmt .Errorf ("unable to create infra: %w" , err )
363349 }
364350 }
365- if err := applyK0sctl (c , prompt , nodes ); err != nil {
351+ if err := applyK0sctl (c , useprompt , nodes ); err != nil {
366352 return fmt .Errorf ("unable update cluster: %w" , err )
367353 }
368354 }
@@ -374,7 +360,7 @@ var installCommand = &cli.Command{
374360 ccfg := defaults .PathToConfig ("k0sctl.yaml" )
375361 kcfg := defaults .PathToConfig ("kubeconfig" )
376362 os .Setenv ("KUBECONFIG" , kcfg )
377- if applier , err := addons .NewApplier (prompt , true ); err != nil {
363+ if applier , err := addons .NewApplier (useprompt , true ); err != nil {
378364 return fmt .Errorf ("unable to create applier: %w" , err )
379365 } else if err := applier .Apply (c .Context ); err != nil {
380366 return fmt .Errorf ("unable to apply addons: %w" , err )
0 commit comments