Skip to content

Commit 68560b5

Browse files
committed
fix: split volume/disk locators
Don't guess based on the volume type, but use explicit fields for different locators. IMAGECACHE-ISO is a disk volume, but uses full volume locator (by filesystem type, etc.) Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent 2c3d30e commit 68560b5

File tree

8 files changed

+147
-38
lines changed

8 files changed

+147
-38
lines changed

api/resource/definitions/block/block.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ message FilesystemSpec {
113113
// LocatorSpec is the spec for volume locator.
114114
message LocatorSpec {
115115
google.api.expr.v1alpha1.CheckedExpr match = 1;
116+
google.api.expr.v1alpha1.CheckedExpr disk_match = 2;
116117
}
117118

118119
// MountRequestSpec is the spec for MountRequest.

internal/app/machined/pkg/controllers/block/internal/volumes/locate.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/siderolabs/go-blockdevice/v2/partitioning"
1515
"go.uber.org/zap"
1616

17+
taloscel "github.com/siderolabs/talos/pkg/machinery/cel"
1718
"github.com/siderolabs/talos/pkg/machinery/cel/celenv"
1819
"github.com/siderolabs/talos/pkg/machinery/resources/block"
1920
)
@@ -45,18 +46,23 @@ func LocateAndProvision(ctx context.Context, logger *zap.Logger, volumeContext M
4546

4647
// attempt to discover the volume
4748
for _, dv := range volumeContext.DiscoveredVolumes {
48-
var locator *cel.Env
49+
var (
50+
locatorEnv *cel.Env
51+
locatorMatch taloscel.Expression
52+
)
4953

5054
matchContext := map[string]any{}
5155

52-
switch volumeType { //nolint:exhaustive // we do not need to repeat exhaustive check here
53-
case block.VolumeTypeDisk:
54-
locator = celenv.DiskLocator()
55-
56-
case block.VolumeTypePartition:
57-
locator = celenv.VolumeLocator()
58-
56+
switch {
57+
case !volumeContext.Cfg.TypedSpec().Locator.Match.IsZero():
58+
locatorEnv = celenv.VolumeLocator()
5959
matchContext["volume"] = dv
60+
locatorMatch = volumeContext.Cfg.TypedSpec().Locator.Match
61+
case !volumeContext.Cfg.TypedSpec().Locator.DiskMatch.IsZero():
62+
locatorEnv = celenv.DiskLocator()
63+
locatorMatch = volumeContext.Cfg.TypedSpec().Locator.DiskMatch
64+
default:
65+
return fmt.Errorf("no locator expression set for volume")
6066
}
6167

6268
// add disk to the context, so we can use it in CEL expressions
@@ -74,7 +80,7 @@ func LocateAndProvision(ctx context.Context, logger *zap.Logger, volumeContext M
7480
}
7581
}
7682

77-
matches, err := volumeContext.Cfg.TypedSpec().Locator.Match.EvalBool(locator, matchContext)
83+
matches, err := locatorMatch.EvalBool(locatorEnv, matchContext)
7884
if err != nil {
7985
return fmt.Errorf("error evaluating volume locator: %w", err)
8086
}

internal/app/machined/pkg/controllers/block/internal/volumes/volumeconfig/user_volumes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func UserVolumeTransformer(c configconfig.Config) ([]VolumeResource, error) {
6565
case block.VolumeTypeDisk:
6666
userVolumeResource.TransformFunc = NewBuilder().
6767
WithType(block.VolumeTypeDisk).
68-
WithLocator(userVolumeConfig.Provisioning().DiskSelector().ValueOr(noMatch)).
68+
WithDiskLocator(userVolumeConfig.Provisioning().DiskSelector().ValueOr(noMatch)).
6969
WithProvisioning(block.ProvisioningSpec{
7070
Wave: block.WaveUserVolumes,
7171
DiskSelector: block.DiskSelector{

internal/app/machined/pkg/controllers/block/internal/volumes/volumeconfig/volume_config_builder.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (b *Builder) WithType(volumeType block.VolumeType) *Builder {
4444
return b
4545
}
4646

47-
// WithLocator sets VolumeConfigSpec.Locator.
47+
// WithLocator sets VolumeConfigSpec.Locator.Match.
4848
func (b *Builder) WithLocator(match cel.Expression) *Builder {
4949
b.opts = append(b.opts, func(spec *block.VolumeConfigSpec) error {
5050
spec.Locator = block.LocatorSpec{Match: match}
@@ -55,6 +55,17 @@ func (b *Builder) WithLocator(match cel.Expression) *Builder {
5555
return b
5656
}
5757

58+
// WithDiskLocator sets VolumeConfigSpec.Locator.DiskMatch.
59+
func (b *Builder) WithDiskLocator(diskMatch cel.Expression) *Builder {
60+
b.opts = append(b.opts, func(spec *block.VolumeConfigSpec) error {
61+
spec.Locator = block.LocatorSpec{DiskMatch: diskMatch}
62+
63+
return nil
64+
})
65+
66+
return b
67+
}
68+
5869
// WithProvisioning sets VolumeConfigSpec.Provisioning.
5970
func (b *Builder) WithProvisioning(provisioning block.ProvisioningSpec) *Builder {
6071
b.opts = append(b.opts, func(spec *block.VolumeConfigSpec) error {

pkg/machinery/api/resource/definitions/block/block.pb.go

Lines changed: 38 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/api/resource/definitions/block/block_vtproto.pb.go

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/resources/block/volume_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ type PartitionSpec struct {
106106
//
107107
//gotagsrewrite:gen
108108
type LocatorSpec struct {
109+
// Match is a volume locator match expression.
109110
Match cel.Expression `yaml:"match,omitempty" protobuf:"1"`
111+
// DiskMatch is a disk locator match expression.
112+
DiskMatch cel.Expression `yaml:"diskMatch,omitempty" protobuf:"2"`
110113
}
111114

112115
// FilesystemSpec is the spec for volume filesystem.

website/content/v1.12/reference/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5713,6 +5713,7 @@ LocatorSpec is the spec for volume locator.
57135713
| Field | Type | Label | Description |
57145714
| ----- | ---- | ----- | ----------- |
57155715
| match | [google.api.expr.v1alpha1.CheckedExpr](#google.api.expr.v1alpha1.CheckedExpr) | | |
5716+
| disk_match | [google.api.expr.v1alpha1.CheckedExpr](#google.api.expr.v1alpha1.CheckedExpr) | | |
57165717

57175718

57185719

0 commit comments

Comments
 (0)