Use configured warewulf.conf path in wwctl upgrade
- Fixes: #1658 Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user