Skip to content

Commit

Permalink
fix: workaround extension name inconsistencies
Browse files Browse the repository at this point in the history
Some extensions have names in the manifest which are different from the
container image names. This was fixed, but old Talos installs will still
report wrong names.

Add a workaround to support name aliases for the known "bad" names.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed May 8, 2024
1 parent f5bc497 commit 116721a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
38 changes: 32 additions & 6 deletions internal/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,33 @@ type ArtifactProducer interface {
GetInstallerImage(context.Context, artifacts.Arch, string) (string, error)
}

func findExtension(availableExtensions []artifacts.ExtensionRef, extensionName string) artifacts.ExtensionRef {
for _, availableExtension := range availableExtensions {
if availableExtension.TaggedReference.RepositoryStr() == extensionName {
return availableExtension
}
}

return artifacts.ExtensionRef{}
}

func extensionNameAlias(extensionName string) (string, bool) {
switch extensionName {
case "siderolabs/v4l-uvc": // wrong name in the extension manifest
return "siderolabs/v4l-uvc-drivers", true
case "siderolabs/usb-modem": // wrong name in the extension manifest
return "siderolabs/usb-modem-drivers", true
case "siderolabs/gasket": // wrong name in the extension manifest
return "siderolabs/gasket-driver", true
case "siderolabs/talos-vmtoolsd": // wrong name in the extension manifest
return "siderolabs/vmtoolsd-guest-agent", true
case "siderolabs/xe-guest-utilities": // extension got renamed
return "siderolabs/xen-guest-agent", true
default:
return "", false
}
}

// EnhanceFromSchematic enhances the profile with the schematic.
//
//nolint:gocognit,gocyclo,cyclop
Expand Down Expand Up @@ -301,13 +328,12 @@ func EnhanceFromSchematic(
}

for _, extensionName := range schematic.Customization.SystemExtensions.OfficialExtensions {
var extensionRef artifacts.ExtensionRef
extensionRef := findExtension(availableExtensions, extensionName)

for _, availableExtension := range availableExtensions {
if availableExtension.TaggedReference.RepositoryStr() == extensionName {
extensionRef = availableExtension

break
if value.IsZero(extensionRef) {
// try with aliases if not found
if aliasedName, ok := extensionNameAlias(extensionName); ok {
extensionRef = findExtension(availableExtensions, aliasedName)
}
}

Expand Down
48 changes: 48 additions & 0 deletions internal/profile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ func (mockArtifactProducer) GetOfficialExtensions(context.Context, string) ([]ar
TaggedReference: ensure.Value(name.NewTag("ghcr.io/siderolabs/intel-ucode:20210608")),
Digest: "sha256:0987654321",
},
{
TaggedReference: ensure.Value(name.NewTag("ghcr.io/siderolabs/gasket-driver:20240101")),
Digest: "sha256:abcdef123456",
},
}, nil
}

Expand Down Expand Up @@ -478,6 +482,50 @@ func TestEnhanceFromSchematic(t *testing.T) {
},
},
},
{
name: "aliased extensions",
baseProfile: baseProfile,
schematic: schematic.Schematic{
Customization: schematic.Customization{
SystemExtensions: schematic.SystemExtensions{
OfficialExtensions: []string{
"siderolabs/amd-ucode",
"siderolabs/gasket",
},
},
},
},
versionString: "v1.5.1",

expectedProfile: profile.Profile{
Platform: constants.PlatformMetal,
SecureBoot: pointer.To(false),
Arch: "amd64",
Version: "v1.5.1",
Customization: profile.CustomizationProfile{},
Input: profile.Input{
SystemExtensions: []profile.ContainerAsset{
{
OCIPath: "amd64-sha256:1234567890.oci",
},
{
OCIPath: "amd64-sha256:abcdef123456.oci",
},
{
TarballPath: "dcf69eb36d2c699ce3050ef2f59fd6f70a6f2d0bf9d34585971aae4991360c89.tar",
},
},
},
Output: profile.Output{
Kind: profile.OutKindImage,
OutFormat: profile.OutFormatZSTD,
ImageOptions: &profile.ImageOptions{
DiskSize: profile.MinRAWDiskSize,
DiskFormat: profile.DiskFormatRaw,
},
},
},
},
{
name: "installer with extensions",
baseProfile: installerProfile,
Expand Down

0 comments on commit 116721a

Please sign in to comment.