diff --git a/internal/agent/install.go b/internal/agent/install.go index a32b6b6..580ab20 100644 --- a/internal/agent/install.go +++ b/internal/agent/install.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/sirupsen/logrus" "net/url" "os" "strings" @@ -74,7 +75,7 @@ func mergeOption(cloudConfig string, r map[string]string) { } } -func ManualInstall(c string, options map[string]string, strictValidations bool) error { +func ManualInstall(c string, options map[string]string, strictValidations, debug bool) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -98,13 +99,17 @@ func ManualInstall(c string, options map[string]string, strictValidations bool) mergeOption(configStr, options) if options["device"] == "" { - options["device"] = cc.Install.Device + if cc.Install.Device == "" { + options["device"] = detectDevice() + } else { + options["device"] = cc.Install.Device + } } - return RunInstall(options) + return RunInstall(debug, options) } -func Install(dir ...string) error { +func Install(debug bool, dir ...string) error { utils.OnSignal(func() { svc, err := machine.Getty(1) if err == nil { @@ -140,7 +145,7 @@ func Install(dir ...string) error { r["device"] = cc.Install.Device mergeOption(configStr, r) - err = RunInstall(r) + err = RunInstall(debug, r) if err != nil { return err } @@ -234,7 +239,7 @@ func Install(dir ...string) error { pterm.Info.Println("Starting installation") - if err := RunInstall(r); err != nil { + if err := RunInstall(debug, r); err != nil { return err } @@ -251,12 +256,15 @@ func Install(dir ...string) error { return nil } -func RunInstall(options map[string]string) error { +func RunInstall(debug bool, options map[string]string) error { // Load the installation Config from the system installConfig, err := elementalConfig.ReadConfigRun("/etc/elemental") if err != nil { return err } + if debug { + installConfig.Logger.SetLevel(logrus.DebugLevel) + } // Run pre-install stage _ = elementalUtils.RunStage(&installConfig.Config, "kairos-install.pre", installConfig.Strict, installConfig.CloudInitPaths...) diff --git a/internal/agent/interactive_install.go b/internal/agent/interactive_install.go index 5548e9f..9ad7b82 100644 --- a/internal/agent/interactive_install.go +++ b/internal/agent/interactive_install.go @@ -127,7 +127,7 @@ func detectDevice() string { return preferedDevice } -func InteractiveInstall(spawnShell bool) error { +func InteractiveInstall(debug, spawnShell bool) error { bus.Manager.Initialize() cmd.PrintBranding(DefaultBanner) @@ -220,7 +220,7 @@ func InteractiveInstall(spawnShell bool) error { } if !isYes(allGood) { - return InteractiveInstall(spawnShell) + return InteractiveInstall(debug, spawnShell) } c := &config.Config{ @@ -261,7 +261,7 @@ func InteractiveInstall(spawnShell bool) error { pterm.Info.Println("Starting installation") pterm.Info.Println(finalCloudConfig) - err = RunInstall(map[string]string{ + err = RunInstall(debug, map[string]string{ "device": device, "cc": finalCloudConfig, }) diff --git a/internal/agent/reset.go b/internal/agent/reset.go index 8854aa7..973ac02 100644 --- a/internal/agent/reset.go +++ b/internal/agent/reset.go @@ -3,6 +3,7 @@ package agent import ( "encoding/json" "fmt" + "github.com/sirupsen/logrus" "os" "sync" "time" @@ -22,7 +23,7 @@ import ( "github.com/pterm/pterm" ) -func Reset(dir ...string) error { +func Reset(debug bool, dir ...string) error { // TODO: Enable args? No args for now so no possibility of reset persistent or overriding the source for the reset // Nor the auto-reboot via cmd? // This comment pertains calling reset via cmdline when wanting to override configs @@ -85,6 +86,9 @@ func Reset(dir ...string) error { if err != nil { return err } + if debug { + resetConfig.Logger.SetLevel(logrus.DebugLevel) + } resetSpec, err := elementalConfig.ReadResetSpec(resetConfig) if err != nil { return err diff --git a/main.go b/main.go index 2dfe693..4897ae6 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/kairos-io/kairos/v2/pkg/elementalConfig" v1 "github.com/kairos-io/kairos/v2/pkg/types/v1" "github.com/kairos-io/kairos/v2/pkg/utils" + "github.com/sirupsen/logrus" "path/filepath" "runtime" @@ -59,10 +60,6 @@ var cmds = []*cli.Command{ Name: "force", Usage: "Force an upgrade", }, - &cli.BoolFlag{ - Name: "debug", - Usage: "Show debug output", - }, &cli.StringFlag{ Name: "image", Usage: "Specify an full image reference, e.g.: quay.io/some/image:tag", @@ -360,7 +357,7 @@ This command is meant to be used from the boot GRUB menu, but can be also starte }, Usage: "Starts interactive installation", Action: func(c *cli.Context) error { - return agent.InteractiveInstall(c.Bool("shell")) + return agent.InteractiveInstall(c.Bool("debug"), c.Bool("shell")) }, }, { @@ -396,7 +393,7 @@ This command is meant to be used from the boot GRUB menu, but can be also starte options["reboot"] = "true" } - return agent.ManualInstall(config, options, c.Bool("strict-validation")) + return agent.ManualInstall(config, options, c.Bool("strict-validation"), c.Bool("debug")) }, }, { @@ -412,7 +409,7 @@ See also https://kairos.io/docs/installation/qrcode/ for documentation. This command is meant to be used from the boot GRUB menu, but can be started manually`, Aliases: []string{"i"}, Action: func(c *cli.Context) error { - return agent.Install(configScanDir...) + return agent.Install(c.Bool("debug"), configScanDir...) }, }, { @@ -435,7 +432,7 @@ This command is meant to be used from the boot GRUB menu, but can likely be used { Name: "reset", Action: func(c *cli.Context) error { - return agent.Reset(configScanDir...) + return agent.Reset(c.Bool("debug"), configScanDir...) }, Usage: "Starts kairos reset mode", Description: ` @@ -519,6 +516,9 @@ The validate command expects a configuration file as its only argument. Local fi if len(c.StringSlice("cloud-init-paths")) > 0 { cfg.CloudInitPaths = append(cfg.CloudInitPaths, c.StringSlice("cloud-init-paths")...) } + if c.Bool("debug") { + cfg.Logger.SetLevel(logrus.DebugLevel) + } if err != nil { cfg.Logger.Errorf("Error reading config: %s\n", err) @@ -566,6 +566,9 @@ The validate command expects a configuration file as its only argument. Local fi if err != nil { return err } + if c.Bool("debug") { + cfg.Logger.SetLevel(logrus.DebugLevel) + } cfg.Logger.Infof("Starting download and extraction for image %s to %s\n", image, destination) e := v1.OCIImageExtractor{} @@ -588,6 +591,11 @@ func main() { Usage: "Fail instead of warn on validation errors.", EnvVars: []string{"STRICT_VALIDATIONS"}, }, + &cli.BoolFlag{ + Name: "debug", + Usage: "enable debug output", + EnvVars: []string{"KAIROS_AGENT_DEBUG"}, + }, }, Name: "kairos-agent", Version: common.VERSION,