Configure nodes.conf path dynamically from config
Removes the use of init() to initialize the variable. - Closes: #1596 - See also: #1569 Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -77,6 +77,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Merge Kernel.Override into Kernel.Version to specify the desired kernel version or path. #1556
|
- Merge Kernel.Override into Kernel.Version to specify the desired kernel version or path. #1556
|
||||||
- Provide detected kernel version to overlay templates. #1556
|
- Provide detected kernel version to overlay templates. #1556
|
||||||
- Bump github.com/containers/storage from 1.53.0 to 1.55.2 #1316, #892
|
- Bump github.com/containers/storage from 1.53.0 to 1.55.2 #1316, #892
|
||||||
|
- Process nodes.conf path dynamically from config. #1595, #1596, #1569
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -45,10 +45,6 @@ wwctl: $(config) $(call godeps,cmd/wwctl/main.go)
|
|||||||
wwclient: $(config) $(call godeps,cmd/wwclient/main.go)
|
wwclient: $(config) $(call godeps,cmd/wwclient/main.go)
|
||||||
CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static" -o wwclient cmd/wwclient/main.go
|
CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static" -o wwclient cmd/wwclient/main.go
|
||||||
|
|
||||||
update_configuration: $(config) $(call godeps,cmd/update_configuration/update_configuration.go)
|
|
||||||
go build -X 'github.com/warewulf/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'" \
|
|
||||||
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o update_configuration cmd/update_configuration/update_configuration.go
|
|
||||||
|
|
||||||
wwapid: $(config) $(apiconfig) $(call godeps,internal/app/api/wwapid/wwapid.go)
|
wwapid: $(config) $(apiconfig) $(call godeps,internal/app/api/wwapid/wwapid.go)
|
||||||
go build -o ./wwapid internal/app/api/wwapid/wwapid.go
|
go build -o ./wwapid internal/app/api/wwapid/wwapid.go
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ var (
|
|||||||
keyTypes []string
|
keyTypes []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
baseCmd.PersistentFlags().StringArrayVarP(&keyTypes, "keytypes", "t", []string{}, "ssh key types to be created")
|
baseCmd.PersistentFlags().StringArrayVarP(&keyTypes, "keytypes", "t", []string{}, "ssh key types to be created")
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Nothing to do here
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&Build, "build", "b", false, "Build container after copy")
|
baseCmd.PersistentFlags().BoolVarP(&Build, "build", "b", false, "Build container after copy")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ var baseCmd = &cobra.Command{
|
|||||||
var SetBuild bool
|
var SetBuild bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Nothing to do here
|
|
||||||
baseCmd.PersistentFlags().BoolVarP(&SetBuild, "build", "b", false, "Build container after rename")
|
baseCmd.PersistentFlags().BoolVarP(&SetBuild, "build", "b", false, "Build container after rename")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ var (
|
|||||||
Zsh bool
|
Zsh bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ var (
|
|||||||
NoHeader bool
|
NoHeader bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ package list
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
@@ -396,30 +393,14 @@ NODE FIELD PROFILE VALUE
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_yml := ``
|
|
||||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
defer os.Remove(tempWarewulfConf.Name())
|
|
||||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
assert.NoError(t, tempWarewulfConf.Sync())
|
|
||||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
|
||||||
|
|
||||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
|
||||||
assert.NoError(t, nodesConfErr)
|
|
||||||
defer os.Remove(tempNodeConf.Name())
|
|
||||||
node.ConfigFile = tempNodeConf.Name()
|
|
||||||
warewulfd.SetNoDaemon()
|
warewulfd.SetNoDaemon()
|
||||||
for _, tt := range tests {
|
env := testenv.New(t)
|
||||||
var err error
|
defer env.RemoveAll(t)
|
||||||
_, err = tempNodeConf.Seek(0, 0)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
|
||||||
_, err = tempNodeConf.Write([]byte(tt.inDb))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, tempNodeConf.Sync())
|
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||||
|
|
||||||
baseCmd := GetCommand()
|
baseCmd := GetCommand()
|
||||||
baseCmd.SetArgs(tt.args)
|
baseCmd.SetArgs(tt.args)
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
@@ -646,19 +643,6 @@ nodes:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_yml := ``
|
|
||||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
defer os.Remove(tempWarewulfConf.Name())
|
|
||||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
assert.NoError(t, tempWarewulfConf.Sync())
|
|
||||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
|
||||||
|
|
||||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
|
||||||
assert.NoError(t, nodesConfErr)
|
|
||||||
defer os.Remove(tempNodeConf.Name())
|
|
||||||
node.ConfigFile = tempNodeConf.Name()
|
|
||||||
warewulfd.SetNoDaemon()
|
warewulfd.SetNoDaemon()
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
run_test(t, tt)
|
run_test(t, tt)
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -28,9 +28,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// baseCmd.PersistentFlags().BoolVarP(&test, "test", "t", false, "Testing.")
|
|
||||||
|
|
||||||
baseCmd.AddCommand(powercycle.GetCommand())
|
baseCmd.AddCommand(powercycle.GetCommand())
|
||||||
baseCmd.AddCommand(poweroff.GetCommand())
|
baseCmd.AddCommand(poweroff.GetCommand())
|
||||||
baseCmd.AddCommand(poweron.GetCommand())
|
baseCmd.AddCommand(poweron.GetCommand())
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
@@ -96,31 +95,13 @@ nodes:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_yml := ``
|
|
||||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
defer os.Remove(tempWarewulfConf.Name())
|
|
||||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
assert.NoError(t, tempWarewulfConf.Sync())
|
|
||||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
|
||||||
|
|
||||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
|
||||||
assert.NoError(t, nodesConfErr)
|
|
||||||
defer os.Remove(tempNodeConf.Name())
|
|
||||||
node.ConfigFile = tempNodeConf.Name()
|
|
||||||
warewulfd.SetNoDaemon()
|
warewulfd.SetNoDaemon()
|
||||||
for _, tt := range tests {
|
env := testenv.New(t)
|
||||||
var err error
|
defer env.RemoveAll(t)
|
||||||
_, err = tempNodeConf.Seek(0, 0)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
|
||||||
_, err = tempNodeConf.Write([]byte(tt.inDb))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, tempNodeConf.Sync())
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||||
baseCmd := GetCommand()
|
baseCmd := GetCommand()
|
||||||
baseCmd.SetArgs(tt.args)
|
baseCmd.SetArgs(tt.args)
|
||||||
stdoutR, stdoutW, _ := os.Pipe()
|
stdoutR, stdoutW, _ := os.Pipe()
|
||||||
@@ -270,28 +251,12 @@ nodes:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_yml := ``
|
|
||||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
defer os.Remove(tempWarewulfConf.Name())
|
|
||||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
|
||||||
assert.NoError(t, warewulfConfErr)
|
|
||||||
assert.NoError(t, tempWarewulfConf.Sync())
|
|
||||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
|
||||||
|
|
||||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
|
||||||
assert.NoError(t, nodesConfErr)
|
|
||||||
defer os.Remove(tempNodeConf.Name())
|
|
||||||
node.ConfigFile = tempNodeConf.Name()
|
|
||||||
warewulfd.SetNoDaemon()
|
warewulfd.SetNoDaemon()
|
||||||
|
env := testenv.New(t)
|
||||||
|
defer env.RemoveAll(t)
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
var err error
|
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||||
_, err = tempNodeConf.Seek(0, 0)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
|
||||||
_, err = tempNodeConf.Write([]byte(tt.inDb))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, tempNodeConf.Sync())
|
|
||||||
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
baseCmd := GetCommand()
|
baseCmd := GetCommand()
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func init() {
|
|||||||
rootCmd.AddCommand(ssh.GetCommand())
|
rootCmd.AddCommand(ssh.GetCommand())
|
||||||
rootCmd.AddCommand(genconf.GetCommand())
|
rootCmd.AddCommand(genconf.GetCommand())
|
||||||
rootCmd.AddCommand(clean.GetCommand())
|
rootCmd.AddCommand(clean.GetCommand())
|
||||||
rootCmd.AddCommand(upgrade.Command)
|
rootCmd.AddCommand(upgrade.GetCommand())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
|
|||||||
@@ -7,17 +7,15 @@ import (
|
|||||||
"github.com/warewulf/warewulf/internal/app/wwctl/upgrade/nodes"
|
"github.com/warewulf/warewulf/internal/app/wwctl/upgrade/nodes"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func GetCommand() *cobra.Command {
|
||||||
Command = &cobra.Command{
|
command := &cobra.Command{
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Use: "upgrade <config|nodes> [OPTIONS]",
|
Use: "upgrade <config|nodes> [OPTIONS]",
|
||||||
Short: "Upgrade configuration files",
|
Short: "Upgrade configuration files",
|
||||||
Long: `Upgrade warewulf.conf or nodes.conf from a previous version of Warewulf 4 to a format
|
Long: `Upgrade warewulf.conf or nodes.conf from a previous version of Warewulf 4 to a format
|
||||||
supported by the current version.`,
|
supported by the current version.`,
|
||||||
}
|
}
|
||||||
)
|
command.AddCommand(config.GetCommand())
|
||||||
|
command.AddCommand(nodes.GetCommand())
|
||||||
func init() {
|
return command
|
||||||
Command.AddCommand(config.Command)
|
|
||||||
Command.AddCommand(nodes.Command)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,17 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
libupgrade "github.com/warewulf/warewulf/internal/pkg/upgrade"
|
"github.com/warewulf/warewulf/internal/pkg/upgrade"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Command = &cobra.Command{
|
inputPath string
|
||||||
|
outputPath string
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetCommand() *cobra.Command {
|
||||||
|
command := &cobra.Command{
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Use: "config [OPTIONS]",
|
Use: "config [OPTIONS]",
|
||||||
Short: "Upgrade an existing warewulf.conf",
|
Short: "Upgrade an existing warewulf.conf",
|
||||||
@@ -20,14 +25,9 @@ var (
|
|||||||
supported by the current version.`,
|
supported by the current version.`,
|
||||||
RunE: UpgradeNodesConf,
|
RunE: UpgradeNodesConf,
|
||||||
}
|
}
|
||||||
|
command.Flags().StringVarP(&inputPath, "input-path", "i", config.ConfigFile, "Path to a legacy warewulf.conf")
|
||||||
inputPath string
|
command.Flags().StringVarP(&outputPath, "output-path", "o", config.ConfigFile, "Path to write the upgraded warewulf.conf to")
|
||||||
outputPath string
|
return command
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
||||||
@@ -35,7 +35,7 @@ func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
legacy, err := libupgrade.ParseConfig(data)
|
legacy, err := upgrade.ParseConfig(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,20 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
libupgrade "github.com/warewulf/warewulf/internal/pkg/upgrade"
|
"github.com/warewulf/warewulf/internal/pkg/upgrade"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Command = &cobra.Command{
|
addDefaults bool
|
||||||
|
replaceOverlays bool
|
||||||
|
inputPath string
|
||||||
|
outputPath string
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetCommand() *cobra.Command {
|
||||||
|
command := &cobra.Command{
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Use: "nodes [OPTIONS]",
|
Use: "nodes [OPTIONS]",
|
||||||
Short: "Upgrade an existing nodes.conf",
|
Short: "Upgrade an existing nodes.conf",
|
||||||
@@ -20,32 +27,33 @@ var (
|
|||||||
supported by the current version.`,
|
supported by the current version.`,
|
||||||
RunE: UpgradeNodesConf,
|
RunE: UpgradeNodesConf,
|
||||||
}
|
}
|
||||||
|
command.Flags().BoolVar(&addDefaults, "add-defaults", false, "Configure a default profile and set default node values")
|
||||||
addDefaults bool
|
command.Flags().BoolVar(&replaceOverlays, "replace-overlays", false, "Replace 'wwinit' and 'generic' overlays with their split replacements")
|
||||||
replaceOverlays bool
|
command.Flags().StringVarP(&inputPath, "input-path", "i", "", "Path to a legacy nodes.conf")
|
||||||
inputPath string
|
command.Flags().StringVarP(&outputPath, "output-path", "o", "", "Path to write the upgraded nodes.conf to")
|
||||||
outputPath string
|
if err := command.MarkFlagRequired("add-defaults"); err != nil {
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Command.Flags().BoolVar(&addDefaults, "add-defaults", false, "Configure a default profile and set default node values")
|
|
||||||
Command.Flags().BoolVar(&replaceOverlays, "replace-overlays", false, "Replace 'wwinit' and 'generic' overlays with their split replacements")
|
|
||||||
Command.Flags().StringVarP(&inputPath, "input-path", "i", node.ConfigFile, "Path to a legacy nodes.conf")
|
|
||||||
Command.Flags().StringVarP(&outputPath, "output-path", "o", node.ConfigFile, "Path to write the upgraded nodes.conf to")
|
|
||||||
if err := Command.MarkFlagRequired("add-defaults"); err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := Command.MarkFlagRequired("replace-overlays"); err != nil {
|
if err := command.MarkFlagRequired("replace-overlays"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
||||||
|
inputPath := inputPath
|
||||||
|
if inputPath == "" {
|
||||||
|
inputPath = config.Get().Paths.NodesConf()
|
||||||
|
}
|
||||||
|
outputPath := outputPath
|
||||||
|
if outputPath == "" {
|
||||||
|
outputPath = config.Get().Paths.NodesConf()
|
||||||
|
}
|
||||||
data, err := os.ReadFile(inputPath)
|
data, err := os.ReadFile(inputPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
legacy, err := libupgrade.ParseNodes(data)
|
legacy, err := upgrade.ParseNodes(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,17 +30,10 @@ Simple check if the config can be written in case wwctl isn't run as root
|
|||||||
*/
|
*/
|
||||||
func CanWriteConfig() (canwrite *wwapiv1.CanWriteConfig, err error) {
|
func CanWriteConfig() (canwrite *wwapiv1.CanWriteConfig, err error) {
|
||||||
canwrite = new(wwapiv1.CanWriteConfig)
|
canwrite = new(wwapiv1.CanWriteConfig)
|
||||||
// node is not initialized yet
|
nodesConf := config.Get().Paths.NodesConf()
|
||||||
if node.ConfigFile == "" {
|
err = syscall.Access(nodesConf, syscall.O_RDWR)
|
||||||
_, err := node.New()
|
|
||||||
if err != nil {
|
|
||||||
canwrite.CanWriteConfig = false
|
|
||||||
return canwrite, fmt.Errorf("unable to initialize the node %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = syscall.Access(node.ConfigFile, syscall.O_RDWR)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Warn("Couldn't open %s:%s", node.ConfigFile, err)
|
wwlog.Warn("Couldn't open %s:%s", nodesConf, err)
|
||||||
canwrite.CanWriteConfig = false
|
canwrite.CanWriteConfig = false
|
||||||
} else {
|
} else {
|
||||||
canwrite.CanWriteConfig = true
|
canwrite.CanWriteConfig = true
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ func (this WarewulfConf) GrubBoot() bool {
|
|||||||
return util.BoolP(this.GrubBootP)
|
return util.BoolP(this.GrubBootP)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (paths BuildConfig) NodesConf() string {
|
||||||
|
return path.Join(paths.Sysconfdir, "warewulf", "nodes.conf")
|
||||||
|
}
|
||||||
|
|
||||||
func (paths BuildConfig) OciBlobCachedir() string {
|
func (paths BuildConfig) OciBlobCachedir() string {
|
||||||
return path.Join(paths.Cachedir, "warewulf")
|
return path.Join(paths.Cachedir, "warewulf")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
@@ -14,23 +13,13 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ConfigFile string
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
conf := warewulfconf.Get()
|
|
||||||
if ConfigFile == "" {
|
|
||||||
ConfigFile = path.Join(conf.Paths.Sysconfdir, "warewulf/nodes.conf")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Creates a new nodeDb object from the on-disk configuration
|
Creates a new nodeDb object from the on-disk configuration
|
||||||
*/
|
*/
|
||||||
func New() (NodesYaml, error) {
|
func New() (NodesYaml, error) {
|
||||||
wwlog.Verbose("Opening node configuration file: %s", ConfigFile)
|
nodesConf := warewulfconf.Get().Paths.NodesConf()
|
||||||
data, err := os.ReadFile(ConfigFile)
|
wwlog.Verbose("Opening node configuration file: %s", nodesConf)
|
||||||
|
data, err := os.ReadFile(nodesConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NodesYaml{}, err
|
return NodesYaml{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
|
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -109,12 +110,12 @@ func (config *NodesYaml) DelProfile(nodeID string) error {
|
|||||||
Write the the NodeYaml to disk.
|
Write the the NodeYaml to disk.
|
||||||
*/
|
*/
|
||||||
func (config *NodesYaml) Persist() error {
|
func (config *NodesYaml) Persist() error {
|
||||||
return config.PersistToFile(ConfigFile)
|
return config.PersistToFile(warewulfconf.Get().Paths.NodesConf())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *NodesYaml) PersistToFile(configFile string) error {
|
func (config *NodesYaml) PersistToFile(configFile string) error {
|
||||||
if configFile == "" {
|
if configFile == "" {
|
||||||
configFile = ConfigFile
|
configFile = warewulfconf.Get().Paths.NodesConf()
|
||||||
}
|
}
|
||||||
out, dumpErr := config.Dump()
|
out, dumpErr := config.Dump()
|
||||||
if dumpErr != nil {
|
if dumpErr != nil {
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
|
||||||
|
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const initWarewulfConf = ``
|
const initWarewulfConf = ``
|
||||||
@@ -61,7 +60,7 @@ func New(t *testing.T) (env *TestEnv) {
|
|||||||
env.WriteFile(t, path.Join(Sysconfdir, "warewulf/warewulf.conf"), initWarewulfConf)
|
env.WriteFile(t, path.Join(Sysconfdir, "warewulf/warewulf.conf"), initWarewulfConf)
|
||||||
|
|
||||||
// re-read warewulf.conf
|
// re-read warewulf.conf
|
||||||
conf := warewulfconf.New()
|
conf := config.New()
|
||||||
err = conf.Read(env.GetPath(path.Join(Sysconfdir, "warewulf/warewulf.conf")))
|
err = conf.Read(env.GetPath(path.Join(Sysconfdir, "warewulf/warewulf.conf")))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@@ -95,9 +94,6 @@ func New(t *testing.T) (env *TestEnv) {
|
|||||||
env.MkdirAll(t, confPath)
|
env.MkdirAll(t, confPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// node.init() has already run, so set the config path again
|
|
||||||
node.ConfigFile = env.GetPath(path.Join(Sysconfdir, "warewulf/nodes.conf"))
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
nodepkg "github.com/warewulf/warewulf/internal/pkg/node"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
@@ -51,7 +51,7 @@ func getOverlayFile(n node.Node, context string, stage_overlays []string, autobu
|
|||||||
build := !util.IsFile(stage_file)
|
build := !util.IsFile(stage_file)
|
||||||
wwlog.Verbose("stage file: %s", stage_file)
|
wwlog.Verbose("stage file: %s", stage_file)
|
||||||
if !build && autobuild {
|
if !build && autobuild {
|
||||||
build = util.PathIsNewer(stage_file, nodepkg.ConfigFile)
|
build = util.PathIsNewer(stage_file, config.Get().Paths.NodesConf())
|
||||||
|
|
||||||
for _, overlayname := range stage_overlays {
|
for _, overlayname := range stage_overlays {
|
||||||
build = build || util.PathIsNewer(stage_file, overlay.OverlaySourceDir(overlayname))
|
build = build || util.PathIsNewer(stage_file, overlay.OverlaySourceDir(overlayname))
|
||||||
|
|||||||
Reference in New Issue
Block a user