diff --git a/README.md b/README.md index fb135e6e1..139e3416b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ technologies: ### Hardware requirements The runtime has a built-in command to determine if your host system is capable -of running a Kata Container: +of running and creating a Kata Container: ```bash $ kata-runtime kata-check @@ -68,8 +68,13 @@ $ kata-runtime kata-check > **Note:** > -> If you run the previous command as the `root` user, further checks will be -> performed (e.g. it will check if another incompatible hypervisor is running). +> - By default, only a brief success / failure message is printed. +> If more details are needed, the `--verbose` flag can be used to display the +> list of all the checks performed. +> +> - `root` permission is needed to check if the system is capable of running +> Kata containers. In this case, additional checks are performed (e.g., if another +> incompatible hypervisor is running). ## Download and install diff --git a/cli/kata-check.go b/cli/kata-check.go index 068c74373..9ffed062d 100644 --- a/cli/kata-check.go +++ b/cli/kata-check.go @@ -304,7 +304,18 @@ func genericHostIsVMContainerCapable(details vmContainerCapableDetails) error { var kataCheckCLICommand = cli.Command{ Name: checkCmd, Usage: "tests if system can run " + project, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "verbose, v", + Usage: "display the list of checks performed", + }, + }, + Action: func(context *cli.Context) error { + verbose := context.Bool("verbose") + if verbose { + kataLog.Logger.SetLevel(logrus.InfoLevel) + } ctx, err := cliContextToContext(context) if err != nil { return err @@ -335,8 +346,7 @@ var kataCheckCLICommand = cli.Command{ if err != nil { return err } - - kataLog.Info(successMessageCapable) + fmt.Println(successMessageCapable) if os.Geteuid() == 0 { err = archHostCanCreateVMContainer(runtimeConfig.HypervisorType) @@ -344,7 +354,7 @@ var kataCheckCLICommand = cli.Command{ return err } - kataLog.Info(successMessageCreate) + fmt.Println(successMessageCreate) } return nil diff --git a/cli/main.go b/cli/main.go index 72c9165e7..40bef7052 100644 --- a/cli/main.go +++ b/cli/main.go @@ -260,11 +260,17 @@ func beforeSubcommands(c *cli.Context) error { return nil } - ignoreLogging := false + ignoreConfigLogs := false var traceRootSpan string - subCmdIsCheckCmd := (c.NArg() == 1 && (c.Args()[0] == checkCmd)) - if !subCmdIsCheckCmd { + subCmdIsCheckCmd := (c.NArg() >= 1 && (c.Args()[0] == checkCmd)) + if subCmdIsCheckCmd { + // checkCmd will use the default logrus logger to stderr + // raise the logger default level to warn + kataLog.Logger.SetLevel(logrus.WarnLevel) + // do not print configuration logs for checkCmd + ignoreConfigLogs = true + } else { if path := c.GlobalString("log"); path != "" { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0640) if err != nil { @@ -300,11 +306,11 @@ func beforeSubcommands(c *cli.Context) error { if c.NArg() == 1 && c.Args()[0] == envCmd { // simply report the logging setup - ignoreLogging = true + ignoreConfigLogs = true } } - configFile, runtimeConfig, err = katautils.LoadConfiguration(c.GlobalString(configFilePathOption), ignoreLogging, false) + configFile, runtimeConfig, err = katautils.LoadConfiguration(c.GlobalString(configFilePathOption), ignoreConfigLogs, false) if err != nil { fatal(err) }