From 22ff6114164e3a482b4ec44c6905022c0b2d4fe3 Mon Sep 17 00:00:00 2001 From: Katya Gordeeva Date: Fri, 15 Aug 2025 13:03:05 +0200 Subject: [PATCH 1/2] adding persitent mode to survive host reboots --- README.md | 27 +++++++++++++++++++++++++-- sno-setup.sh | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 14383f4..b3a4063 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ $ ./sno-setup.sh quay.io/openshift-release-dev/ocp-release:4.14.3-x86_64 ~/confi > **_NOTE:_** The pull secret file parameter is not required if the `REGISTRY_AUTH_FILE` environment variable is already set +For clusters that should survive host reboots, add the `--persist` flag: + +``` bash +$ ./sno-setup.sh quay.io/openshift-release-dev/ocp-release:4.14.3-x86_64 ~/config/my-pull-secret --persist +``` + 2. Wait for the installation to complete. The console will show a detailed output about each phase of the installation. ``` bash @@ -41,14 +47,31 @@ INFO export KUBECONFIG=/tmp/agent-DvM/auth/kubeconfig 3. Connect to your new cluster using the credentials stored in the asset folder. +**Default mode (ephemeral):** ``` bash -$ export KUBECONFIG=/tmp/agent/auth/kubeconfig +$ export KUBECONFIG=/tmp/mini-agent/auth/kubeconfig $ oc get nodes NAME STATUS ROLES AGE VERSION master-0 Ready control-plane,master,worker 36m v1.26.3+b404935 ``` -4. Once done, to remove the cluster and cleanup the enviroment, run the cleanup script +**Persistent mode (with `--persist` flag):** +``` bash +$ export KUBECONFIG=/var/lib/miniagent/kubeconfig +$ oc get nodes +NAME STATUS ROLES AGE VERSION +master-0 Ready control-plane,master,worker 36m v1.26.3+b404935 +``` + +4. Once done, to remove the cluster and cleanup the environment, run the cleanup script ``` bash $ ./sno-cleanup.sh ``` + +## Persistence Mode + +By default, miniagent creates ephemeral clusters for quick testing that do not survive host reboots. Use the `--persist` flag to enable reboot survival features: + +- **Network and VM autostart**: Automatically start after host reboot +- **Installation ISO detachment**: Eliminates dependency on /tmp files +- **Persistent kubeconfig**: Saved to `/var/lib/miniagent/kubeconfig` diff --git a/sno-setup.sh b/sno-setup.sh index 30def01..98cbe22 100755 --- a/sno-setup.sh +++ b/sno-setup.sh @@ -5,17 +5,28 @@ source "sno-common.sh" ### 1. Initial checks if [ $# -lt 1 ]; then - echo "./sno-setup.sh [pull secret path]" + echo "./sno-setup.sh [pull secret path] [--persist]" echo "Usage example:" echo "$ ./sno-setup.sh quay.io/openshift-release-dev/ocp-release:4.14.3-x86_64 # This works if REGISTRY_AUTH_FILE is already set" echo "$ ./sno-setup.sh quay.io/openshift-release-dev/ocp-release:4.14.3-x86_64 ~/config/my-pull-secret" + echo "$ ./sno-setup.sh quay.io/openshift-release-dev/ocp-release:4.14.3-x86_64 ~/config/my-pull-secret --persist # Survive reboots" exit 1 fi +# Check if --persist flag is present +persist_mode=false +for arg in "$@"; do + if [ "$arg" = "--persist" ]; then + persist_mode=true + break + fi +done + releaseImage=$1 pullSecretFile=${REGISTRY_AUTH_FILE:-} -if [ $# -eq 2 ]; then +# Handle pull secret from $2, accounting for possible --persist flag +if [ $# -eq 2 ] || [ $# -eq 3 ]; then pullSecretFile=$2 fi @@ -101,6 +112,10 @@ EOF sudo virsh net-define ${assets_dir}/${network}.xml sudo virsh net-start ${network} +if [ "$persist_mode" = "true" ]; then + echo "* Enabling network autostart for persistence" + sudo virsh net-autostart ${network} +fi ### The guest inside the agent network will not be resolvable from the host, ### and this will be required later by the wait-for command @@ -173,16 +188,39 @@ sudo virt-install \ --os-variant rhel9-unknown \ --noautoconsole & - ### 9. Check if the agent virtual machine is up and running while ! sudo virsh list --all | grep -q "\s${hostname}\s.*running"; do echo "Waiting for ${hostname} to start..." sleep 5 done -### 10. Wait for the installation to complete +### 10. Enable VM autostart for persistence across reboots (if requested) +if [ "$persist_mode" = "true" ]; then + echo "* Enabling VM autostart" + sudo virsh autostart ${hostname} +fi + +### 11. Wait for the installation to complete ${assets_dir}/openshift-install agent wait-for install-complete --dir=${assets_dir} --log-level=debug +### 12. Post-installation persistence steps (if requested) +if [ "$persist_mode" = "true" ]; then + echo "* Copying kubeconfig to persistent location" + sudo mkdir -p /var/lib/miniagent + sudo cp ${assets_dir}/auth/kubeconfig /var/lib/miniagent/kubeconfig + sudo chmod 644 /var/lib/miniagent/kubeconfig + echo " Kubeconfig saved to: /var/lib/miniagent/kubeconfig" + + echo "* Detaching installation ISO" + sudo virsh detach-disk ${hostname} ${assets_dir}/agent.x86_64.iso --config + echo " ISO detached - VM will boot from persistent disk" + + echo "" + echo "=== PERSISTENCE ENABLED ===" + echo "Cluster will survive host reboots." + echo "To access cluster after reboot: export KUBECONFIG=/var/lib/miniagent/kubeconfig" + echo "==========================" +fi end=$(date +%s) echo "" echo "Cluster deployed in $(((end - start) / 60)) minutes" From 9d936d8094e2a6eb358092dfb18eea36af60d178 Mon Sep 17 00:00:00 2001 From: Katya Gordeeva Date: Fri, 15 Aug 2025 14:28:45 +0200 Subject: [PATCH 2/2] chore: clean up unnecessary prints to console --- sno-setup.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sno-setup.sh b/sno-setup.sh index 98cbe22..de5d3f0 100755 --- a/sno-setup.sh +++ b/sno-setup.sh @@ -205,21 +205,15 @@ ${assets_dir}/openshift-install agent wait-for install-complete --dir=${assets_d ### 12. Post-installation persistence steps (if requested) if [ "$persist_mode" = "true" ]; then - echo "* Copying kubeconfig to persistent location" + echo "* Copying kubeconfig to /var/lib/miniagent/kubeconfig" sudo mkdir -p /var/lib/miniagent sudo cp ${assets_dir}/auth/kubeconfig /var/lib/miniagent/kubeconfig sudo chmod 644 /var/lib/miniagent/kubeconfig - echo " Kubeconfig saved to: /var/lib/miniagent/kubeconfig" echo "* Detaching installation ISO" sudo virsh detach-disk ${hostname} ${assets_dir}/agent.x86_64.iso --config - echo " ISO detached - VM will boot from persistent disk" - echo "" - echo "=== PERSISTENCE ENABLED ===" - echo "Cluster will survive host reboots." - echo "To access cluster after reboot: export KUBECONFIG=/var/lib/miniagent/kubeconfig" - echo "==========================" + echo "To access the cluster run: export KUBECONFIG=/var/lib/miniagent/kubeconfig" fi end=$(date +%s) echo ""