Skip to content

Commit

Permalink
fix: generate UKI only if actually needed
Browse files Browse the repository at this point in the history
Without this fix, imager tries to generate UKI when it's not needed at
all, and also it might try to generate UKI when it's not even supported
for the version of Talos.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Jan 16, 2025
1 parent b21bdc5 commit c201476
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
21 changes: 19 additions & 2 deletions pkg/imager/imager.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,25 @@ func (i *Imager) Execute(ctx context.Context, outputPath string, report *reporte
Status: reporter.StatusSucceeded,
})

// 4. Build UKI unless the output is a kernel or cmdline.
if i.prof.Output.Kind != profile.OutKindKernel && i.prof.Output.Kind != profile.OutKindCmdline {
// 4. Build UKI if needed
needBuildUKI := quirks.New(i.prof.Version).SupportsUKI()

switch i.prof.Output.Kind {
case profile.OutKindUKI:
if !needBuildUKI {
return "", fmt.Errorf("UKI output is not supported in this Talos version")
}
case profile.OutKindISO, profile.OutKindImage, profile.OutKindInstaller:
needBuildUKI = needBuildUKI && i.prof.SecureBootEnabled()
case profile.OutKindCmdline, profile.OutKindKernel, profile.OutKindInitramfs:
needBuildUKI = false
case profile.OutKindUnknown:
fallthrough
default:
return "", fmt.Errorf("unknown output kind: %s", i.prof.Output.Kind)
}

if needBuildUKI {
if err = i.buildUKI(ctx, report); err != nil {
return "", err
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/machinery/imager/quirks/quirks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func New(talosVersion string) Quirks {
}}
}

var minVersionResetOption = semver.MustParse("1.4.0")

// Version returns the Talos version.
func (q Quirks) Version() *semver.Version {
return q.v
}

var minVersionResetOption = semver.MustParse("1.4.0")

// SupportsResetGRUBOption returns true if the Talos version supports the reset option in GRUB menu (image and ISO).
func (q Quirks) SupportsResetGRUBOption() bool {
// if the version doesn't parse, we assume it's latest Talos
Expand All @@ -44,6 +44,18 @@ func (q Quirks) SupportsResetGRUBOption() bool {
return q.v.GTE(minVersionResetOption)
}

var minVersionUKI = semver.MustParse("1.5.0")

// SupportsUKI returns true if the Talos version supports building UKIs.
func (q Quirks) SupportsUKI() bool {
// if the version doesn't parse, we assume it's latest Talos
if q.v == nil {
return true
}

return q.v.GTE(minVersionUKI)
}

var minVersionCompressedMETA = semver.MustParse("1.6.3")

// SupportsCompressedEncodedMETA returns true if the Talos version supports compressed and encoded META as an environment variable.
Expand Down

0 comments on commit c201476

Please sign in to comment.