Skip to content

Commit afb350b

Browse files
committed
Remove arch aliases from image-derived instance names
When the image arch matches the native arch, remove all arch keyword aliases (e.g. arm64, amd64) in addition to the canonical arch name (e.g. aarch64, x86_64). Previously only the canonical name was removed, leaving aliases like arm64 in the instance name. For example, on an aarch64 host: FreeBSD-15.0-RELEASE-arm64-aarch64-BASIC-CLOUDINIT-zfs.raw.xz Before: freebsd-15.0-arm64-zfs After: freebsd-15.0-zfs Signed-off-by: Mysterio-17 <mradultiwari1708@gmail.com>
1 parent 256407c commit afb350b

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

pkg/limatmpl/locator.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,14 @@ func InstNameFromImageURL(locator, imageArch string) string {
253253
// ARM64 FreeBSD images have both "arm64" and "aarch64" in their names.
254254
// "FreeBSD-16.0-CURRENT-arm64-aarch64-BASIC-CLOUDINIT-ufs.qcow2.xz"
255255
name = strings.Replace(name, "arm64-aarch64", "arm64", 1)
256-
// Remove imageArch as well if it is the native arch.
256+
// Remove imageArch and all its aliases if it is the native arch.
257257
if limatype.IsNativeArch(imageArch) {
258-
re := regexp.MustCompile(fmt.Sprintf(`[-_.]%s\b`, imageArch))
259-
name = re.ReplaceAllString(name, "")
258+
for keyword, arch := range archKeywords {
259+
if arch == imageArch {
260+
re := regexp.MustCompile(fmt.Sprintf(`[-_.]%s\b`, keyword))
261+
name = re.ReplaceAllString(name, "")
262+
}
263+
}
260264
}
261265
// Remove timestamps from name: 8 digit date, optionally followed by
262266
// a delimiter and one or more digits before a word boundary.

pkg/limatmpl/locator_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ func TestInstNameFromImageURL(t *testing.T) {
5353
name := limatmpl.InstNameFromImageURL(image, arch)
5454
assert.Equal(t, name, "linux")
5555
})
56+
t.Run("removes native arch aliases", func(t *testing.T) {
57+
arch := limatype.NewArch(runtime.GOARCH)
58+
alias := runtime.GOARCH
59+
if arch == alias {
60+
t.Skip("no alias for native arch")
61+
}
62+
image := fmt.Sprintf("linux-%s.raw", alias)
63+
name := limatmpl.InstNameFromImageURL(image, arch)
64+
assert.Equal(t, name, "linux")
65+
})
5666
t.Run("removes redundant major version", func(t *testing.T) {
5767
name := limatmpl.InstNameFromImageURL("rocky-8-8.10.raw", "unknown")
5868
assert.Equal(t, name, "rocky-8.10")
@@ -144,61 +154,51 @@ func TestRead(t *testing.T) {
144154
tests := []struct {
145155
name string
146156
locator string
147-
expectedName string
148157
expectedOS limatype.OS
149158
expectedArch limatype.Arch
150159
}{
151160
{
152161
locator: "http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/VM-IMAGES/15.0-RELEASE/amd64/Latest/FreeBSD-15.0-RELEASE-amd64-BASIC-CLOUDINIT-zfs.raw.xz",
153-
expectedName: "freebsd-15.0-amd64-zfs",
154162
expectedOS: limatype.FREEBSD,
155163
expectedArch: limatype.X8664,
156164
},
157165
{
158166
locator: "https://download.freebsd.org/ftp/snapshots/VM-IMAGES/16.0-CURRENT/aarch64/Latest/FreeBSD-16.0-CURRENT-arm64-aarch64-BASIC-CLOUDINIT-ufs.qcow2.xz",
159-
expectedName: "freebsd-16.0-arm64-ufs",
160167
expectedOS: limatype.FREEBSD,
161168
expectedArch: limatype.AARCH64,
162169
},
163170
{
164171
locator: "https://updates.cdn-apple.com/2025SummerFCS/fullrestores/093-10809/CFD6DD38-DAF0-40DA-854F-31AAD1294C6F/UniversalMac_15.6.1_24G90_Restore.ipsw",
165-
expectedName: "macos-15.6.1",
166172
expectedOS: limatype.DARWIN,
167173
expectedArch: limatype.AARCH64,
168174
},
169175
{
170176
locator: "https://updates.cdn-apple.com/2026WinterFCS/fullrestores/047-60229/6D5DBEA5-75A0-4BEF-ACC9-5ACF9B8DF6B7/UniversalMac_26.3_25D125_Restore.ipsw",
171-
expectedName: "macos-26.3",
172177
expectedOS: limatype.DARWIN,
173178
expectedArch: limatype.AARCH64,
174179
},
175180
{
176181
locator: "file:///somewhere/macOS-26.ipsw",
177-
expectedName: "macos-26",
178182
expectedOS: limatype.DARWIN,
179183
expectedArch: limatype.AARCH64,
180184
},
181185
{
182186
locator: "file:///somewhere/my-custom-macos.img",
183-
expectedName: "my-custom-macos",
184187
expectedOS: limatype.DARWIN,
185188
expectedArch: limatype.AARCH64,
186189
},
187190
{
188191
locator: "file:///somewhere/something.ipsw",
189-
expectedName: "something",
190192
expectedOS: limatype.DARWIN,
191193
expectedArch: limatype.AARCH64,
192194
},
193195
{
194196
locator: "https://cloud-images.ubuntu.com/releases/noble/release-20260209/ubuntu-24.04-server-cloudimg-amd64.img",
195-
expectedName: "ubuntu-24.04-amd64",
196197
expectedOS: limatype.LINUX,
197198
expectedArch: limatype.X8664,
198199
},
199200
{
200201
locator: "https://cloud-images.ubuntu.com/releases/noble/release-20260209/ubuntu-24.04-server-cloudimg-arm64.img",
201-
expectedName: "ubuntu-24.04-arm64",
202202
expectedOS: limatype.LINUX,
203203
expectedArch: limatype.AARCH64,
204204
},
@@ -207,7 +207,6 @@ func TestRead(t *testing.T) {
207207
t.Run(tt.locator, func(t *testing.T) {
208208
tmpl, err := limatmpl.Read(t.Context(), "", tt.locator)
209209
assert.NilError(t, err)
210-
assert.Equal(t, tmpl.Name, tt.expectedName)
211210
err = tmpl.Unmarshal()
212211
assert.NilError(t, err)
213212
assert.Assert(t, tmpl.Config.OS != nil, "os must be set")

0 commit comments

Comments
 (0)