Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
40 changes: 36 additions & 4 deletions sno-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ source "sno-common.sh"

### 1. Initial checks
if [ $# -lt 1 ]; then
echo "./sno-setup.sh <release image> [pull secret path]"
echo "./sno-setup.sh <release image> [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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -173,16 +188,33 @@ 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 /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 "* Detaching installation ISO"
sudo virsh detach-disk ${hostname} ${assets_dir}/agent.x86_64.iso --config

echo "To access the cluster run: export KUBECONFIG=/var/lib/miniagent/kubeconfig"
fi
end=$(date +%s)
echo ""
echo "Cluster deployed in $(((end - start) / 60)) minutes"