Skip to content

Commit

Permalink
fix: make system_disk condition work properly before install
Browse files Browse the repository at this point in the history
The problem was with specific disk selector `!system_disk` - in previous
implementation, as `system_disk` defaulted to false even if the system
disk is not known yet, this might result in picking up a disk which is
going to be system disk before system disk is picked.

In new implementation, as `system_disk` is not set before it is
detected, the condition containing `system_disk` (in either way) would
fail to execute and volume provision will be delayed until system disk
is detected.

Also:

Fixes #9809

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Nov 27, 2024
1 parent af91c99 commit bef4d51
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var imageListCmd = &cobra.Command{

// imagePullCmd represents the image pull command.
var imagePullCmd = &cobra.Command{
Use: "pull",
Use: "pull <image>",
Aliases: []string{"p"},
Short: "Pull an image into CRI",
Long: ``,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ func LocateAndProvision(ctx context.Context, logger *zap.Logger, volumeContext M
continue
}

matches, err := volumeContext.Cfg.TypedSpec().Provisioning.DiskSelector.Match.EvalBool(celenv.DiskLocator(), map[string]any{
"disk": diskCtx.Disk,
"system_disk": diskCtx.SystemDisk,
})
matches, err := volumeContext.Cfg.TypedSpec().Provisioning.DiskSelector.Match.EvalBool(celenv.DiskLocator(), diskCtx.ToCELContext())
if err != nil {
return fmt.Errorf("error evaluating disk locator: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package volumes
import (
"cmp"

"github.com/siderolabs/gen/optional"

blockpb "github.com/siderolabs/talos/pkg/machinery/api/resource/definitions/block"
"github.com/siderolabs/talos/pkg/machinery/resources/block"
"github.com/siderolabs/talos/pkg/machinery/resources/hardware"
Expand Down Expand Up @@ -40,7 +42,20 @@ type Retryable struct{}
// DiskContext captures the context of a disk.
type DiskContext struct {
Disk *blockpb.DiskSpec
SystemDisk bool
SystemDisk optional.Optional[bool]
}

// ToCELContext converts the disk context to CEL contexts.
func (d *DiskContext) ToCELContext() map[string]any {
result := map[string]any{
"disk": d.Disk,
}

if val, ok := d.SystemDisk.Get(); ok {
result["system_disk"] = val
}

return result
}

// ManagerContext captures the context of the volume manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,15 @@ func (ctrl *VolumeManagerController) Run(ctx context.Context, r controller.Runti
return volumes.DiskContext{}, err
}

var optionalSystemDisk optional.Optional[bool]

if systemDisk != nil {
optionalSystemDisk = optional.Some(d.Metadata().ID() == systemDisk.TypedSpec().DiskID)
}

return volumes.DiskContext{
Disk: spec,
SystemDisk: systemDisk != nil && d.Metadata().ID() == systemDisk.TypedSpec().DiskID,
SystemDisk: optionalSystemDisk,
}, nil
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion website/content/v1.9/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ talosctl image list [flags]
Pull an image into CRI

```
talosctl image pull [flags]
talosctl image pull <image> [flags]
```

### Options
Expand Down

0 comments on commit bef4d51

Please sign in to comment.