Skip to content

Commit

Permalink
chore: handle renamed drm extensions
Browse files Browse the repository at this point in the history
Handle renamed drm extensions.

Fixes: siderolabs/talos#9728

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed Dec 10, 2024
1 parent 6f3ce0d commit 24ebc00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
21 changes: 19 additions & 2 deletions internal/backend/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const OfficialPrefix = "siderolabs/"
var (
talosV170 = semver.MustParse("1.7.0")
talosV180 = semver.MustParse("1.8.0")
talosV190 = semver.MustParse("1.9.0")

talosV17RenamedExtensions = newBiMap[string, string](map[string]string{
OfficialPrefix + "xe-guest-utilities": OfficialPrefix + "xen-guest-agent",
Expand All @@ -29,6 +30,11 @@ var (
OfficialPrefix + "nonfree-kmod-nvidia": OfficialPrefix + "nonfree-kmod-nvidia-lts",
OfficialPrefix + "nvidia-fabricmanager": OfficialPrefix + "nvidia-fabric-manager-lts",
})

talosV19RenamedExtensions = newBiMap[string, string](map[string]string{
OfficialPrefix + "i915-ucode": OfficialPrefix + "i915",
OfficialPrefix + "amdgpu-firmware": OfficialPrefix + "amdgpu",
})
)

// MapNames maps the extension names to their correct final names, taking extensions with the wrong name in their manifests into account.
Expand Down Expand Up @@ -60,14 +66,15 @@ func MapNamesByVersion(extensions []string, talosVersion semver.Version) []strin

gte170 := talosVersion.GTE(talosV170)
gte180 := talosVersion.GTE(talosV180)
gte190 := talosVersion.GTE(talosV190)

return xslices.Map(extensions, func(extension string) string {
return mapSingleNameByVersion(extension, gte170, gte180)
return mapSingleNameByVersion(extension, gte170, gte180, gte190)
})
}

// mapSingleNameByVersion returns the renamed extension based on the talos version.
func mapSingleNameByVersion(extension string, gte170, gte180 bool) string {
func mapSingleNameByVersion(extension string, gte170, gte180, get190 bool) string {
if gte170 {
if name, ok := talosV17RenamedExtensions.Get(extension); ok {
return name
Expand All @@ -88,6 +95,16 @@ func mapSingleNameByVersion(extension string, gte170, gte180 bool) string {
}
}

if get190 {
if name, ok := talosV19RenamedExtensions.Get(extension); ok {
return name
}
} else {
if name, ok := talosV19RenamedExtensions.GetInverse(extension); ok {
return name
}
}

return extension
}

Expand Down
14 changes: 14 additions & 0 deletions internal/backend/extensions/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,18 @@ func TestMap(t *testing.T) {
"siderolabs/xen-guest-agent", // kept as-is because not in the renamed list
}, mapped)
})

t.Run("talos-v1.8", func(t *testing.T) {
exts := []string{
"siderolabs/i915-ucode",
"siderolabs/amdgpu-firmware",
}

mapped := extensions.MapNamesByVersion(exts, semver.MustParse("1.9.0"))

require.Equal(t, []string{
"siderolabs/i915", // mapped to the new name
"siderolabs/amdgpu", // mapped to the new name
}, mapped)
})
}

0 comments on commit 24ebc00

Please sign in to comment.