Skip to content

Commit

Permalink
vsphere-agents: delete any conflicting vm/template before starting
Browse files Browse the repository at this point in the history
Before trying to create a new VM/template with a given name, delete any
pre-existing vm/template that might pose as a conflict
  • Loading branch information
etungsten committed Dec 12, 2023
1 parent 12044ec commit 96bc97d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,16 @@ async fn create_vsphere_k8s_cluster(
serde_json::to_writer_pretty(&import_spec_file, &import_spec)
.context(*resources, "Failed to write out OVA import spec file")?;

// Delete any conflicting VM/template
let vm_template_name = format!("{}-eksa-vmtemplate", &config.name);
let _ = Command::new("govc")
.arg("vm.destroy")
.arg(&vm_template_name)
.status()
.context(*resources, "Failed to launch govc process")?;

// Import OVA and create a template out of it
info!("Importing OVA and creating a VM template out of it");
let vm_template_name = format!("{}-eksa-vmtemplate", &config.name);
let import_ova_output = Command::new("govc")
.arg("import.ova")
.arg("-options=/local/ova.importspec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ impl Create for VMCreator {
serde_json::to_writer_pretty(&import_spec_file, &import_spec)
.context(resources, "Failed to write out OVA import spec file")?;

// Delete any conflicting VM/template
let vm_template_name = format!("{}-node-vmtemplate", vsphere_cluster.name);
let _ = Command::new("govc")
.arg("vm.destroy")
.arg(&vm_template_name)
.status()
.context(resources, "Failed to launch govc process")?;

info!("Importing OVA");
memo.current_status = "Importing OVA".to_string();
client
Expand All @@ -302,7 +310,6 @@ impl Create for VMCreator {
.context(resources, "Error sending cluster creation message")?;
// Import OVA and create a template out of it
info!("Importing OVA and creating a VM template out of it");
let vm_template_name = format!("{}-node-vmtemplate", vsphere_cluster.name);
let import_ova_output = Command::new("govc")
.arg("import.ova")
.arg("-options=/local/ova.importspec")
Expand Down

0 comments on commit 96bc97d

Please sign in to comment.