From d5b94afcb9259b93c87058ad8a8a0224da5cfd17 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 22 Jul 2025 14:40:12 +0200 Subject: [PATCH] replace bools in disk structures with wwBool --- CHANGELOG.md | 1 + internal/pkg/node/datastructure.go | 36 +++++++++++++++--------------- internal/pkg/node/storage.go | 12 +++++----- internal/pkg/wwtype/wwbool.go | 16 +++++++++++++ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2c126af..e014c0fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `DELETE /api/overlays/{name}?force=true` can delete overlays that are in use - `warewulfd` overlay autobuild rebuilds overlays after node discovery. #1468 - Improved netplan support. #1873 +- fixed boolean options for the disk related seetings ### Fixed diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index d7825e15..73397e65 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -93,7 +93,7 @@ Holds the disks of a node */ type Disk struct { id string `yaml:"-" json:"-"` - WipeTable bool `yaml:"wipe_table,omitempty" json:"wipe_table,omitempty" lopt:"diskwipe" comment:"whether or not the partition tables shall be wiped"` + WipeTable wwtype.WWbool `yaml:"wipe_table,omitempty" json:"wipe_table,omitempty" lopt:"diskwipe" comment:"whether or not the partition tables shall be wiped"` Partitions map[string]*Partition `yaml:"partitions,omitempty" json:"partitions,omitempty"` } @@ -102,29 +102,29 @@ partition definition, the label must be uniq so its used as the key in the Partitions map */ type Partition struct { - id string `yaml:"-" json:"-"` - Number string `yaml:"number,omitempty" json:"number,omitempty" lopt:"partnumber" comment:"Set the partition number, if not set next free slot is used" type:"uint"` - SizeMiB string `yaml:"size_mib,omitempty" json:"size_mib,omitempty" lopt:"partsize" comment:"Set the size of the partition, if not set maximal possible size is used" type:"uint"` - StartMiB string `yaml:"start_mib,omitempty" json:"start_mib,omitempty" comment:"the start of the partition" type:"uint"` - TypeGuid string `yaml:"type_guid,omitempty" json:"type_guid,omitempty" lopt:"parttype" comment:"Set the partition type GUID"` - Guid string `yaml:"guid,omitempty" json:"guid,omitempty" comment:"the GPT unique partition GUID"` - WipePartitionEntry bool `yaml:"wipe_partition_entry,omitempty" json:"wipe_partition_entry,omitempty" comment:"if true, Ignition will clobber an existing partition if it does not match the config"` - ShouldExist bool `yaml:"should_exist,omitempty" json:"should_exist,omitempty" lopt:"partcreate" comment:"Create partition if it does not exist"` - Resize bool `yaml:"resize,omitempty" json:"resize,omitempty" comment:"whether or not the existing partition should be resize"` + id string `yaml:"-" json:"-"` + Number string `yaml:"number,omitempty" json:"number,omitempty" lopt:"partnumber" comment:"Set the partition number, if not set next free slot is used" type:"uint"` + SizeMiB string `yaml:"size_mib,omitempty" json:"size_mib,omitempty" lopt:"partsize" comment:"Set the size of the partition, if not set maximal possible size is used" type:"uint"` + StartMiB string `yaml:"start_mib,omitempty" json:"start_mib,omitempty" comment:"the start of the partition" type:"uint"` + TypeGuid string `yaml:"type_guid,omitempty" json:"type_guid,omitempty" lopt:"parttype" comment:"Set the partition type GUID"` + Guid string `yaml:"guid,omitempty" json:"guid,omitempty" comment:"the GPT unique partition GUID"` + WipePartitionEntry wwtype.WWbool `yaml:"wipe_partition_entry,omitempty" json:"wipe_partition_entry,omitempty" comment:"if true, Ignition will clobber an existing partition if it does not match the config"` + ShouldExist wwtype.WWbool `yaml:"should_exist,omitempty" json:"should_exist,omitempty" lopt:"partcreate" comment:"Create partition if it does not exist"` + Resize wwtype.WWbool `yaml:"resize,omitempty" json:"resize,omitempty" comment:"whether or not the existing partition should be resize"` } /* Definition of a filesystem. The device is uniq so its used as key */ type FileSystem struct { - id string `yaml:"-" json:"-"` - Format string `yaml:"format,omitempty" json:"format,omitempty" lopt:"fsformat" comment:"format of the file system"` - Path string `yaml:"path,omitempty" json:"path,omitempty" lopt:"fspath" comment:"the mount point of the file system"` - WipeFileSystem bool `yaml:"wipe_filesystem,omitempty" json:"wipe_filesystem,omitempty" lopt:"fswipe" comment:"wipe file system at boot"` - Label string `yaml:"label,omitempty" json:"label,omitempty" comment:"the label of the filesystem"` - Uuid string `yaml:"uuid,omitempty" json:"uuid,omitempty" comment:"the uuid of the filesystem"` - Options []string `yaml:"options,omitempty" json:"options,omitempty" comment:"any additional options to be passed to the format-specific mkfs utility"` - MountOptions string `yaml:"mount_options,omitempty" json:"mount_options,omitempty" comment:"any special options to be passed to the mount command"` + id string `yaml:"-" json:"-"` + Format string `yaml:"format,omitempty" json:"format,omitempty" lopt:"fsformat" comment:"format of the file system"` + Path string `yaml:"path,omitempty" json:"path,omitempty" lopt:"fspath" comment:"the mount point of the file system"` + WipeFileSystem wwtype.WWbool `yaml:"wipe_filesystem,omitempty" json:"wipe_filesystem,omitempty" lopt:"fswipe" comment:"wipe file system at boot"` + Label string `yaml:"label,omitempty" json:"label,omitempty" comment:"the label of the filesystem"` + Uuid string `yaml:"uuid,omitempty" json:"uuid,omitempty" comment:"the uuid of the filesystem"` + Options []string `yaml:"options,omitempty" json:"options,omitempty" comment:"any additional options to be passed to the format-specific mkfs utility"` + MountOptions string `yaml:"mount_options,omitempty" json:"mount_options,omitempty" comment:"any special options to be passed to the mount command"` } type Resource interface{} diff --git a/internal/pkg/node/storage.go b/internal/pkg/node/storage.go index 6e1993e0..5e1eb162 100644 --- a/internal/pkg/node/storage.go +++ b/internal/pkg/node/storage.go @@ -115,7 +115,7 @@ func (node *Node) GetIgnitionStorage() (stor types_3_4.Storage, rep string, err myFs := types_3_4.Filesystem{ Device: fsdevice, Path: &fs.Path, - WipeFilesystem: &wipe, + WipeFilesystem: wipe.BoolPtr(), } if fs.Format != "" { myFs.Format = &fs.Format @@ -156,14 +156,14 @@ func (node *Node) GetIgnitionStorage() (stor types_3_4.Storage, rep string, err myPart := types_3_4.Partition{ Label: &label, Number: number, - ShouldExist: &shouldExist, - WipePartitionEntry: &wipe, + ShouldExist: shouldExist.BoolPtr(), + WipePartitionEntry: wipe.BoolPtr(), } if part.Guid != "" { myPart.GUID = &part.Guid } - if part.Resize { - myPart.Resize = &resize + if part.Resize.Bool() { + myPart.Resize = resize.BoolPtr() } if part.SizeMiB != "" { var size int @@ -202,7 +202,7 @@ func (node *Node) GetIgnitionStorage() (stor types_3_4.Storage, rep string, err disks = append(disks, types_3_4.Disk{ Device: diskDev, Partitions: partitions, - WipeTable: &wipe, + WipeTable: wipe.BoolPtr(), }) } stor = types_3_4.Storage{ diff --git a/internal/pkg/wwtype/wwbool.go b/internal/pkg/wwtype/wwbool.go index c47efbb1..63010092 100644 --- a/internal/pkg/wwtype/wwbool.go +++ b/internal/pkg/wwtype/wwbool.go @@ -33,6 +33,14 @@ func (val WWbool) Bool() bool { return bval } +/* +Return a pointer to a bool +*/ +func (val WWbool) BoolPtr() *bool { + ret := val.Bool() + return &ret +} + func (val WWbool) BoolDefaultTrue() bool { str := strings.ToLower(string(val)) if isUnsetValue(str) { @@ -89,3 +97,11 @@ var unsetValues = []string{"unset", "delete", "undef", "--", "nil", "0.0.0.0"} func isUnsetValue(value string) bool { return util.InSlice(unsetValues, strings.ToLower(value)) } + +/* +Parse a string to a WWBool +*/ +func Parse(in string) (ret WWbool) { + ret.Set(in) + return +}