From 6e32ea5b7f1a22500014ecb365e13af36034187a Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 10 Jan 2025 20:47:05 +0400 Subject: [PATCH] fix: merge of VolumeConfig documents with sizes Without the fix, the merge panics for `min`/`maxSize` due to missing `Merge` method. Signed-off-by: Andrey Smirnov --- pkg/machinery/config/types/block/byte_size.go | 14 ++++++++++++++ .../config/types/block/volume_config_test.go | 2 ++ 2 files changed, 16 insertions(+) diff --git a/pkg/machinery/config/types/block/byte_size.go b/pkg/machinery/config/types/block/byte_size.go index 2e0898743d..fcc5a89056 100644 --- a/pkg/machinery/config/types/block/byte_size.go +++ b/pkg/machinery/config/types/block/byte_size.go @@ -6,6 +6,7 @@ package block import ( "encoding" + "fmt" "slices" "strconv" @@ -80,3 +81,16 @@ func (bs *ByteSize) UnmarshalText(text []byte) error { func (bs ByteSize) IsZero() bool { return bs.value == nil && bs.raw == nil } + +// Merge implements merger interface. +func (bs *ByteSize) Merge(other any) error { + otherBS, ok := other.(ByteSize) + if !ok { + return fmt.Errorf("cannot merge %T with %T", bs, other) + } + + bs.raw = otherBS.raw + bs.value = otherBS.value + + return nil +} diff --git a/pkg/machinery/config/types/block/volume_config_test.go b/pkg/machinery/config/types/block/volume_config_test.go index 230696c479..98c6e2f3ef 100644 --- a/pkg/machinery/config/types/block/volume_config_test.go +++ b/pkg/machinery/config/types/block/volume_config_test.go @@ -184,10 +184,12 @@ func TestVolumeConfigMerge(t *testing.T) { c2.MetaName = constants.EphemeralPartitionLabel require.NoError(t, c2.ProvisioningSpec.DiskSelectorSpec.Match.UnmarshalText([]byte(`disk.size > 150`))) + require.NoError(t, c2.ProvisioningSpec.ProvisioningMaxSize.UnmarshalText([]byte("2.5TiB"))) require.NoError(t, merge.Merge(c1, c2)) assert.Equal(t, c1.ProvisioningSpec.DiskSelectorSpec.Match, c2.ProvisioningSpec.DiskSelectorSpec.Match) + assert.Equal(t, c1.ProvisioningSpec.ProvisioningMaxSize, c2.ProvisioningSpec.ProvisioningMaxSize) } type validationMode struct{}