Skip to content

Commit 48fc079

Browse files
authored
Generate boot disk name from image name (#2542)
* Use image name to generate fallback boot disk name * Update test * More accurate comment
1 parent f3d3810 commit 48fc079

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

app/forms/instance-create.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
usePrefetchedApiQuery,
2323
type ExternalIpCreate,
2424
type FloatingIp,
25+
type Image,
2526
type InstanceCreate,
2627
type InstanceDiskAttachment,
2728
type NameOrId,
@@ -81,17 +82,21 @@ import { nearest10 } from '~/util/math'
8182
import { pb } from '~/util/path-builder'
8283
import { GiB } from '~/util/units'
8384

84-
const getBootDiskAttachment = (values: InstanceCreateInput): InstanceDiskAttachment => {
85+
const getBootDiskAttachment = (
86+
values: InstanceCreateInput,
87+
images: Array<Image>
88+
): InstanceDiskAttachment => {
8589
if (values.bootDiskSourceType === 'disk') {
8690
return { type: 'attach', name: values.diskSource }
8791
}
8892
const source =
8993
values.bootDiskSourceType === 'siloImage'
9094
? values.siloImageSource
9195
: values.projectImageSource
96+
const sourceName = images.find((image) => image.id === source)?.name
9297
return {
9398
type: 'create',
94-
name: values.bootDiskName || genName(values.name, source),
99+
name: values.bootDiskName || genName(values.name, sourceName || source),
95100
description: `Created as a boot disk for ${values.name}`,
96101
size: values.bootDiskSize * GiB,
97102
diskSource: { type: 'image', imageId: source },
@@ -301,7 +306,7 @@ export function CreateInstanceForm() {
301306
? { memory: values.memory, ncpus: values.ncpus }
302307
: { memory: preset.memory, ncpus: preset.ncpus }
303308

304-
const bootDisk = getBootDiskAttachment(values)
309+
const bootDisk = getBootDiskAttachment(values, allImages)
305310

306311
const userData = values.userData
307312
? await readBlobAsBase64(values.userData)

test/e2e/instance-create.e2e.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ test('maintains selected values even when changing tabs', async ({ page }) => {
374374
await page.getByRole('button', { name: 'Create instance' }).click()
375375
await expect(page).toHaveURL(`/projects/mock-project/instances/${instanceName}/storage`)
376376
await expectVisible(page, [`h1:has-text("${instanceName}")`, 'text=8 GiB'])
377-
// when a disk name isn’t assigned, the generated one uses the ID of the image,
378-
// so this checks to make sure that the arch-based image — with ID `bd6aa051…` — was used
379-
await expectVisible(page, [`text=${instanceName}-bd6aa051`])
377+
// when a disk name isn’t assigned, the generated one uses the name of the image,
378+
// so this checks to make sure that the arch-based image — with name `arch-2022-06-01` — was used
379+
await expectVisible(page, [`text=${instanceName}-${arch}`])
380380
})
381381

382382
test('does not attach an ephemeral IP when the checkbox is unchecked', async ({ page }) => {

0 commit comments

Comments
 (0)