@@ -19,8 +19,9 @@ export async function prepare(werft: Werft, config: JobConfig) {
19
19
configureDocker ( )
20
20
configureCoreDevAccess ( )
21
21
werft . done ( prepareSlices . CONFIGURE_CORE_DEV )
22
-
23
- decideHarvesterVMCreation ( werft , config )
22
+ if ( config . withVM ) {
23
+ prepareVM ( werft , config )
24
+ }
24
25
} catch ( err ) {
25
26
werft . fail ( phaseName , err ) ;
26
27
}
@@ -62,27 +63,23 @@ function configureCoreDevAccess() {
62
63
}
63
64
}
64
65
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
-
74
66
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 ) {
76
72
werft . log ( prepareSlices . BOOT_VM , "Cleaning previously created VM" )
77
73
VM . deleteVM ( { name : config . previewEnvironment . destname } )
74
+ createVM ( werft , config , prepareSlices . BOOT_VM )
78
75
}
79
- createVM ( werft , config , prepareSlices . BOOT_VM )
76
+ werft . done ( prepareSlices . BOOT_VM )
80
77
}
81
78
82
79
// createVM only triggers the VM creation.
83
80
// Readiness is not guaranted.
84
81
function createVM ( werft : Werft , config : JobConfig , slice : string ) {
85
- werft . log ( slice , 'Booting VM' )
82
+ werft . log ( slice , 'Creating VM' )
86
83
VM . startVM ( { name : config . previewEnvironment . destname } )
87
84
werft . currentPhaseSpan . setAttribute ( "werft.harvester.created_vm" , true )
88
85
}
0 commit comments