From 847d11611bd016e1e9c78321288bda46bf8753fa Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 26 Nov 2024 12:03:21 +0100 Subject: [PATCH] creating exports from resource Signed-off-by: Christian Goll --- CHANGELOG.md | 1 + internal/pkg/overlay/funcmap.go | 3 ++- overlays/host/internal/host_test.go | 9 ++++----- overlays/host/internal/nodes.conf | 7 +++++++ overlays/host/rootfs/etc/exports.ww | 18 +++++++++--------- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e910ae79..34419edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - New "localtime" overlay to define the system time zone. #1303 - Add support for nested profiles. #1572, #1598 - Adds `wwctl container --build=false` to prevent automatically (re)building the container. #1490, #1489 +- Added resource as global variable for templates ### Changed diff --git a/internal/pkg/overlay/funcmap.go b/internal/pkg/overlay/funcmap.go index 0a2e99fb..374e4c2d 100644 --- a/internal/pkg/overlay/funcmap.go +++ b/internal/pkg/overlay/funcmap.go @@ -46,7 +46,8 @@ func templateFileBlock(inc string, abortStr string) (string, error) { wwlog.Debug("Including file block into template: %s", inc) readFile, err := os.Open(inc) if err != nil { - return "", err + wwlog.Info("couldn't read block %s: %s", inc, err) + return abortStr, nil } defer readFile.Close() var cont string diff --git a/overlays/host/internal/host_test.go b/overlays/host/internal/host_test.go index ef4f4b08..4faa14a9 100644 --- a/overlays/host/internal/host_test.go +++ b/overlays/host/internal/host_test.go @@ -58,7 +58,7 @@ func Test_hostOverlay(t *testing.T) { conf: "", args: []string{"--render", "host", "host", "etc/exports.ww"}, log: host_exports, - header: "", + header: "# Do not edit after this line", }, { name: "host:/etc/hosts", @@ -278,11 +278,10 @@ dhcp-host=e6:92:39:49:7b:04,set:warewulf,node2,192.168.3.23,infinite const host_exports string = `backupFile: true writeFile: true Filename: etc/exports - -# This file is autogenerated by warewulf +# Do not edit after this line +# This block is autogenerated by warewulf +# Resource: NFSHOME /home 192.168.0.0/255.255.255.0(rw,sync) -/opt 192.168.0.0/255.255.255.0(ro,sync,no_root_squash) - ` const host_hosts string = `backupFile: true diff --git a/overlays/host/internal/nodes.conf b/overlays/host/internal/nodes.conf index 3b286313..135a7a49 100644 --- a/overlays/host/internal/nodes.conf +++ b/overlays/host/internal/nodes.conf @@ -15,3 +15,10 @@ nodes: device: wwnet0 hwaddr: e6:92:39:49:7b:04 ipaddr: 192.168.3.23 +resource: + NFSHOME: + mountpoint: /home + moptions: defaults + eoptions: rw,sync + epath: /home + server: controller \ No newline at end of file diff --git a/overlays/host/rootfs/etc/exports.ww b/overlays/host/rootfs/etc/exports.ww index 7507c37f..61356b1c 100644 --- a/overlays/host/rootfs/etc/exports.ww +++ b/overlays/host/rootfs/etc/exports.ww @@ -1,11 +1,11 @@ -{{- if .Nfs.Enabled }} -# This file is autogenerated by warewulf +{{ IncludeBlock "/etc/exports" "# Do not edit after this line" }} +# This block is autogenerated by warewulf +{{- $Resource := .Resource }} {{- $network := .Network }} {{- $netmask := .Netmask }} -{{- range .Nfs.ExportsExtended }} -{{ .Path }} {{ $network }}/{{ $netmask }}({{ .ExportOptions }}) -{{- end }} -{{- else }} -{{ abort }} -{{- end }} - +{{- range $ResName,$Res := .Resource }} +{{- if eq (substr 0 3 $ResName) "NFS" }}{{ if eq $Res.server "controller" }} +# Resource: {{ $ResName }} +{{ $Res.epath}} {{ $network }}/{{ $netmask }}({{ $Res.eoptions }}) +{{- end }}{{ end }} +{{- end }} \ No newline at end of file