From cdbabfc834c115c2daa6e58578a6114f10f4c5b2 Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Fri, 27 Sep 2024 18:15:15 -0600 Subject: [PATCH] Update IgnitionJson to sort the list of file systems - Closes #1433 Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + internal/pkg/node/ignition.go | 3 ++ overlays/ignition/internal/ignition_test.go | 50 +++++++++++++++++---- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10cc0ab5..ed97ee0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Bump github.com/coreos/ignition/v2 from 2.15.0 to 2.19.0 #1239 - Disable building containers by default when calling `wwctl container copy`. #1378 - Split wwinit and generic overlays into discrete functionality. #987 +- Updated IgnitionJson to sort filesystems. #1433 ### Fixed diff --git a/internal/pkg/node/ignition.go b/internal/pkg/node/ignition.go index ba09d184..849c4fbd 100644 --- a/internal/pkg/node/ignition.go +++ b/internal/pkg/node/ignition.go @@ -47,6 +47,9 @@ func (node *NodeInfo) GetStorage() (stor types_3_4.Storage, err error, rep strin wwlog.Debug("created file system struct: %v", myFs) fileSystems = append(fileSystems, myFs) } + sort.SliceStable(fileSystems, func(i int, j int) bool { + return fileSystems[i].Device < fileSystems[j].Device + }) var disks []types_3_4.Disk for diskDev, disk := range node.Disks { var partitions []types_3_4.Partition diff --git a/overlays/ignition/internal/ignition_test.go b/overlays/ignition/internal/ignition_test.go index d4919b3c..2a1d45b5 100644 --- a/overlays/ignition/internal/ignition_test.go +++ b/overlays/ignition/internal/ignition_test.go @@ -2,8 +2,6 @@ package ignition import ( "bytes" - "encoding/json" - "reflect" "testing" "github.com/stretchr/testify/assert" @@ -61,10 +59,7 @@ func Test_ignitionOverlay(t *testing.T) { assert.Empty(t, stdout.String()) assert.Empty(t, stderr.String()) if tt.json { - var expected, actual interface{} - assert.NoError(t, json.Unmarshal([]byte(tt.log), &expected)) - assert.NoError(t, json.Unmarshal(logbuf.Bytes(), &actual)) - assert.True(t, reflect.DeepEqual(expected, actual), "expected: %v\nactual : %v", expected, actual) + assert.JSONEq(t, tt.log, logbuf.String()) } else { assert.Equal(t, tt.log, logbuf.String()) } @@ -116,5 +111,44 @@ What=/dev/disk/by-partlabel/swap RequiredBy=swap.target ` -const ignition_json string = `{"ignition":{"version":"3.1.0"},"storage":{"disks":[{"device":"/dev/vda","partitions":[{"label":"scratch","shouldExist":true,"wipePartitionEntry":false},{"label":"swap","number":1,"shouldExist":false,"sizeMiB":1024,"wipePartitionEntry":false}],"wipeTable":true}],"filesystems":[{"device":"/dev/disk/by-partlabel/scratch","format":"btrfs","path":"/scratch","wipeFilesystem":true},{"device":"/dev/disk/by-partlabel/swap","format":"swap","path":"swap","wipeFilesystem":false}]}} -` +const ignition_json string = `{ + "ignition": { + "version": "3.1.0" + }, + "storage": { + "disks": [ + { + "device": "/dev/vda", + "partitions": [ + { + "label": "scratch", + "shouldExist": true, + "wipePartitionEntry": false + }, + { + "label": "swap", + "number": 1, + "shouldExist": false, + "sizeMiB": 1024, + "wipePartitionEntry": false + } + ], + "wipeTable": true + } + ], + "filesystems": [ + { + "device": "/dev/disk/by-partlabel/scratch", + "format": "btrfs", + "path": "/scratch", + "wipeFilesystem": true + }, + { + "device": "/dev/disk/by-partlabel/swap", + "format": "swap", + "path": "swap", + "wipeFilesystem": false + } + ] + } +}`