From ad45200f7a84ccb5decdce78e3563336f0264965 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 14 Feb 2022 16:53:48 +0100 Subject: [PATCH] extended tstruct for templating - tstruct is in new datastructure.go - updated fstab.ww to new syntax --- internal/pkg/overlay/datastructure.go | 38 +++++++++++++++++ internal/pkg/overlay/overlay.go | 48 +++++----------------- internal/pkg/warewulfconf/datastructure.go | 9 ++-- overlays/wwinit/etc/fstab.ww | 18 ++++++-- 4 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 internal/pkg/overlay/datastructure.go diff --git a/internal/pkg/overlay/datastructure.go b/internal/pkg/overlay/datastructure.go new file mode 100644 index 00000000..cc43ef43 --- /dev/null +++ b/internal/pkg/overlay/datastructure.go @@ -0,0 +1,38 @@ +package overlay + +import ( + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/hpcng/warewulf/internal/pkg/warewulfconf" +) + +type TemplateStruct struct { + Id string + Hostname string + ClusterName string + Container string + KernelVersion string + KernelArgs string + Init string + Root string + IpmiIpaddr string + IpmiNetmask string + IpmiPort string + IpmiGateway string + IpmiUserName string + IpmiPassword string + IpmiInterface string + RuntimeOverlay string + SystemOverlay string + NetDevs map[string]*node.NetDevs + Tags map[string]string + Keys map[string]string + AllNodes []node.NodeInfo + BuildHost string + BuildTime string + BuildSource string + Ipaddr string + Netmask string + Network string + Dhcp warewulfconf.DhcpConf + Nfs warewulfconf.NfsConf +} diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 1744eea8..e02dac8f 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "text/template" + "time" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/util" @@ -19,31 +20,6 @@ import ( "github.com/pkg/errors" ) -type TemplateStruct struct { - Id string - Hostname string - ClusterName string - Container string - KernelVersion string - KernelArgs string - Init string - Root string - IpmiIpaddr string - IpmiNetmask string - IpmiPort string - IpmiGateway string - IpmiUserName string - IpmiPassword string - IpmiInterface string - RuntimeOverlay string - SystemOverlay string - NetDevs map[string]*node.NetDevs - Tags map[string]string - Keys map[string]string - AllNodes []node.NodeInfo - NFSMounts []string -} - /* func BuildSystemOverlay(nodeList []node.NodeInfo) error { @@ -234,18 +210,15 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error { tstruct.Tags[keyname] = key.Get() } tstruct.AllNodes = allNodes - for _, export := range controller.Nfs.ExportsExtended { - if export.Mount { - var mountOpts string - if export.MountOptions == "" { - mountOpts = "defaults" - } else { - mountOpts = export.MountOptions - } - tstruct.NFSMounts = append(tstruct.NFSMounts, fmt.Sprintf("%s:%s %s nfs %s 0 0\n", controller.Ipaddr, export.Path, export.Path, mountOpts)) - } - } - + tstruct.Nfs = *controller.Nfs + tstruct.Dhcp = *controller.Dhcp + tstruct.Ipaddr = controller.Ipaddr + tstruct.Netmask = controller.Netmask + tstruct.Network = controller.Network + hostname, _ := os.Hostname() + tstruct.BuildHost = hostname + dt := time.Now() + tstruct.BuildTime = dt.Format("01-02-2006 15:04:05 MST") wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlaySourceDir) err = os.Chdir(OverlaySourceDir) if err != nil { @@ -275,6 +248,7 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error { wwlog.Printf(wwlog.DEBUG, "Created directory in overlay: %s\n", location) } else if filepath.Ext(location) == ".ww" { + tstruct.BuildSource = path.Join(OverlaySourceDir, location) wwlog.Printf(wwlog.VERBOSE, "Evaluating overlay template file: %s\n", location) destFile := strings.TrimSuffix(location, ".ww") diff --git a/internal/pkg/warewulfconf/datastructure.go b/internal/pkg/warewulfconf/datastructure.go index c1e32626..0b721204 100644 --- a/internal/pkg/warewulfconf/datastructure.go +++ b/internal/pkg/warewulfconf/datastructure.go @@ -52,9 +52,9 @@ type NfsConf struct { type NfsExportConf struct { Path string `yaml:"path"` - ExportOptions string `yaml:"export options"` - MountOptions string `yaml:"mount options"` - Mount bool `yaml:"mount"` + ExportOptions string `default:"rw,sync" yaml:"export options"` + MountOptions string `default:"defaults" yaml:"mount options"` + Mount bool `default:"true" yaml:"mount"` } func (s *NfsConf) UnmarshalYAML(unmarshal func(interface{}) error) error { @@ -70,7 +70,6 @@ func (s *NfsConf) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } - func init() { if !util.IsFile(ConfigFile) { wwlog.Printf(wwlog.ERROR, "Configuration file not found: %s\n", ConfigFile) @@ -86,4 +85,4 @@ func init() { func DataStore() string { return cachedConf.Warewulf.DataStore -} \ No newline at end of file +} diff --git a/overlays/wwinit/etc/fstab.ww b/overlays/wwinit/etc/fstab.ww index 84b64b15..c5263a3f 100644 --- a/overlays/wwinit/etc/fstab.ww +++ b/overlays/wwinit/etc/fstab.ww @@ -1,8 +1,20 @@ +# This file is autogenerated by warewulf +# Host: {{.BuildHost}} +# Time: {{.BuildTime}} +# Source: {{.BuildSource}} rootfs / tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /run/shm tmpfs defaults 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 -{{range .NFSMounts}} - {{.}} -{{end}} +{{- $IP:=.Ipaddr }} +{{- if .Nfs.Enabled }} +{{- range .Nfs.ExportsExtended }} +{{- if .Mount }} +{{ $IP }}:{{ .Path }} {{ .Path }} nfs {{ .MountOptions }} 0 0 +{{- end }} +{{- end }} +{{- end }} +{{- range .Nfs.Exports }} +{{ $IP }}:{{ . }} {{ . }} nfs defaults 0 0 +{{- end }}