Skip to content

Commit

Permalink
feat: refactor platform metadata
Browse files Browse the repository at this point in the history
Updates the wizard to be more correct, handle SecureBoot for !metal
choice, etc.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Jan 20, 2025
1 parent 4bb43ef commit ffad511
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 152 deletions.
120 changes: 61 additions & 59 deletions internal/frontend/http/templates/wizard-final.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,10 @@ <h2>First Boot</h2>
<p>Use the following disk image for {{ .BoardMeta.Label }}:</p>
{{ end }}
<dl>
{{ if eq .Target "metal" }}
{{ if eq .SecureBoot "true" }}
{{ template "secureboot-iso" . }}
{{ template "secureboot-metal-image" . }}
{{ else }}
{{ template "iso" . }}
{{ template "metal-image" . }}
{{ template "pxe-boot" . }}
{{ end }}
{{ else if eq .Target "cloud" }}
{{ if or (eq .Target "metal") (eq .Target "cloud") }}
{{ range .PlatformMeta.BootMethods }}
{{ if eq . "disk-image" }}
{{ template "cloud-image" $ }}
{{ template "disk-image" $ }}
{{ else if eq . "iso" }}
{{ template "iso" $ }}
{{ else if eq . "pxe" }}
Expand Down Expand Up @@ -100,64 +91,75 @@ <h2>Extra Assets</h2>
{{ end }}

{{ define "iso" }}
<dt>ISO</dt>
<dd><a href="{{ printf "%s-%s.iso" .Platform .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "%s-%s.iso" .Platform .Arch | $.ImageBaseURL.JoinPath }}</a>
{{ if eq .SecureBoot "true" }}
<dt>SecureBoot ISO</dt>
<dd><a href="{{ .PlatformMeta.SecureBootISOPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.SecureBootISOPath .Arch | $.ImageBaseURL.JoinPath }}</a>
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/secureboot/" target="_blank">SecureBoot documentation</a>)
</dd>
{{ else}}
<dt>ISO</dt>
<dd><a href="{{ .PlatformMeta.ISOPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.ISOPath .Arch | $.ImageBaseURL.JoinPath }}</a>

{{ if eq .Target "metal" }}
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/iso/" target="_blank">ISO documentation</a>)
{{ if eq .Target "metal" }}
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/iso/" target="_blank">ISO documentation</a>)
{{ end }}
</dd>
{{ end }}
</dd>
{{ end }}

{{ define "secureboot-iso" }}
<dt>SecureBoot ISO</dt>
<dd><a href="{{ printf "%s-%s-secureboot.iso" .Platform .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "%s-%s-secureboot.iso" .Platform .Arch | $.ImageBaseURL.JoinPath }}</a>
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/secureboot/" target="_blank">SecureBoot documentation</a>)
</dd>
{{ define "disk-image" }}
{{ if eq .SecureBoot "true" }}
<dt>SecureBoot Disk Image</dt>
<dd><a href="{{ .PlatformMeta.SecureBootDiskImageDefaultPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.SecureBootDiskImageDefaultPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
{{ if eq .Target "metal" }}
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/secureboot/" target="_blank">SecureBoot documentation</a>)
{{ end }}
</dd>
{{ else }}
{{ if eq .Target "metal" }}
<dt>Disk Image (raw)</dt>
<dd><a href="{{ .PlatformMeta.DiskImageDefaultPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.DiskImageDefaultPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
<dt>Disk Image (qcow2)</dt>
<dd><a href="{{ .PlatformMeta.DiskImagePath .Arch "qcow2" | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.DiskImagePath .Arch "qcow2" |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ else }}
<dt>Disk Image</dt>
<dd><a href="{{ .PlatformMeta.DiskImageDefaultPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.DiskImageDefaultPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ end }}
{{ end}}
{{ end }}

{{ define "metal-image" }}
<dt>Disk Image (raw)</dt>
<dd><a href="{{ printf "metal-%s.raw.zst" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "metal-%s.raw.zst" .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
<dt>Disk Image (qcow2)</dt>
<dd><a href="{{ printf "metal-%s.qcow2" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "metal-%s.qcow2" .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ end }}
{{ define "pxe-boot" }}
{{ if eq .SecureBoot "true" }}
<dt>SecureBoot PXE (iPXE script)</dt>
<dd>{{ .PlatformMeta.SecureBootPXEScriptPath .Arch | $.PXEBaseURL.JoinPath }}</dd>

{{ define "cloud-image" }}
<dt>Disk Image</dt>
<dd><a href="{{ printf "%s-%s.%s" .Platform .Arch .PlatformMeta.DiskImageSuffix | $.ImageBaseURL.JoinPath }}">{{ printf "%s-%s.%s" .Platform .Arch .PlatformMeta.DiskImageSuffix |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ if eq .Target "metal" }}
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/pxe/" target="_blank">PXE documentation</a>)
{{ end }}
{{ else }}
<dt>PXE boot (iPXE script)</dt>
<dd>{{ .PlatformMeta.PXEScriptPath .Arch | $.PXEBaseURL.JoinPath }}</dd>

{{ if eq .Target "metal" }}
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/pxe/" target="_blank">PXE documentation</a>)
{{ end }}
{{ end }}
{{ end }}

{{ define "board-image" }}
<dt>Disk Image</dt>
<dd><a href="{{ printf "metal%s-arm64.raw.xz" .LegacyBoard | $.ImageBaseURL.JoinPath }}">{{ printf "metal%s-arm64.raw.xz" .LegacyBoard |
<dd><a href="{{ .BoardMeta.DiskImagePath .Version | $.ImageBaseURL.JoinPath }}">{{ .BoardMeta.DiskImagePath .Version |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ end }}

{{ define "secureboot-metal-image" }}
<dt>SecureBoot Disk Image</dt>
<dd><a href="{{ printf "metal-%s-secureboot.raw.zst" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "metal-%s-secureboot.raw.zst" .Arch |
$.ImageBaseURL.JoinPath }}</a>
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/secureboot/" target="_blank">SecureBoot documentation</a>)
</dd>
{{ end }}

{{ define "pxe-boot" }}
<dt>PXE boot (iPXE script)</dt>
<dd>{{ printf "%s-%s" .Platform .Arch | $.PXEBaseURL.JoinPath }}</dd>

{{ if eq .Target "metal" }}
(<a href="https://www.talos.dev/{{ short_version .Version }}/talos-guides/install/bare-metal-platforms/pxe/" target="_blank">PXE documentation</a>)
{{ end }}
{{ end }}

{{ define "installer-image" }}
<span class="font-mono bg-slate-200 dark:bg-slate-700 p-1">
{{ if eq .SecureBoot "true"}}
Expand All @@ -170,26 +172,26 @@ <h2>Extra Assets</h2>

{{ define "extra-assets" }}
<dt>Kernel Image</dt>
<dd><a href="{{ printf "kernel-%s" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "kernel-%s" .Arch |
<dd><a href="{{ .PlatformMeta.KernelPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.KernelPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
<dt>Kernel Command Line</dt>
<dd><a href="{{ printf "cmdline-metal-%s" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "cmdline-metal-%s" .Arch |
<dd><a href="{{ .PlatformMeta.CmdlinePath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.CmdlinePath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
<dt>Initramfs Image</dt>
<dd><a href="{{ printf "initramfs-%s.xz" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "initramfs-%s.xz" .Arch |
<dd><a href="{{ .PlatformMeta.InitramfsPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.InitramfsPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
<dt>UKI</dt>
<dd><a href="{{ printf "metal-%s-uki.efi" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "metal-%s-uki.efi" .Arch |
<dd><a href="{{ .PlatformMeta.UKIPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.UKIPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ end }}

{{ define "secureboot-extra-assets" }}
<dt>SecureBoot UKI</dt>
<dd><a href="{{ printf "metal-%s-secureboot-uki.efi" .Arch | $.ImageBaseURL.JoinPath }}">{{ printf "metal-%s-secureboot-uki.efi" .Arch |
<dd><a href="{{ .PlatformMeta.SecureBootUKIPath .Arch | $.ImageBaseURL.JoinPath }}">{{ .PlatformMeta.SecureBootUKIPath .Arch |
$.ImageBaseURL.JoinPath }}</a>
</dd>
{{ end }}
Expand Down
36 changes: 14 additions & 22 deletions internal/frontend/http/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func WizardParamsFromRequest(r *http.Request) WizardParams {
switch {
case params.Target == TargetMetal:
params.Platform = constants.PlatformMetal
params.PlatformMeta = metadata.MetalPlatform()
case params.Target == TargetSBC:
params.Platform = constants.PlatformMetal

Expand All @@ -185,17 +186,17 @@ func WizardParamsFromRequest(r *http.Request) WizardParams {
}
}
case params.Target == TargetCloud && params.Platform != "":
if idx := slices.IndexFunc(metadata.Platforms(), func(p metadata.Platform) bool {
if idx := slices.IndexFunc(metadata.CloudPlatforms(), func(p metadata.Platform) bool {
return p.Name == params.Platform
}); idx != -1 {
params.PlatformMeta = metadata.Platforms()[idx]
params.PlatformMeta = metadata.CloudPlatforms()[idx]

if len(params.PlatformMeta.Architectures) == 1 && params.Arch == "" {
if params.SelectedArch != "" {
// going back, reset platform choice
params.SelectedPlatform, params.Platform = params.Platform, ""
} else {
params.Arch = string(params.PlatformMeta.Architectures[0])
params.Arch = params.PlatformMeta.Architectures[0]
}
}
}
Expand Down Expand Up @@ -282,7 +283,7 @@ func (f *Frontend) wizardClouds(_ context.Context, params WizardParams) (string,

talosVersion, _ := semver.ParseTolerant(params.Version) //nolint:errcheck

allPlatforms := metadata.Platforms()
allPlatforms := metadata.CloudPlatforms()

allPlatforms = xslices.Filter(allPlatforms, func(p metadata.Platform) bool {
if value.IsZero(&p.MinVersion) {
Expand Down Expand Up @@ -406,26 +407,19 @@ func (f *Frontend) wizardFinal(ctx context.Context, params WizardParams) (string

slices.Sort(extensions)

var (
overlay schematic.Overlay
legacyBoard string
)
var overlay schematic.Overlay

if params.Target == TargetSBC {
if quirks.New(params.Version).SupportsOverlay() {
overlay.Name = params.BoardMeta.OverlayName
overlay.Image = params.BoardMeta.OverlayImage
if params.Target == TargetSBC && quirks.New(params.Version).SupportsOverlay() {
overlay.Name = params.BoardMeta.OverlayName
overlay.Image = params.BoardMeta.OverlayImage

var overlayOptsParsed map[string]any

if err := yaml.Unmarshal([]byte(params.OverlayOptions), &overlayOptsParsed); err != nil {
return "", nil, nil, fmt.Errorf("error parsing overlay options: %w", err)
}
var overlayOptsParsed map[string]any

overlay.Options = overlayOptsParsed
} else {
legacyBoard = "-" + params.BoardMeta.BoardName
if err := yaml.Unmarshal([]byte(params.OverlayOptions), &overlayOptsParsed); err != nil {
return "", nil, nil, fmt.Errorf("error parsing overlay options: %w", err)
}

overlay.Options = overlayOptsParsed
}

requestedSchematic := schematic.Schematic{
Expand Down Expand Up @@ -464,7 +458,6 @@ func (f *Frontend) wizardFinal(ctx context.Context, params WizardParams) (string

TroubleshootingGuideAvailable bool
ProductionGuideAvailable bool
LegacyBoard string
}{
WizardParams: params,

Expand All @@ -479,7 +472,6 @@ func (f *Frontend) wizardFinal(ctx context.Context, params WizardParams) (string

TroubleshootingGuideAvailable: talosVersion.GTE(semver.MustParse("1.6.0")),
ProductionGuideAvailable: talosVersion.GTE(semver.MustParse("1.5.0")),
LegacyBoard: legacyBoard,
},
params.URLValues(),
nil
Expand Down
Loading

0 comments on commit ffad511

Please sign in to comment.