Skip to content

Commit

Permalink
Changes as per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Sep 21, 2023
1 parent 4450d4a commit 2c2132d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
25 changes: 3 additions & 22 deletions cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion cmd/kots/cli/set-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions pkg/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/print/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"
}

0 comments on commit 2c2132d

Please sign in to comment.