Skip to content

Commit 7c6b54f

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

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

.werft/jobs/build/prepare.ts

Lines changed: 8 additions & 13 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,21 +63,15 @@ 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+
if (config.cleanSlateDeployment && VM.vmExists({ name: config.previewEnvironment.destname })) {
7668
werft.log(prepareSlices.BOOT_VM, "Cleaning previously created VM")
7769
VM.deleteVM({ name: config.previewEnvironment.destname })
7870
}
79-
createVM(werft, config, prepareSlices.BOOT_VM)
71+
if (!VM.vmExists({ name: config.previewEnvironment.destname })) {
72+
werft.log(prepareSlices.BOOT_VM, "Creating VM")
73+
createVM(werft, config, prepareSlices.BOOT_VM)
74+
}
8075
}
8176

8277
// createVM only triggers the VM creation.

.werft/vm/vm.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ export function startVM(options: { name: string }) {
114114
* @returns true if the VM already exists
115115
*/
116116
export function vmExists(options: { name: string }) {
117-
const namespace = `preview-${options.name}`
118-
const status = exec(`kubectl --kubeconfig ${KUBECONFIG_PATH} -n ${namespace} get vmi ${options.name}`, { dontCheckRc: true, silent: true })
117+
const status = exec(`kubectl --kubeconfig ${KUBECONFIG_PATH} -n preview-${options.name} get vmi ${options.name}`, { dontCheckRc: true, silent: true })
119118
return status.code == 0
120119
}
121120

0 commit comments

Comments
 (0)