-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: order volume config by the requested size
This fixes an issue like that: * the system disk is say 10GiB * STATE is fixed 100 MiB always * EPHEMERAL is configured to be min 6 GiB, max 100 GiB As the EPHEMERAL/STATE provisioning order was not defined, EPHEMERAL might be created first, occupying whole disk and leaving no space left for STATE. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
- Loading branch information
Showing
6 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1alpha1 | ||
kind: VolumeConfig | ||
name: EPHEMERAL | ||
provisioning: | ||
diskSelector: | ||
match: system_disk | ||
minSize: 4GB | ||
maxSize: 100GB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
internal/app/machined/pkg/controllers/block/internal/volumes/volumes_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package volumes_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/block/internal/volumes" | ||
"github.com/siderolabs/talos/pkg/machinery/resources/block" | ||
) | ||
|
||
func TestCompareVolumeConfigs(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, test := range []struct { | ||
name string | ||
|
||
a *block.VolumeConfigSpec | ||
b *block.VolumeConfigSpec | ||
|
||
expected int | ||
}{ | ||
{ | ||
name: "different wave", | ||
|
||
a: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
}, | ||
}, | ||
b: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveUserDisks, | ||
}, | ||
}, | ||
|
||
expected: -1, | ||
}, | ||
{ | ||
name: "prefer grow", | ||
|
||
a: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
PartitionSpec: block.PartitionSpec{ | ||
Grow: true, | ||
}, | ||
}, | ||
}, | ||
b: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
PartitionSpec: block.PartitionSpec{ | ||
Grow: false, | ||
}, | ||
}, | ||
}, | ||
|
||
expected: 1, | ||
}, | ||
{ | ||
name: "prefer smaller size", | ||
|
||
a: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
PartitionSpec: block.PartitionSpec{ | ||
Grow: false, | ||
MinSize: 100, | ||
MaxSize: 200, | ||
}, | ||
}, | ||
}, | ||
b: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
PartitionSpec: block.PartitionSpec{ | ||
Grow: false, | ||
MinSize: 150, | ||
MaxSize: 1000, | ||
}, | ||
}, | ||
}, | ||
|
||
expected: -1, | ||
}, | ||
{ | ||
name: "prefer max size", | ||
|
||
a: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
PartitionSpec: block.PartitionSpec{ | ||
Grow: false, | ||
MinSize: 100, | ||
MaxSize: 200, | ||
}, | ||
}, | ||
}, | ||
b: &block.VolumeConfigSpec{ | ||
Provisioning: block.ProvisioningSpec{ | ||
Wave: block.WaveSystemDisk, | ||
PartitionSpec: block.PartitionSpec{ | ||
Grow: false, | ||
MinSize: 50, | ||
MaxSize: 0, // no limit | ||
}, | ||
}, | ||
}, | ||
|
||
expected: -1, | ||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
resA := block.NewVolumeConfig(block.NamespaceName, "A") | ||
*resA.TypedSpec() = *test.a | ||
|
||
resB := block.NewVolumeConfig(block.NamespaceName, "B") | ||
*resB.TypedSpec() = *test.b | ||
|
||
actual := volumes.CompareVolumeConfigs(resA, resB) | ||
|
||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} |