fcos: skip ErrReuseByLabel warning for boot_device.mirror disks#711
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the configuration validation logic for FCOS (versions v1_6, v1_7, and v1_8_exp) to skip the reuse-by-label check for boot mirror devices, and adds corresponding unit tests. The reviewer suggests optimizing the map allocation for mirrorDevices across all three versions. Specifically, since reading from a nil map is safe in Go, map allocation can be avoided entirely when there are no mirror devices, and the map can be pre-allocated with the exact capacity when mirror devices are present.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| mirrorDevices := make(map[string]bool) | ||
| for _, dev := range conf.BootDevice.Mirror.Devices { | ||
| mirrorDevices[dev] = true | ||
| } |
There was a problem hiding this comment.
We can optimize this by avoiding map allocation entirely when there are no mirror devices (which is the most common case). In Go, reading from a nil map is safe and returns the zero value (false for bool), so the lookup !mirrorDevices[disk.Device] will still work perfectly without any changes.
Additionally, if there are mirror devices, we can pre-allocate the map with the exact capacity to avoid map resizing overhead.
var mirrorDevices map[string]bool
if len(conf.BootDevice.Mirror.Devices) > 0 {
mirrorDevices = make(map[string]bool, len(conf.BootDevice.Mirror.Devices))
for _, dev := range conf.BootDevice.Mirror.Devices {
mirrorDevices[dev] = true
}
}| mirrorDevices := make(map[string]bool) | ||
| for _, dev := range conf.BootDevice.Mirror.Devices { | ||
| mirrorDevices[dev] = true | ||
| } |
There was a problem hiding this comment.
We can optimize this by avoiding map allocation entirely when there are no mirror devices (which is the most common case). In Go, reading from a nil map is safe and returns the zero value (false for bool), so the lookup !mirrorDevices[disk.Device] will still work perfectly without any changes.
Additionally, if there are mirror devices, we can pre-allocate the map with the exact capacity to avoid map resizing overhead.
var mirrorDevices map[string]bool
if len(conf.BootDevice.Mirror.Devices) > 0 {
mirrorDevices = make(map[string]bool, len(conf.BootDevice.Mirror.Devices))
for _, dev := range conf.BootDevice.Mirror.Devices {
mirrorDevices[dev] = true
}
}| mirrorDevices := make(map[string]bool) | ||
| for _, dev := range conf.BootDevice.Mirror.Devices { | ||
| mirrorDevices[dev] = true | ||
| } |
There was a problem hiding this comment.
We can optimize this by avoiding map allocation entirely when there are no mirror devices (which is the most common case). In Go, reading from a nil map is safe and returns the zero value (false for bool), so the lookup !mirrorDevices[disk.Device] will still work perfectly without any changes.
Additionally, if there are mirror devices, we can pre-allocate the map with the exact capacity to avoid map resizing overhead.
var mirrorDevices map[string]bool
if len(conf.BootDevice.Mirror.Devices) > 0 {
mirrorDevices = make(map[string]bool, len(conf.BootDevice.Mirror.Devices))
for _, dev := range conf.BootDevice.Mirror.Devices {
mirrorDevices[dev] = true
}
}Config.Validate() warns when a partition on a non-boot disk uses a label without an explicit number and wipe_table is not set. However, when the disk is listed in boot_device.mirror.devices, this warning is a false positive: processBootDevice() in translate.go will auto- generate wipe_table: true for mirror disks, but Validate() runs before translation so it doesn't see the auto-generated wipe_table. The user can't reasonably suppress this: adding explicit wipe_table: true is redundant, and adding explicit partition number fields would break the label-based merge with the auto-generated mirror partitions. Skip the ErrReuseByLabel check for disks that are listed in boot_device.mirror.devices. Fixes: coreos#710 Assisted-by: <anthropic/claude-opus-4.6>
9d38eed to
ca25c01
Compare
|
This fixes one of the two cases. The second one is: |
@travier I think that one is a different problem. In that case we should probably set the partition number. This is what AI says (see below). It actually recommends setting The second warning is a different case from the storage:
disks:
- device: /dev/vdb
wipe_table: false
partitions:
- size_mib: 0
start_mib: 0
label: logHere Unlike the mirror case, I think this is a legitimate warning and it's the Two possible docs fixes:
That said, there is a possible butane improvement here too: when a I'd recommend option 1 (change |
Fixes: ``` Invalid Butane config at ./modules/ROOT/pages/storage.adoc:92: warning at $.storage.disks.0.partitions.0.number, line 8 col 7: partitions cannot be reused by label; number must be specified except on boot disk (/dev/disk/by-id/coreos-boot-disk) or when wipe_table is true Config produced warnings and --strict was specified ``` See: coreos/butane#711
|
Sounds good indeed. I fixed that in the docs PR. |
|
Gemini's suggestions looks OK to me. It should not matter but it does not make the code harder to read or understand. |
To me it makes it a little harder to read/understand. Since performance/memory use isn't really a concern here I'd prefer to leave it unless you think it is much better. |
|
Works for me. |
Fixes: ``` Invalid Butane config at ./modules/ROOT/pages/storage.adoc:92: warning at $.storage.disks.0.partitions.0.number, line 8 col 7: partitions cannot be reused by label; number must be specified except on boot disk (/dev/disk/by-id/coreos-boot-disk) or when wipe_table is true Config produced warnings and --strict was specified ``` See: coreos/butane#711 (comment)
Fixes: ``` Invalid Butane config at ./modules/ROOT/pages/storage.adoc:92: warning at $.storage.disks.0.partitions.0.number, line 8 col 7: partitions cannot be reused by label; number must be specified except on boot disk (/dev/disk/by-id/coreos-boot-disk) or when wipe_table is true Config produced warnings and --strict was specified ``` See: coreos/butane#711 (comment)
Config.Validate() warns when a partition on a non-boot disk uses a label without an explicit number and wipe_table is not set. However, when the disk is listed in boot_device.mirror.devices, this warning is a false positive: processBootDevice() in translate.go will auto- generate wipe_table: true for mirror disks, but Validate() runs before translation so it doesn't see the auto-generated wipe_table.
The user can't reasonably suppress this: adding explicit wipe_table: true is redundant, and adding explicit partition number fields would break the label-based merge with the auto-generated mirror partitions.
Skip the ErrReuseByLabel check for disks that are listed in boot_device.mirror.devices.
Fixes: #710
Assisted-by: <anthropic/claude-opus-4.6>