Prune Scenario

This commit is contained in:
Yosafat Marselino 2025-05-17 09:46:22 -04:00
parent 5b01428a31
commit c3f19b744a
2 changed files with 13 additions and 5 deletions

View File

@ -38,6 +38,9 @@
msg: "{{ item.stdout_lines }}"
loop: "{{ script_output.results }}"
- name: Add Kubeconfig to User
shell: "rm -rf /home/ubuntu/.kube/config && mkdir -p /home/ubuntu/.kube/config && cp /etc/kubernetes/adminf.conf /home/ubuntu/.kube/config"
- name: Clean up temporary directory
file:
path: /tmp/downloaded_scripts

View File

@ -40,6 +40,10 @@ while [ $# -gt 0 ]; do
VM_IP="$2"
shift 2
;;
-prune | --prune)
PRUNE=true
shift 2
;;
*)
echo "Error: Unknown option $1"
usage
@ -90,16 +94,17 @@ check_and_install_curl() {
check_existing_cluster() {
if command_exists kubectl && kubectl cluster-info &>/dev/null; then
read -p "Existing Kubernetes cluster found. Do you want to remove it? (y/N): " remove_cluster
if [[ "$remove_cluster" != "y" && "$remove_cluster" != "Y" ]]; then
if [[ $PRUNE != false ]]; then
echo "Kubernetes cluster removal skipped. Exiting script."
exit 0
fi
echo "Removing existing Kubernetes cluster..."
kubeadm reset -f
sudo apt-get -y purge kubeadm kubectl kubelet kubernetes-cni kube* containerd
sudo apt-get -y autoremove
sudo rm -rf ~/.kube
apt-get -y autoremove
# What's the point of uninstalling them if later on we gonna install them again
# sudo apt-get -y purge kubeadm kubectl kubelet kubernetes-cni kube* containerd
# sudo apt-get -y autoremove
# sudo rm -rf ~/.kube
# apt-get -y autoremove
fi
}