From 170d03e751a7b01abb13cf4b473a503b5e8d8490 Mon Sep 17 00:00:00 2001 From: xu yang Date: Wed, 19 Jun 2024 09:31:32 +0000 Subject: [PATCH] fix the issue that system/runtime overlays are not auto-rebuilt Signed-off-by: xu yang --- CHANGELOG.md | 6 ++++++ internal/pkg/overlay/overlay.go | 3 ++- internal/pkg/overlay/overlay_test.go | 31 +++++++++++++--------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de5b6505..65b62921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix a regression that caused an error when passing flags to `wwctl container exec` and `wwctl container shell`. #1250 +## v4.5.x, unreleased + +### Fixed + +- Fix the issue that system/runtime overlays are not auto-rebuilt. #1216 + ## v4.5.3, 2024-06-07 ### Added diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index c0f93a24..a49c8bb7 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -127,9 +127,10 @@ func OverlayInit(overlayName string) error { Build the given overlays for a node and create a Image for them */ func BuildOverlay(nodeInfo node.NodeInfo, context string, overlayNames []string) error { - if len(overlayNames) == 0 { + if len(overlayNames) == 0 && context == "" { return nil } + // create the dir where the overlay images will reside name := fmt.Sprintf("overlay %s/%v", nodeInfo.Id.Get(), overlayNames) overlayImage := OverlayImage(nodeInfo.Id.Get(), context, overlayNames) diff --git a/internal/pkg/overlay/overlay_test.go b/internal/pkg/overlay/overlay_test.go index 833dfb06..e5c9fa48 100644 --- a/internal/pkg/overlay/overlay_test.go +++ b/internal/pkg/overlay/overlay_test.go @@ -40,11 +40,11 @@ var buildOverlayTests = []struct { contents: nil, }, { - description: "if only context is specified then no overlay image is generated", + description: "if only context is specified then context named image is generated", nodeName: "", context: "system", overlays: nil, - image: "", + image: "__SYSTEM__.img", contents: nil, }, { @@ -80,19 +80,19 @@ var buildOverlayTests = []struct { contents: []string{"o1.txt", "o2.txt"}, }, { - description: "if no node system overlays are specified, then no overlay image is generated", + description: "if no node system overlays are specified, then context pointed overlay is generated", nodeName: "node1", context: "system", overlays: nil, - image: "", + image: "node1/__SYSTEM__.img", contents: nil, }, { - description: "if no node runtime overlays are specified, then no overlay image is generated", + description: "if no node runtime overlays are specified, then context pointed overlay is generated", nodeName: "node1", context: "runtime", overlays: nil, - image: "", + image: "node1/__RUNTIME__.img", contents: nil, }, { @@ -147,9 +147,6 @@ func Test_BuildOverlay(t *testing.T) { } for _, tt := range buildOverlayTests { - assert.True(t, (tt.image != "" && tt.contents != nil) || (tt.image == "" && tt.contents == nil), - "image and contents must eiher be populated or empty together") - nodeInfo := node.NodeInfo{} nodeInfo.Id.Set(tt.nodeName) t.Run(tt.description, func(t *testing.T) { @@ -196,18 +193,18 @@ var buildAllOverlaysTests = []struct { createdOverlays: nil, }, { - description: "a node with no overlays creates no overlays", + description: "a node with no overlays creates default system/runtime overlays", nodes: []string{"node1"}, - systemOverlays: nil, - runtimeOverlays: nil, - createdOverlays: nil, + systemOverlays: [][]string{{"o1"}}, + runtimeOverlays: [][]string{{"o1"}}, + createdOverlays: []string{"node1/__SYSTEM__.img.gz", "node1/__RUNTIME__.img.gz"}, }, { - description: "multiple nodes with no overlays creates no overlays", + description: "multiple nodes with no overlays creates default system/runtime overlays", nodes: []string{"node1", "node2"}, - systemOverlays: nil, - runtimeOverlays: nil, - createdOverlays: nil, + systemOverlays: [][]string{{"o1"}, {"o2"}}, + runtimeOverlays: [][]string{{"o1"}, {"o2"}}, + createdOverlays: []string{"node1/__SYSTEM__.img.gz", "node1/__RUNTIME__.img.gz", "node2/__SYSTEM__.img.gz", "node2/__RUNTIME__.img.gz"}, }, { description: "a system overlay for a node generates a system overlay for that node",