From bb894df100f47d745416b1efef9ad7ef6be1d0f1 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Thu, 2 Mar 2023 19:44:48 +0100 Subject: [PATCH] added make_defaults to wwctl genconfig defaults Signed-off-by: Christian Goll --- internal/app/wwctl/genconf/dfaults/root.go | 1 - internal/app/wwctl/root.go | 10 +++++++--- internal/pkg/warewulfconf/constructors.go | 12 +++++++++--- internal/pkg/warewulfconf/datastructure.go | 7 +------ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/internal/app/wwctl/genconf/dfaults/root.go b/internal/app/wwctl/genconf/dfaults/root.go index ad575709..9eadd58a 100644 --- a/internal/app/wwctl/genconf/dfaults/root.go +++ b/internal/app/wwctl/genconf/dfaults/root.go @@ -11,7 +11,6 @@ var ( Args: cobra.NoArgs, Aliases: []string{"dfaults"}, } - Zsh bool ) func init() { diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index 20a02657..9c746c79 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -13,6 +13,7 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/ssh" "github.com/hpcng/warewulf/internal/app/wwctl/version" "github.com/hpcng/warewulf/internal/pkg/help" + "github.com/hpcng/warewulf/internal/pkg/warewulfconf" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" ) @@ -27,9 +28,10 @@ var ( SilenceUsage: true, SilenceErrors: true, } - verboseArg bool - DebugFlag bool - LogLevel int + verboseArg bool + DebugFlag bool + LogLevel int + WarewulfConfArg string ) func init() { @@ -37,6 +39,7 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&DebugFlag, "debug", "d", false, "Run with debugging messages enabled.") rootCmd.PersistentFlags().IntVar(&LogLevel, "loglevel", wwlog.INFO, "Set log level to given string") _ = rootCmd.PersistentFlags().MarkHidden("loglevel") + rootCmd.PersistentFlags().StringVar(&WarewulfConfArg, "warewulfconf", "", "Set the warewulf configuration file") rootCmd.SetUsageTemplate(help.UsageTemplate) rootCmd.SetHelpTemplate(help.HelpTemplate) @@ -69,5 +72,6 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) error { if LogLevel != wwlog.INFO { wwlog.SetLogLevel(LogLevel) } + warewulfconf.ConfigFile = WarewulfConfArg return nil } diff --git a/internal/pkg/warewulfconf/constructors.go b/internal/pkg/warewulfconf/constructors.go index c434d66e..f956bcd0 100644 --- a/internal/pkg/warewulfconf/constructors.go +++ b/internal/pkg/warewulfconf/constructors.go @@ -19,7 +19,13 @@ var cachedConf ControllerConf var ConfigFile string +/* +Get the configFile location from the os.ev if set +*/ func init() { + if ConfigFile == "" { + ConfigFile = os.Getenv("WARWULFCONF") + } if ConfigFile == "" { ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/warewulf.conf") } @@ -51,7 +57,7 @@ func New() (ControllerConf, error) { wwlog.Debug("Opening Warewulf configuration file: %s", ConfigFile) data, err := os.ReadFile(ConfigFile) if err != nil { - wwlog.Warn("Error reading Warewulf configuration file") + wwlog.Warn("Error reading Warewulf configuration file, falling back on defaults") } wwlog.Debug("Unmarshaling the Warewulf configuration") @@ -71,12 +77,12 @@ func New() (ControllerConf, error) { localIp := conn.LocalAddr().(*net.UDPAddr) if ret.Ipaddr == "" { ret.Ipaddr = localIp.IP.String() - wwlog.Warn("IP address is not configured in warewulfd.conf, using %s", ret.Ipaddr) + wwlog.Verbose("IP address is not configured in warewulfd.conf, using %s", ret.Ipaddr) } if ret.Netmask == "" { mask := localIp.IP.DefaultMask() ret.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3]) - wwlog.Warn("Netmask address is not configured in warewulfd.conf, using %s", ret.Netmask) + wwlog.Verbose("Netmask address is not configured in warewulfd.conf, using %s", ret.Netmask) } } diff --git a/internal/pkg/warewulfconf/datastructure.go b/internal/pkg/warewulfconf/datastructure.go index 8403e878..38443883 100644 --- a/internal/pkg/warewulfconf/datastructure.go +++ b/internal/pkg/warewulfconf/datastructure.go @@ -2,7 +2,6 @@ package warewulfconf import ( "github.com/creasty/defaults" - "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" ) @@ -80,13 +79,9 @@ func (s *NfsConf) Unmarshal(unmarshal func(interface{}) error) error { } func init() { - if !util.IsFile(ConfigFile) { - wwlog.Error("Configuration file not found: %s", ConfigFile) - // fail silently as this also called by bash_completion - } _, err := New() if err != nil { - wwlog.Error("Could not read Warewulf configuration file: %s", err) + wwlog.Warn("Could not get any Warewulf configuration: %s", err) } }