-
Notifications
You must be signed in to change notification settings - Fork 15
Add bare metal agent-based install support #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Initialize a bare metal host for two-node cluster deployment. | ||
| # Usage: bm-init.sh [user@host] | ||
| # | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| DEPLOY_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)" | ||
|
|
||
| set -o nounset | ||
| set -o errexit | ||
| set -o pipefail | ||
|
|
||
| INSTANCE_DATA_DIR="${DEPLOY_DIR}/aws-hypervisor/instance-data" | ||
| INVENTORY_FILE="${DEPLOY_DIR}/openshift-clusters/inventory.ini" | ||
|
|
||
| HOST_TARGET="${1:-}" | ||
|
|
||
| if [[ -z "${HOST_TARGET}" ]]; then | ||
| read -rp "Enter bare metal host (user@host or IP): " HOST_TARGET | ||
| fi | ||
|
|
||
| if [[ -z "${HOST_TARGET}" ]]; then | ||
| echo "Error: No host specified." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # If only an IP/hostname was given, default to root@ | ||
| if [[ "${HOST_TARGET}" != *@* ]]; then | ||
| HOST_TARGET="root@${HOST_TARGET}" | ||
| fi | ||
|
|
||
| echo "Initializing bare metal host: ${HOST_TARGET}" | ||
|
|
||
| # Generate inventory file | ||
| echo "Generating inventory.ini..." | ||
| cat > "${INVENTORY_FILE}" <<EOF | ||
| [metal_machine] | ||
| ${HOST_TARGET} ansible_ssh_extra_args='-o ServerAliveInterval=30 -o ServerAliveCountMax=120' | ||
|
|
||
| [metal_machine:vars] | ||
| ansible_become_password="" | ||
| EOF | ||
|
|
||
| # Run the init-host playbook | ||
| echo "Running init-host.yml playbook..." | ||
| cd "${DEPLOY_DIR}/openshift-clusters" | ||
|
|
||
| if ansible-playbook init-host.yml -i inventory.ini; then | ||
| echo "" | ||
| echo "Host initialization completed successfully!" | ||
|
|
||
| # Write the bare metal marker file | ||
| mkdir -p "${INSTANCE_DATA_DIR}" | ||
| echo "${HOST_TARGET}" > "${INSTANCE_DATA_DIR}/bare-metal-host" | ||
|
|
||
| echo "" | ||
| echo "Next steps:" | ||
| echo " Deploy a cluster:" | ||
| echo " make bm-fencing-agent" | ||
| echo " make bm-arbiter-agent" | ||
| else | ||
| echo "Error: Host initialization failed!" | ||
| echo "Check the Ansible logs for more details." | ||
| exit 1 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
| # | ||
| # SSH to a bare metal host initialized with bm-init.sh | ||
| # | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| DEPLOY_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)" | ||
|
|
||
| set -o nounset | ||
| set -o errexit | ||
| set -o pipefail | ||
|
|
||
| MARKER_FILE="${DEPLOY_DIR}/aws-hypervisor/instance-data/bare-metal-host" | ||
|
|
||
| if [[ ! -f "${MARKER_FILE}" ]]; then | ||
| echo "Error: No bare metal host found. Run 'make bm-init' first." | ||
| exit 1 | ||
| fi | ||
|
|
||
| HOST_TARGET=$(cat "${MARKER_FILE}") | ||
| echo "Connecting to bare metal host: ${HOST_TARGET}" | ||
| ssh "${HOST_TARGET}" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| # Shared helper functions for cluster management scripts. | ||||||||||||||||||||||||||||||||||||||||||
| # Supports both AWS EC2 and bare metal deployments. | ||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Detect the instance type (aws or baremetal) by checking for marker files. | ||||||||||||||||||||||||||||||||||||||||||
| # Prints the type to stdout and returns 0, or prints an error and returns 1. | ||||||||||||||||||||||||||||||||||||||||||
| check_instance() { | ||||||||||||||||||||||||||||||||||||||||||
| local deploy_dir="$1" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [[ -f "${deploy_dir}/aws-hypervisor/instance-data/aws-instance-id" ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "aws" | ||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
| elif [[ -f "${deploy_dir}/aws-hypervisor/instance-data/bare-metal-host" ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "baremetal" | ||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| echo "Error: No instance found. Run 'make deploy' (EC2) or 'make bm-init' (bare metal) first." >&2 | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Get a display identifier for the current instance (instance ID or hostname). | ||||||||||||||||||||||||||||||||||||||||||
| get_instance_display() { | ||||||||||||||||||||||||||||||||||||||||||
| local deploy_dir="$1" | ||||||||||||||||||||||||||||||||||||||||||
| local instance_type="$2" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| case "${instance_type}" in | ||||||||||||||||||||||||||||||||||||||||||
| aws) | ||||||||||||||||||||||||||||||||||||||||||
| cat "${deploy_dir}/aws-hypervisor/instance-data/aws-instance-id" | ||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||
| baremetal) | ||||||||||||||||||||||||||||||||||||||||||
| cat "${deploy_dir}/aws-hypervisor/instance-data/bare-metal-host" | ||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Get the SSH user and host for connecting to the hypervisor. | ||||||||||||||||||||||||||||||||||||||||||
| get_ssh_target() { | ||||||||||||||||||||||||||||||||||||||||||
| local deploy_dir="$1" | ||||||||||||||||||||||||||||||||||||||||||
| local instance_type="$2" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| case "${instance_type}" in | ||||||||||||||||||||||||||||||||||||||||||
| aws) | ||||||||||||||||||||||||||||||||||||||||||
| local ssh_user host_ip | ||||||||||||||||||||||||||||||||||||||||||
| ssh_user=$(cat "${deploy_dir}/aws-hypervisor/instance-data/ssh_user") | ||||||||||||||||||||||||||||||||||||||||||
| host_ip=$(cat "${deploy_dir}/aws-hypervisor/instance-data/public_address") | ||||||||||||||||||||||||||||||||||||||||||
| echo "${ssh_user}@${host_ip}" | ||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||
| baremetal) | ||||||||||||||||||||||||||||||||||||||||||
| # Read the first metal_machine host from the inventory | ||||||||||||||||||||||||||||||||||||||||||
| grep -A1 '^\[metal_machine\]' "${deploy_dir}/openshift-clusters/inventory.ini" \ | ||||||||||||||||||||||||||||||||||||||||||
| | tail -1 | awk '{print $1}' | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't derive the bare-metal SSH target from the inventory alias alone. This branch returns the first field under 💡 Suggested fix baremetal)
- # Read the first metal_machine host from the inventory
- grep -A1 '^\[metal_machine\]' "${deploy_dir}/openshift-clusters/inventory.ini" \
- | tail -1 | awk '{print $1}'
+ awk '
+ /^\[metal_machine\]$/ { in_section=1; next }
+ /^\[/ { in_section=0 }
+ in_section && NF {
+ host=$1; user=""; addr=""
+ for (i=2; i<=NF; i++) {
+ if ($i ~ /^ansible_user=/) { sub(/^ansible_user=/, "", $i); user=$i }
+ if ($i ~ /^ansible_host=/) { sub(/^ansible_host=/, "", $i); addr=$i }
+ }
+ if (addr == "") addr=host
+ print (user ? user "@" : "") addr
+ exit
+ }
+ ' "${deploy_dir}/openshift-clusters/inventory.ini"
;;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,9 +67,12 @@ if [[ "${METHOD}" != "ipi" && "${METHOD}" != "agent" && "${METHOD}" != "kcli" ]] | |
| exit 1 | ||
| fi | ||
|
|
||
| # Check if instance data exists | ||
| if [[ ! -f "${DEPLOY_DIR}/aws-hypervisor/instance-data/aws-instance-id" ]]; then | ||
| echo "Error: No instance found. Please run 'make deploy' first." | ||
| # Source shared helpers | ||
| # shellcheck source=common.sh | ||
| source "${SCRIPT_DIR}/common.sh" | ||
|
|
||
| # Check if instance data exists (EC2 or bare metal) | ||
| if ! check_instance "${DEPLOY_DIR}" >/dev/null; then | ||
| exit 1 | ||
|
Comment on lines
+74
to
76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject non-agent methods on bare metal. This new gate lets bare-metal runs through for every method, but this PR only adds bare-metal support for agent-based installs. 💡 Suggested fix-# Check if instance data exists (EC2 or bare metal)
-if ! check_instance "${DEPLOY_DIR}" >/dev/null; then
- exit 1
-fi
+# Check if instance data exists (EC2 or bare metal)
+INSTANCE_TYPE=$(check_instance "${DEPLOY_DIR}") || exit 1
+
+if [[ "${INSTANCE_TYPE}" == "baremetal" && "${METHOD}" != "agent" ]]; then
+ echo "Error: bare metal deployments only support --method agent"
+ exit 1
+fi🤖 Prompt for AI Agents |
||
| fi | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear stale AWS marker when persisting bare-metal state.
At Line 55,
bare-metal-hostis written, but an existingaws-instance-idis left intact. Sincecheck_instance()prioritizes AWS markers, later scripts can branch to the wrong mode when both files exist.Suggested patch
# Write the bare metal marker file mkdir -p "${INSTANCE_DATA_DIR}" + rm -f "${INSTANCE_DATA_DIR}/aws-instance-id" echo "${HOST_TARGET}" > "${INSTANCE_DATA_DIR}/bare-metal-host"📝 Committable suggestion
🤖 Prompt for AI Agents