Recommended changes from review of #1568
- Make Resources an `interface{}` to support arbitrary yaml
- Remove `wwctl resource` as incompatible with arbitrary yaml
- Revert changes to host overlay templates
- Remove NFS mount options from warewulf.conf
- Replace NFS support / resource prefix with "fstab" resource
- Move resources to profiles
- Migrate warewulf.conf mounts to nodes.conf with `wwctl upgrade`
- Add documentation
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func ParseConfig(data []byte) (warewulfYaml *WarewulfYaml, err error) {
|
||||
@@ -175,8 +176,9 @@ func (this *NFSExportConf) Upgrade() (upgraded *config.NFSExportConf) {
|
||||
upgraded = new(config.NFSExportConf)
|
||||
upgraded.Path = this.Path
|
||||
upgraded.ExportOptions = this.ExportOptions
|
||||
upgraded.MountOptions = this.MountOptions
|
||||
upgraded.MountP = this.Mount
|
||||
if *(this.Mount) {
|
||||
wwlog.Warn("Legacy mount configured for NFS export %s: use `wwctl upgrade nodes --with-warewulfconf=<original file>` to port to nodes.conf", this.Path)
|
||||
}
|
||||
return upgraded
|
||||
}
|
||||
|
||||
|
||||
@@ -231,12 +231,8 @@ nfs:
|
||||
export paths:
|
||||
- path: /home
|
||||
export options: rw,sync
|
||||
mount options: defaults
|
||||
mount: true
|
||||
- path: /opt
|
||||
export options: ro,sync,no_root_squash
|
||||
mount options: defaults
|
||||
mount: false
|
||||
systemd name: nfs-server
|
||||
`,
|
||||
},
|
||||
@@ -299,12 +295,8 @@ nfs:
|
||||
export paths:
|
||||
- path: /home
|
||||
export options: rw,sync
|
||||
mount options: defaults
|
||||
mount: true
|
||||
- path: /opt
|
||||
export options: ro,sync,no_root_squash
|
||||
mount options: defaults
|
||||
mount: false
|
||||
systemd name: nfs-server
|
||||
`,
|
||||
},
|
||||
@@ -387,12 +379,8 @@ nfs:
|
||||
export paths:
|
||||
- path: /home
|
||||
export options: rw,sync
|
||||
mount options: defaults
|
||||
mount: true
|
||||
- path: /opt
|
||||
export options: ro,sync,no_root_squash
|
||||
mount options: defaults
|
||||
mount: false
|
||||
systemd name: nfs-server
|
||||
ssh:
|
||||
key types:
|
||||
@@ -485,12 +473,8 @@ nfs:
|
||||
export paths:
|
||||
- path: /home
|
||||
export options: rw,sync
|
||||
mount options: defaults
|
||||
mount: true
|
||||
- path: /opt
|
||||
export options: ro,sync,no_root_squash
|
||||
mount options: defaults
|
||||
mount: false
|
||||
systemd name: nfs-server
|
||||
ssh:
|
||||
key types:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -50,7 +51,7 @@ type NodesYaml struct {
|
||||
Nodes map[string]*Node
|
||||
}
|
||||
|
||||
func (this *NodesYaml) Upgrade(addDefaults bool, replaceOverlays bool) (upgraded *node.NodesYaml) {
|
||||
func (this *NodesYaml) Upgrade(addDefaults bool, replaceOverlays bool, warewulfconf *WarewulfYaml) (upgraded *node.NodesYaml) {
|
||||
upgraded = new(node.NodesYaml)
|
||||
upgraded.NodeProfiles = make(map[string]*node.Profile)
|
||||
upgraded.Nodes = make(map[string]*node.Node)
|
||||
@@ -93,6 +94,50 @@ func (this *NodesYaml) Upgrade(addDefaults bool, replaceOverlays bool) (upgraded
|
||||
defaultProfile.Ipxe = "default"
|
||||
}
|
||||
}
|
||||
if warewulfconf != nil && warewulfconf.NFS != nil {
|
||||
var fstab []map[string]string
|
||||
for _, export := range warewulfconf.NFS.Exports {
|
||||
fmt.Printf("PORTING EXPORT: %s\n", export)
|
||||
fstab = append(fstab, map[string]string{
|
||||
"spec": fmt.Sprintf("warewulf:%s", export),
|
||||
"file": export,
|
||||
"vfstype": "nfs",
|
||||
})
|
||||
}
|
||||
for _, export := range warewulfconf.NFS.ExportsExtended {
|
||||
if export.Mount != nil && *(export.Mount) {
|
||||
entry := map[string]string{
|
||||
"spec": fmt.Sprintf("warewulf:%s", export.Path),
|
||||
"file": export.Path,
|
||||
"vfstype": "nfs",
|
||||
}
|
||||
if export.MountOptions != "" {
|
||||
entry["mntops"] = export.MountOptions
|
||||
}
|
||||
fstab = append(fstab, entry)
|
||||
}
|
||||
}
|
||||
fmt.Printf("FSTAB: %+v\n", fstab)
|
||||
if len(fstab) > 0 {
|
||||
if _, ok := upgraded.NodeProfiles["default"]; !ok {
|
||||
upgraded.NodeProfiles["default"] = new(node.Profile)
|
||||
}
|
||||
if upgraded.NodeProfiles["default"].Resources == nil {
|
||||
upgraded.NodeProfiles["default"].Resources = make(map[string]node.Resource)
|
||||
}
|
||||
if _, ok := upgraded.NodeProfiles["default"].Resources["fstab"]; ok {
|
||||
if prevFstab, ok := (upgraded.NodeProfiles["default"].Resources["fstab"]).([]map[string]string); ok {
|
||||
newFstab := append(prevFstab, fstab...)
|
||||
upgraded.NodeProfiles["default"].Resources["fstab"] = newFstab
|
||||
} else {
|
||||
wwlog.Warn("Unable to port NFS mounts from warewulf.conf: incompatible existing fstab resource in default profile")
|
||||
}
|
||||
} else {
|
||||
upgraded.NodeProfiles["default"].Resources["fstab"] = fstab
|
||||
}
|
||||
fmt.Printf("RECORDED FSTAB: %+v\n", upgraded.NodeProfiles["default"].Resources["fstab"])
|
||||
}
|
||||
}
|
||||
return upgraded
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -16,6 +15,7 @@ var nodesYamlUpgradeTests = []struct {
|
||||
files map[string]string
|
||||
legacyYaml string
|
||||
upgradedYaml string
|
||||
warewulfConf string
|
||||
}{
|
||||
{
|
||||
name: "captured vers42 example",
|
||||
@@ -767,6 +767,64 @@ nodeprofiles:
|
||||
- p2
|
||||
p2: {}
|
||||
nodes: {}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "Legacy export mounts",
|
||||
legacyYaml: `
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
`,
|
||||
upgradedYaml: `
|
||||
nodeprofiles:
|
||||
default:
|
||||
resources:
|
||||
fstab:
|
||||
- spec: warewulf:/home
|
||||
file: /home
|
||||
vfstype: nfs
|
||||
- spec: warewulf:/opt
|
||||
file: /opt
|
||||
vfstype: nfs
|
||||
nodes: {}
|
||||
`,
|
||||
warewulfConf: `
|
||||
nfs:
|
||||
exports:
|
||||
- /home
|
||||
- /opt
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "Legacy extended export mounts",
|
||||
legacyYaml: `
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
`,
|
||||
upgradedYaml: `
|
||||
nodeprofiles:
|
||||
default:
|
||||
resources:
|
||||
fstab:
|
||||
- spec: warewulf:/home
|
||||
file: /home
|
||||
vfstype: nfs
|
||||
- spec: warewulf:/opt
|
||||
file: /opt
|
||||
mntops: defaults,ro
|
||||
vfstype: nfs
|
||||
nodes: {}
|
||||
`,
|
||||
warewulfConf: `
|
||||
nfs:
|
||||
export paths:
|
||||
- path: /home
|
||||
mount: true
|
||||
- path: /opt
|
||||
mount options: defaults,ro
|
||||
mount: true
|
||||
- path: /var
|
||||
mount: false
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -781,12 +839,14 @@ func Test_UpgradeNodesYaml(t *testing.T) {
|
||||
env.WriteFile(fileName, content)
|
||||
}
|
||||
}
|
||||
conf, err := ParseConfig([]byte(tt.warewulfConf))
|
||||
assert.NoError(t, err)
|
||||
legacy, err := ParseNodes([]byte(tt.legacyYaml))
|
||||
assert.NoError(t, err)
|
||||
upgraded := legacy.Upgrade(tt.addDefaults, tt.replaceOverlays)
|
||||
upgraded := legacy.Upgrade(tt.addDefaults, tt.replaceOverlays, conf)
|
||||
upgradedYaml, err := upgraded.Dump()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, strings.TrimSpace(tt.upgradedYaml), strings.TrimSpace(string(upgradedYaml)))
|
||||
assert.YAMLEq(t, tt.upgradedYaml, string(upgradedYaml))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user