Skip to content

Commit 1381c3c

Browse files
Wulf ThimmWulf Thimm
Wulf Thimm
authored and
Wulf Thimm
committed
fixed clean-slate-deployment of VMs
1 parent d2913ae commit 1381c3c

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

.werft/jobs/build/prepare.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export async function prepare(werft: Werft, config: JobConfig) {
1919
configureDocker()
2020
configureCoreDevAccess()
2121
werft.done(prepareSlices.CONFIGURE_CORE_DEV)
22-
23-
decideHarvesterVMCreation(werft, config)
22+
if (config.withVM) {
23+
prepareVM(werft, config)
24+
}
2425
} catch (err) {
2526
werft.fail(phaseName, err);
2627
}
@@ -62,27 +63,23 @@ function configureCoreDevAccess() {
6263
}
6364
}
6465

65-
function decideHarvesterVMCreation(werft: Werft, config: JobConfig) {
66-
if (config.withVM && !VM.vmExists({ name: config.previewEnvironment.destname })) {
67-
prepareVM(werft, config)
68-
} else {
69-
werft.currentPhaseSpan.setAttribute("werft.harvester.created_vm", false)
70-
}
71-
werft.done(prepareSlices.BOOT_VM)
72-
}
73-
7466
function prepareVM(werft: Werft, config: JobConfig) {
75-
if (config.cleanSlateDeployment) {
67+
const vmExists = VM.vmExists({ name: config.previewEnvironment.destname })
68+
if (!vmExists) {
69+
createVM(werft, config, prepareSlices.BOOT_VM)
70+
}
71+
else if (config.cleanSlateDeployment && vmExists) {
7672
werft.log(prepareSlices.BOOT_VM, "Cleaning previously created VM")
7773
VM.deleteVM({ name: config.previewEnvironment.destname })
74+
createVM(werft, config, prepareSlices.BOOT_VM)
7875
}
79-
createVM(werft, config, prepareSlices.BOOT_VM)
76+
werft.done(prepareSlices.BOOT_VM)
8077
}
8178

8279
// createVM only triggers the VM creation.
8380
// Readiness is not guaranted.
8481
function createVM(werft: Werft, config: JobConfig, slice: string) {
85-
werft.log(slice, 'Booting VM')
82+
werft.log(slice, 'Creating VM')
8683
VM.startVM({ name: config.previewEnvironment.destname })
8784
werft.currentPhaseSpan.setAttribute("werft.harvester.created_vm", true)
8885
}

0 commit comments

Comments
 (0)