Skip to content

Commit

Permalink
fix: merge of VolumeConfig documents with sizes
Browse files Browse the repository at this point in the history
Without the fix, the merge panics for `min`/`maxSize` due to missing
`Merge` method.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Jan 10, 2025
1 parent 1be5f8f commit 6e32ea5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/machinery/config/types/block/byte_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package block

import (
"encoding"
"fmt"
"slices"
"strconv"

Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions pkg/machinery/config/types/block/volume_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 6e32ea5

Please sign in to comment.