Skip to content

Commit 2543294

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

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.werft/jobs/build/prepare.ts

Lines changed: 11 additions & 5 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
}
@@ -63,7 +64,9 @@ function configureCoreDevAccess() {
6364
}
6465

6566
function decideHarvesterVMCreation(werft: Werft, config: JobConfig) {
66-
if (config.withVM && !VM.vmExists({ name: config.previewEnvironment.destname })) {
67+
werft.log(`prepare`, VM.vmExists({ name: config.previewEnvironment.destname }))
68+
&& {
69+
werft.log(`prepare`, `Prepare VM`)
6770
prepareVM(werft, config)
6871
} else {
6972
werft.currentPhaseSpan.setAttribute("werft.harvester.created_vm", false)
@@ -72,11 +75,14 @@ function decideHarvesterVMCreation(werft: Werft, config: JobConfig) {
7275
}
7376

7477
function prepareVM(werft: Werft, config: JobConfig) {
75-
if (config.cleanSlateDeployment) {
78+
if (config.cleanSlateDeployment && VM.vmExists({ name: config.previewEnvironment.destname })) {
7679
werft.log(prepareSlices.BOOT_VM, "Cleaning previously created VM")
7780
VM.deleteVM({ name: config.previewEnvironment.destname })
7881
}
79-
createVM(werft, config, prepareSlices.BOOT_VM)
82+
if (!VM.vmExists({ name: config.previewEnvironment.destname })) {
83+
werft.log(prepareSlices.BOOT_VM, "Creating VM")
84+
createVM(werft, config, prepareSlices.BOOT_VM)
85+
}
8086
}
8187

8288
// 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)