Adjusting cleanup process
This commit is contained in:
parent
91d1e369e8
commit
814b690329
2 changed files with 14 additions and 23 deletions
|
|
@ -1,5 +1,8 @@
|
|||
#!/bin/bash
|
||||
cluster_name="$1"
|
||||
echo "Starting cleanup for cluster: $cluster_name"
|
||||
|
||||
sudo ifconfig bridge0 destroy || true
|
||||
|
||||
# Remove kubeconfig entries
|
||||
kubectl config delete-context "$cluster_name" || true
|
||||
|
|
|
|||
|
|
@ -46,9 +46,13 @@ resource "random_id" "cluster_suffix" {
|
|||
|
||||
resource "null_resource" "talos_cluster" {
|
||||
triggers = {
|
||||
cluster_name = local.unique_cluster_name
|
||||
memory_mb = var.memory_mb
|
||||
vcpu_count = var.vcpu_count
|
||||
config_hash = sha1(join("", [
|
||||
var.cluster_name,
|
||||
tostring(var.memory_mb),
|
||||
tostring(var.vcpu_count),
|
||||
var.talos_version,
|
||||
filesha1("${path.module}/cleanup.sh") # Recreate if cleanup script changes
|
||||
]))
|
||||
}
|
||||
|
||||
# Download Talos kernel and initramfs
|
||||
|
|
@ -64,41 +68,25 @@ resource "null_resource" "talos_cluster" {
|
|||
command = <<EOT
|
||||
set -e # Exit on error
|
||||
|
||||
# First, try to destroy the cluster properly
|
||||
echo "Attempting to destroy existing cluster..."
|
||||
sudo --preserve-env=HOME talosctl cluster destroy \
|
||||
--provisioner=qemu \
|
||||
--name ${self.triggers.cluster_name} 2>/dev/null || echo "Cluster destroy completed or not found"
|
||||
|
||||
# Wait for cleanup
|
||||
sleep 3
|
||||
|
||||
# Now run the comprehensive cleanup script to remove any leftovers
|
||||
echo "Running comprehensive cleanup..."
|
||||
chmod +x ${path.module}/cleanup.sh
|
||||
${path.module}/cleanup.sh ${self.triggers.cluster_name}
|
||||
|
||||
# Wait a bit more to ensure everything is cleaned up
|
||||
sleep 2
|
||||
|
||||
# Now create the cluster
|
||||
echo "Creating new cluster..."
|
||||
sudo --preserve-env=HOME talosctl cluster create \
|
||||
--provisioner=qemu \
|
||||
--name ${self.triggers.cluster_name} \
|
||||
--talosconfig ${path.module}/talosconfig \
|
||||
--controlplanes 1 \
|
||||
--workers 0 \
|
||||
--memory ${self.triggers.memory_mb} \
|
||||
--cpus ${self.triggers.vcpu_count}
|
||||
|
||||
# Change ownership of the generated files in ~/.talos and ~/.kube
|
||||
sudo chown -R $(whoami):admin ~/.talos
|
||||
sudo chown -R $(whoami):admin ~/.kube
|
||||
sudo chown -R $(whoami):admin $(HOME)/.talos
|
||||
sudo chown -R $(whoami):admin $(HOME)/.kube
|
||||
EOT
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
when = destroy
|
||||
when = destroyed
|
||||
command = <<EOT
|
||||
sudo --preserve-env=HOME talosctl cluster destroy \
|
||||
--provisioner=qemu \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue