Skip to content

Commit

Permalink
feat: always run host preflights (#1495)
Browse files Browse the repository at this point in the history
* add ignore host preflights flag

* use ignore-host-preflights

* fix output

* add skip-host-preflights deprecation warning

* fix logic error
  • Loading branch information
laverya authored Nov 25, 2024
1 parent 97e66e4 commit b9acbe9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 20 deletions.
8 changes: 7 additions & 1 deletion cmd/installer/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
overrides string
privateCAs []string
skipHostPreflights bool
ignoreHostPreflights bool
configValues string

proxy *ecv1beta1.ProxySpec
Expand All @@ -65,6 +66,9 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
if os.Getuid() != 0 {
return fmt.Errorf("install command must be run as root")
}
if skipHostPreflights {
logrus.Warnf("Warning: --skip-host-preflights is deprecated and will be removed in a later version. Use --ignore-host-preflights instead.")
}

var err error
proxy, err = getProxySpecFromFlags(cmd)
Expand Down Expand Up @@ -271,7 +275,9 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
cmd.Flags().StringVar(&overrides, "overrides", "", "File with an EmbeddedClusterConfig object to override the default configuration")
cmd.Flags().MarkHidden("overrides")
cmd.Flags().StringSliceVar(&privateCAs, "private-ca", []string{}, "Path to a trusted private CA certificate file")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended.")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
cmd.Flags().MarkHidden("skip-host-preflights")
cmd.Flags().BoolVar(&ignoreHostPreflights, "ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")
cmd.Flags().StringVar(&configValues, "config-values", "", "path to a manifest containing config values (must be apiVersion: kots.io/v1beta1, kind: ConfigValues)")

addProxyFlags(cmd)
Expand Down
29 changes: 28 additions & 1 deletion cmd/installer/cli/install_runpreflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
privateCAs []string
configValues string
skipHostPreflights bool
ignoreHostPreflights bool

proxy *ecv1beta1.ProxySpec
)
Expand Down Expand Up @@ -155,7 +156,9 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
cmd.Flags().StringSliceVar(&privateCAs, "private-ca", []string{}, "Path to a trusted private CA certificate file")
cmd.Flags().StringVar(&configValues, "config-values", "", "path to a manifest containing config values (must be apiVersion: kots.io/v1beta1, kind: ConfigValues)")

cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended.")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
cmd.Flags().MarkHidden("skip-host-preflights")
cmd.Flags().BoolVar(&ignoreHostPreflights, "ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")

addProxyFlags(cmd)
addCIDRFlags(cmd)
Expand Down Expand Up @@ -436,6 +439,30 @@ func runHostPreflights(cmd *cobra.Command, provider *defaults.Provider, hpf *v1b

pb.CloseWithError()
output.PrintTableWithoutInfo()
ignoreHostPreflightsFlag, err := cmd.Flags().GetBool("ignore-host-preflights")
if err != nil {
return fmt.Errorf("unable to get ignore-host-preflights flag: %w", err)
}
if ignoreHostPreflightsFlag {
noPromptFlag, err := cmd.Flags().GetBool("no-prompt")
if err != nil {
return fmt.Errorf("unable to get no-prompt flag: %w", err)
}
if noPromptFlag {
logrus.Infof("Host preflights failed and were ignored, but the installation will continue.")
return nil
}
if prompts.New().Confirm("Are you sure you want to ignore these failures and continue installing?", false) {
return nil // user continued after host preflights failed
}
}

if len(output.Fail)+len(output.Warn) > 1 {
logrus.Info("Please address these issues and try again.")
} else {
logrus.Info("Please address this issue and try again.")
}

return ErrPreflightsHaveFail
}

Expand Down
8 changes: 7 additions & 1 deletion cmd/installer/cli/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
networkInterface string
noPrompt bool
skipHostPreflights bool
ignoreHostPreflights bool
)

cmd := &cobra.Command{
Expand All @@ -47,6 +48,9 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
if os.Getuid() != 0 {
return fmt.Errorf("join command must be run as root")
}
if skipHostPreflights {
logrus.Warnf("Warning: --skip-host-preflights is deprecated and will be removed in a later version. Use --ignore-host-preflights instead.")
}

return nil
},
Expand Down Expand Up @@ -287,7 +291,9 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {

cmd.Flags().StringVar(&networkInterface, "network-interface", "", "The network interface to use for the cluster")
cmd.Flags().BoolVar(&noPrompt, "no-prompt", false, "Disable interactive prompts.")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended.")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
cmd.Flags().MarkHidden("skip-host-preflights")
cmd.Flags().BoolVar(&ignoreHostPreflights, "ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")

cmd.AddCommand(JoinRunPreflightsCmd(ctx, name))

Expand Down
8 changes: 7 additions & 1 deletion cmd/installer/cli/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func RestoreCmd(ctx context.Context, name string) *cobra.Command {
networkInterface string
noPrompt bool
skipHostPreflights bool
ignoreHostPreflights bool
skipStoreValidation bool

proxy *ecv1beta1.ProxySpec
Expand All @@ -100,6 +101,9 @@ func RestoreCmd(ctx context.Context, name string) *cobra.Command {
if os.Getuid() != 0 {
return fmt.Errorf("restore command must be run as root")
}
if skipHostPreflights {
logrus.Warnf("Warning: --skip-host-preflights is deprecated and will be removed in a later version. Use --ignore-host-preflights instead.")
}

var err error
proxy, err = getProxySpecFromFlags(cmd)
Expand Down Expand Up @@ -482,7 +486,9 @@ func RestoreCmd(ctx context.Context, name string) *cobra.Command {
cmd.Flags().IntVar(&localArtifactMirrorPort, "local-artifact-mirror-port", ecv1beta1.DefaultLocalArtifactMirrorPort, "Local artifact mirror port")
cmd.Flags().StringVar(&networkInterface, "network-interface", "", "The network interface to use for the cluster")
cmd.Flags().BoolVar(&noPrompt, "no-prompt", false, "Disable interactive prompts. The Admin Console password will be set to password.")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended.")
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
cmd.Flags().MarkHidden("skip-host-preflights")
cmd.Flags().BoolVar(&ignoreHostPreflights, "ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")
cmd.Flags().BoolVar(&skipStoreValidation, "skip-store-validation", false, "Skip validation of the backup storage location")
cmd.Flags().String("overrides", "", "File with an EmbeddedClusterConfig object to override the default configuration")

Expand Down
4 changes: 2 additions & 2 deletions e2e/scripts/default-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ main() {
echo "Running install with additional args: $additional_args"
fi

if embedded-cluster install --no-prompt --skip-host-preflights --license /assets/license.yaml $additional_args 2>&1 | tee /tmp/log ; then
if embedded-cluster install --no-prompt --ignore-host-preflights --license /assets/license.yaml $additional_args 2>&1 | tee /tmp/log ; then
echo "Expected installation to fail with a license provided"
exit 1
fi

if ! embedded-cluster install --no-prompt --skip-host-preflights $additional_args 2>&1 | tee /tmp/log ; then
if ! embedded-cluster install --no-prompt --ignore-host-preflights $additional_args 2>&1 | tee /tmp/log ; then
cat /etc/os-release
echo "Failed to install embedded-cluster"
exit 1
Expand Down
14 changes: 7 additions & 7 deletions e2e/scripts/resume-restore.exp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ proc send_interrupt {} {
expect eof
}

spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"Enter information to configure access to your backup storage location." {}
Expand Down Expand Up @@ -134,7 +134,7 @@ expect {
}
}

spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"A previous restore operation was detected. Would you like to resume?" {
Expand Down Expand Up @@ -174,7 +174,7 @@ expect {
}

send_interrupt
spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"A previous restore operation was detected. Would you like to resume?" {
Expand Down Expand Up @@ -219,7 +219,7 @@ expect {
}

send_interrupt
spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"A previous restore operation was detected. Would you like to resume?" {
Expand Down Expand Up @@ -274,7 +274,7 @@ expect {
}

send_interrupt
spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"A previous restore operation was detected. Would you like to resume?" {
Expand Down Expand Up @@ -339,7 +339,7 @@ expect {
}

send_interrupt
spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"A previous restore operation was detected. Would you like to resume?" {
Expand Down Expand Up @@ -384,7 +384,7 @@ expect {
}

send_interrupt
spawn embedded-cluster restore --skip-host-preflights
spawn embedded-cluster restore --ignore-host-preflights

expect {
"A previous restore operation was detected. Would you like to resume?" {
Expand Down
7 changes: 0 additions & 7 deletions pkg/preflights/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ func (o Output) printTable() {
tb.AppendRow(table.Row{"•", o.wrapText(rec.Message, maxwidth-5)})
}
logrus.Infof("\n%s\n", tb.Render())

if len(o.Fail) > 1 {
logrus.Info("Please address these issues and try again.")
return
}

logrus.Info("Please address this issue and try again.")
}

func (o Output) SaveToDisk(path string) error {
Expand Down

0 comments on commit b9acbe9

Please sign in to comment.