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 }}" msg: "{{ item.stdout_lines }}"
loop: "{{ script_output.results }}" 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 - name: Clean up temporary directory
file: file:
path: /tmp/downloaded_scripts path: /tmp/downloaded_scripts

View File

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