Skip to content

Commit

Permalink
logging: do not show help output on runtime errors and print timestam…
Browse files Browse the repository at this point in the history
…ps (SPLAT-618)
  • Loading branch information
bostrt committed Jun 30, 2022
1 parent 7947b71 commit 2699f5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
20 changes: 15 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vmware-tanzu/sonobuoy/cmd/sonobuoy/app"
Expand All @@ -18,28 +19,37 @@ import (
"github.com/openshift/provider-certification-tool/pkg/version"
)

var ()

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "openshift-provider-cert",
Short: "OpenShift Provider Certification Tool",
Long: `OpenShift Provider Certification Tool is used to evaluate an OpenShift installation on a provider or hardware is in conformance`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
var err error

// Validate logging level
loglevel := viper.GetString("loglevel")
logrusLevel, err := log.ParseLevel(loglevel)
if err != nil {
return err
log.Fatal(err)
}
log.SetLevel(logrusLevel)

// Additional log options
customFormatter := new(log.TextFormatter)
customFormatter.FullTimestamp = true
log.SetFormatter(customFormatter)

// Save kubeconfig
client.Kubeconfig = viper.GetString("kubeconfig")
if client.Kubeconfig == "" {
log.Fatal("--kubeconfig or KUBECONFIG environment variable must be set")
}

return nil
// Check kubeconfig exists
if _, err := os.Stat(client.Kubeconfig); err != nil {
log.Fatal(err)
}
},
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@ func NewCmdRun() *cobra.Command {
Use: "run",
Short: "Run the suite of tests for provider certification",
Long: `Launches the provider certification environment inside of an already running OpenShift cluster`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRun: func(cmd *cobra.Command, args []string) {
// Client setup
kclient, sclient, err = client.CreateClients()
if err != nil {
return err
log.Fatal(err)
}

// Pre-checks and setup
err = o.PreRunCheck(kclient)
if err != nil {
return err
log.Fatal(err)
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
log.Info("Running OpenShift Provider Certification Tool...")
Expand Down

0 comments on commit 2699f5d

Please sign in to comment.