From 2c2132da875914871b5d1aff94ef2808c7ef28db Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 21 Sep 2023 18:01:47 +0100 Subject: [PATCH] Changes as per PR comments --- cmd/kots/cli/install.go | 25 +++---------------------- cmd/kots/cli/set-config.go | 3 ++- pkg/preflight/preflight.go | 5 ++--- pkg/print/config.go | 25 +++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/cmd/kots/cli/install.go b/cmd/kots/cli/install.go index b1a855d61f..4582dc4d25 100644 --- a/cmd/kots/cli/install.go +++ b/cmd/kots/cli/install.go @@ -32,6 +32,7 @@ import ( "github.com/replicatedhq/kots/pkg/kurl" "github.com/replicatedhq/kots/pkg/logger" "github.com/replicatedhq/kots/pkg/metrics" + "github.com/replicatedhq/kots/pkg/print" "github.com/replicatedhq/kots/pkg/pull" "github.com/replicatedhq/kots/pkg/replicatedapp" "github.com/replicatedhq/kots/pkg/store/kotsstore" @@ -448,18 +449,12 @@ func InstallCmd() *cobra.Command { switch status { case storetypes.VersionPendingPreflight: log.ActionWithSpinner("Waiting for preflight checks to complete") - log.FinishSpinner() if err := ValidatePreflightStatus(deployOptions, authSlug, apiEndpoint); err != nil { + log.FinishSpinner() log.Errorf("Preflight checks contain warnings or errors. The application was not deployed") perr := preflightError{} if errors.As(err, &perr) { - cmd.SilenceErrors = true - var s strings.Builder - s.WriteString("\nPreflight check results (state - title - message)") - for _, result := range perr.Results { - s.WriteString(fmt.Sprintf("\n%s - %q - %q", preflightState(result), result.Title, result.Message)) - } - log.Info(s.String()) + print.PreflightErrors(log, perr.Results) os.Exit(1) } return err @@ -1070,17 +1065,3 @@ func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool, return true, nil } - -func preflightState(r *preflight.UploadPreflightResult) string { - if r.IsFail { - return "FAIL" - } - if r.IsWarn { - return "WARN" - } - if r.IsPass { - return "PASS" - } - // We should never get here - return "UNKNOWN" -} diff --git a/cmd/kots/cli/set-config.go b/cmd/kots/cli/set-config.go index c07b7c738c..800d7931bd 100644 --- a/cmd/kots/cli/set-config.go +++ b/cmd/kots/cli/set-config.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "io/ioutil" "net/http" "net/url" @@ -127,7 +128,7 @@ func SetConfigCmd() *cobra.Command { } defer resp.Body.Close() - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { log.FinishSpinnerWithError() return errors.Wrap(err, "failed to read server response") diff --git a/pkg/preflight/preflight.go b/pkg/preflight/preflight.go index ef0b8a83e5..f94440dc59 100644 --- a/pkg/preflight/preflight.go +++ b/pkg/preflight/preflight.go @@ -170,8 +170,7 @@ func Run(appID string, appSlug string, sequence int64, isAirgap bool, archiveDir // Log the preflight results if there are any warnings or errors // The app may not get installed so we need to see this info for debugging if GetPreflightState(uploadPreflightResults) != "pass" { - // TODO: Are there conditions when the application gets installed? - logger.Warnf("Preflight checks completed with warnings or errors. The application may not get installed") + logger.Warnf("Preflight checks completed with warnings or errors. The application will not get deployed") for _, result := range uploadPreflightResults.Results { if result == nil { continue @@ -208,7 +207,7 @@ func Run(appID string, appSlug string, sequence int64, isAirgap bool, archiveDir // preflight reporting if isDeployed { if err := reporting.WaitAndReportPreflightChecks(appID, sequence, false, false); err != nil { - logger.Errorf("failed to send preflights data to replicated app: %v", err) + logger.Debugf("failed to send preflights data to replicated app: %v", err) return } } diff --git a/pkg/print/config.go b/pkg/print/config.go index adadbbe4cf..e499ff2ef8 100644 --- a/pkg/print/config.go +++ b/pkg/print/config.go @@ -6,6 +6,7 @@ import ( configtypes "github.com/replicatedhq/kots/pkg/kotsadmconfig/types" "github.com/replicatedhq/kots/pkg/logger" + "github.com/replicatedhq/troubleshoot/pkg/preflight" ) func ConfigValidationErrors(log *logger.CLILogger, groupValidationErrors []configtypes.ConfigGroupValidationError) { @@ -26,3 +27,27 @@ func ConfigValidationErrors(log *logger.CLILogger, groupValidationErrors []confi log.FinishSpinnerWithError() log.Errorf(sb.String()) } + +func PreflightErrors(log *logger.CLILogger, results []*preflight.UploadPreflightResult) { + var s strings.Builder + s.WriteString("\nPreflight check results (state - title - message)") + for _, result := range results { + s.WriteString(fmt.Sprintf("\n%s - %q - %q", preflightState(result), result.Title, result.Message)) + } + log.Info(s.String()) + // log.Errorf(sb.String()) +} + +func preflightState(r *preflight.UploadPreflightResult) string { + if r.IsFail { + return "FAIL" + } + if r.IsWarn { + return "WARN" + } + if r.IsPass { + return "PASS" + } + // We should never get here + return "UNKNOWN" +}