Use configured warewulf.conf path in wwctl upgrade

- Fixes: #1658

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-01-30 10:52:29 -07:00
parent 20c3b3db23
commit 736f9dae48
4 changed files with 25 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix default nodes.conf to use the new kernel command line list format. #1670
- Fix `make install` when `sudo` does not set `$PWD`. #1660
- Use sh to parse and exec IPMI command. #1663
- Use configured warewulf.conf path in `wwctl upgrade`. #1658
## v4.6.0rc1, 2025-01-29

View File

@@ -78,20 +78,22 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) (err error) {
if LogLevel != wwlog.INFO {
wwlog.SetLogLevel(LogLevel)
}
if WarewulfConfArg != "" {
warewulfconf.ConfigFile = WarewulfConfArg
} else if os.Getenv("WAREWULFCONF") != "" {
warewulfconf.ConfigFile = os.Getenv("WAREWULFCONF")
}
conf := warewulfconf.Get()
if !AllowEmptyConf && !conf.InitializedFromFile() {
if WarewulfConfArg != "" {
err = conf.Read(WarewulfConfArg)
} else if os.Getenv("WAREWULFCONF") != "" {
err = conf.Read(os.Getenv("WAREWULFCONF"))
} else {
err = conf.Read(warewulfconf.ConfigFile)
if err = conf.Read(warewulfconf.ConfigFile); err != nil {
wwlog.Error("error reading config file: %s", err)
return
}
}
if err != nil {
wwlog.Error("version: %s relase: %s", warewulfconf.Version, warewulfconf.Release)
return
if err = conf.SetDynamicDefaults(); err != nil {
wwlog.Error("error setting default configuration: %s", err)
}
err = conf.SetDynamicDefaults()
return
}

View File

@@ -25,12 +25,18 @@ func GetCommand() *cobra.Command {
supported by the current version.`,
RunE: UpgradeNodesConf,
}
command.Flags().StringVarP(&inputPath, "input-path", "i", config.ConfigFile, "Path to a legacy warewulf.conf")
command.Flags().StringVarP(&outputPath, "output-path", "o", config.ConfigFile, "Path to write the upgraded warewulf.conf to")
command.Flags().StringVarP(&inputPath, "input-path", "i", "", "Path to a legacy warewulf.conf")
command.Flags().StringVarP(&outputPath, "output-path", "o", "", "Path to write the upgraded warewulf.conf to")
return command
}
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
if inputPath == "" {
inputPath = config.ConfigFile
}
if outputPath == "" {
outputPath = config.ConfigFile
}
data, err := os.ReadFile(inputPath)
if err != nil {
return err

View File

@@ -32,7 +32,7 @@ supported by the current version.`,
command.Flags().BoolVar(&replaceOverlays, "replace-overlays", false, "Replace 'wwinit' and 'generic' overlays with their split replacements")
command.Flags().StringVarP(&inputPath, "input-path", "i", "", "Path to a legacy nodes.conf")
command.Flags().StringVarP(&outputPath, "output-path", "o", "", "Path to write the upgraded nodes.conf to")
command.Flags().StringVar(&inputConfPath, "with-warewulfconf", config.ConfigFile, "Path to a legacy warewulf.conf")
command.Flags().StringVar(&inputConfPath, "with-warewulfconf", "", "Path to a legacy warewulf.conf")
if err := command.MarkFlagRequired("add-defaults"); err != nil {
panic(err)
}
@@ -51,6 +51,9 @@ func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
if outputPath == "" {
outputPath = config.Get().Paths.NodesConf()
}
if inputConfPath == "" {
inputConfPath = config.ConfigFile
}
confData, err := os.ReadFile(inputConfPath)
if err != nil {