diff --git a/CHANGELOG.md b/CHANGELOG.md index 474baf70..5e2babd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Wait until ignition has completed before trying to mount. - Fix timeout problem for wwclient. #1741 - Fixed default "true" state of NetDev.OnBoot. #1754 +- Port NFS mounts during `wwctl upgrade nodes` before applying defaults. #1758 ### Removed diff --git a/internal/pkg/upgrade/node.go b/internal/pkg/upgrade/node.go index 70960787..46cf5d63 100644 --- a/internal/pkg/upgrade/node.go +++ b/internal/pkg/upgrade/node.go @@ -67,6 +67,47 @@ func (legacy *NodesYaml) Upgrade(addDefaults bool, replaceOverlays bool, warewul wwlog.Warn("node %s does not include the default profile: verify default settings manually", name) } } + if warewulfconf != nil && warewulfconf.NFS != nil { + var fstab []map[string]string + for _, export := range warewulfconf.NFS.Exports { + 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) + } + } + 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 + } + } + } if addDefaults { if _, ok := upgraded.NodeProfiles["default"]; !ok { upgraded.NodeProfiles["default"] = new(node.Profile) @@ -113,47 +154,6 @@ func (legacy *NodesYaml) Upgrade(addDefaults bool, replaceOverlays bool, warewul } } } - if warewulfconf != nil && warewulfconf.NFS != nil { - var fstab []map[string]string - for _, export := range warewulfconf.NFS.Exports { - 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) - } - } - 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 - } - } - } return upgraded } diff --git a/internal/pkg/upgrade/node_test.go b/internal/pkg/upgrade/node_test.go index 79037b2f..fa04fea5 100644 --- a/internal/pkg/upgrade/node_test.go +++ b/internal/pkg/upgrade/node_test.go @@ -880,6 +880,73 @@ nfs: mount: true - path: /var mount: false + mount options: defaults + - path: /srv + mount options: defaults +`, + }, + { + name: "Legacy extended export mounts with defaults", + addDefaults: true, + legacyYaml: ` +nodeprofiles: + default: {} +`, + upgradedYaml: ` +nodeprofiles: + default: + ipxe template: default + runtime overlay: + - hosts + - ssh.authorized_keys + - syncuser + system overlay: + - wwinit + - wwclient + - fstab + - hostname + - ssh.host_keys + - issue + - resolv + - udev.netname + - systemd.netname + - ifcfg + - NetworkManager + - debian.interfaces + - wicked + - ignition + kernel: + args: + - quiet + - crashkernel=no + - vga=791 + - net.naming-scheme=v238 + init: /sbin/init + root: initramfs + 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 + mount options: defaults + - path: /srv + mount options: defaults `, }, {