Skip to content

Commit

Permalink
fix: exclude disks with empty transport for disk selector
Browse files Browse the repository at this point in the history
Fixes #10055

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Dec 27, 2024
1 parent b7a7fdc commit e915c98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
26 changes: 15 additions & 11 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,20 @@ func (i *InstallConfig) DiskMatchExpression() (*cel.Expression, error) {
exprs = append(exprs, patternMatcherExpr(selector.Modalias, "modalias"))
}

// disk.transport != "" (otherwise it might select e.g. DM devices)
exprs = append(exprs,
builder.NewCall(
builder.NextID(),
operators.NotEquals,
builder.NewSelect(
builder.NextID(),
builder.NewIdent(builder.NextID(), "disk"),
"transport",
),
builder.NewLiteral(builder.NextID(), types.String("")),
),
)

if selector.Type != "" {
switch selector.Type {
case "nvme": // disk.transport == "nvme"
Expand All @@ -1339,18 +1353,8 @@ func (i *InstallConfig) DiskMatchExpression() (*cel.Expression, error) {
builder.NewIdent(builder.NextID(), "disk"),
"rotational",
))
case "ssd": // disk.transport != "" && !disk.rotational
case "ssd": // !disk.rotational
exprs = append(exprs,
builder.NewCall(
builder.NextID(),
operators.NotEquals,
builder.NewSelect(
builder.NextID(),
builder.NewIdent(builder.NextID(), "disk"),
"transport",
),
builder.NewLiteral(builder.NextID(), types.String("")),
),
builder.NewCall(
builder.NextID(),
operators.LogicalNot,
Expand Down
9 changes: 5 additions & 4 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestInstallDiskSelector(t *testing.T) {
},
},

expected: `disk.size <= 262144u && !disk.readonly && !disk.cdrom`,
expected: `disk.size <= 262144u && disk.transport != "" && !disk.readonly && !disk.cdrom`,
},
{
name: "size and type",
Expand All @@ -49,7 +49,8 @@ func TestInstallDiskSelector(t *testing.T) {
Type: v1alpha1.InstallDiskType("nvme"),
},

expected: `disk.size == 1048576u && disk.transport == "nvme" && !disk.readonly && !disk.cdrom`,
expected: `disk.size == 1048576u && disk.transport != "" && disk.transport == "nvme" && !disk.readonly &&
!disk.cdrom`,
},
{
name: "size and type and modalias",
Expand All @@ -64,8 +65,8 @@ func TestInstallDiskSelector(t *testing.T) {
Modalias: "pci:1234:5678*",
},

expected: `disk.size == 1048576u && glob("pci:1234:5678*", disk.modalias) && disk.rotational &&
!disk.readonly && !disk.cdrom`,
expected: `disk.size == 1048576u && glob("pci:1234:5678*", disk.modalias) && disk.transport != "" &&
disk.rotational && !disk.readonly && !disk.cdrom`,
},
{
name: "ssd",
Expand Down

0 comments on commit e915c98

Please sign in to comment.