-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tilt improved for easier baremetalhost creation
Signed-off-by: peppi-lotta <peppi-lotta.saari@est.tech>
- Loading branch information
1 parent
63abe2d
commit 26ddbe5
Showing
8 changed files
with
220 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
# Get a list of all virtual machines | ||
VM_LIST=$(virsh -c qemu:///system list --all --name | grep '^bmh-test-') || true | ||
|
||
if [[ -n "${VM_LIST}" ]]; then | ||
# Loop through the list and delete each virtual machine | ||
for vm_name in ${VM_LIST}; do | ||
virsh -c qemu:///system destroy --domain "${vm_name}" | ||
virsh -c qemu:///system undefine --domain "${vm_name}" --remove-all-storage | ||
kubectl delete baremetalhost "${vm_name}" || true | ||
done | ||
else | ||
echo "No virtual machines found. Skipping..." | ||
fi | ||
|
||
# Clear vbmc | ||
docker stop vbmc | ||
docker rm vbmc | ||
|
||
# Clear network | ||
virsh -c qemu:///system net-destroy baremetal-e2e | ||
virsh -c qemu:///system net-undefine baremetal-e2e | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
|
||
# ------------------------------------------------------------------------------------------- | ||
# Description: This script creates a virtual machine using virt-install, | ||
# adds the virtual machine to VBMC (Virtual BMC) for out-of-band management, | ||
# and applies the configuration to Kubernetes | ||
# | ||
# Usage: make tilt-up -> press button in the right upper corner to create bmhs | ||
# /tools/bmh_test/create_bmh.sh | ||
# | ||
# Prerequecites: a network with ip address of 192.168.222.1 named baremetal-e2e and | ||
# VBMC runing | ||
# ------------------------------------------------------------------------------------------- | ||
|
||
set -euxo pipefail | ||
|
||
REPO_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")/../..") | ||
|
||
cd "${REPO_ROOT}" || exit 1 | ||
|
||
# Set default values | ||
NAME="bmh-test-${1:?}" | ||
VBMC_PORT="${2:?}" | ||
CONSUMER="${3:-}" | ||
CONSUMER_NAMESPACE="${4:-}" | ||
|
||
# Generate a random MAC address for the VM's network interface | ||
MAC_ADDRESS="$(printf '00:60:2F:%02X:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)))" | ||
|
||
# Create a virtual machine and connect it to vbmc | ||
"${REPO_ROOT}/tools/bmh_test/create_vm.sh" "${NAME}" "${MAC_ADDRESS}" | ||
"${REPO_ROOT}/tools/bmh_test/vm2vbmc.sh" "${NAME}" "${VBMC_PORT}" | ||
|
||
# Create a YAML file to generate Kubernetes configuration for the VM | ||
# Apply the generated YAML file to the cluster | ||
if [[ -n "${CONSUMER}" ]] && [[ -n "${CONSUMER_NAMESPACE}" ]]; then | ||
echo "Applying YAML for controlplane host..." | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: ${NAME}-bmc-secret | ||
type: Opaque | ||
stringData: | ||
username: admin | ||
password: password | ||
--- | ||
apiVersion: metal3.io/v1alpha1 | ||
kind: BareMetalHost | ||
metadata: | ||
name: ${NAME} | ||
spec: | ||
online: true | ||
bmc: | ||
address: libvirt://192.168.122.1:${VBMC_PORT}/ | ||
credentialsName: ${NAME}-bmc-secret | ||
bootMACAddress: ${MAC_ADDRESS} | ||
consumerRef: | ||
name: ${CONSUMER} | ||
namespace: ${CONSUMER_NAMESPACE} | ||
EOF | ||
else | ||
echo "Applying YAML for host..." | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: ${NAME}-bmc-secret | ||
type: Opaque | ||
stringData: | ||
username: admin | ||
password: password | ||
--- | ||
apiVersion: metal3.io/v1alpha1 | ||
kind: BareMetalHost | ||
metadata: | ||
name: ${NAME} | ||
spec: | ||
online: true | ||
bmc: | ||
address: libvirt://192.168.122.1:${VBMC_PORT}/ | ||
credentialsName: ${NAME}-bmc-secret | ||
bootMACAddress: ${MAC_ADDRESS} | ||
EOF | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
NAME="${1:?}" | ||
MAC_ADDRESS="${2:?}" | ||
|
||
# Create a virtual machine | ||
virt-install \ | ||
--connect qemu:///system \ | ||
--name "${NAME}" \ | ||
--description "Virtualized BareMetalHost" \ | ||
--osinfo=ubuntu-lts-latest \ | ||
--ram=4096 \ | ||
--vcpus=2 \ | ||
--disk size=20 \ | ||
--graphics=none \ | ||
--console pty \ | ||
--serial pty \ | ||
--pxe \ | ||
--network network=baremetal-e2e,mac="${MAC_ADDRESS}" \ | ||
--noautoconsole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
REPO_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")/../..") | ||
|
||
cd "${REPO_ROOT}" || exit 1 | ||
|
||
# Check if the script is run as root | ||
if [[ $EUID != 0 ]]; then | ||
echo "ERROR: This script must be run as root" | ||
exit 1 | ||
fi | ||
|
||
# Install virtinst, libvirt clients and daemon system | ||
apt-get -y update | ||
apt-get -y install virtinst libvirt-clients libvirt-daemon-system | ||
|
||
# Define and start a virtual network | ||
virsh -c qemu:///system net-define "${REPO_ROOT}/hack/e2e/net.xml" | ||
virsh -c qemu:///system net-start baremetal-e2e | ||
|
||
# Start VBMC | ||
docker run --name vbmc --network host -d \ | ||
-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock \ | ||
-v /var/run/libvirt/libvirt-sock-ro:/var/run/libvirt/libvirt-sock-ro \ | ||
quay.io/metal3-io/vbmc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
NAME="${1:?}" | ||
VBMC_PORT="${2:?}" | ||
|
||
# Add the BareMetalHost VM to VBMC | ||
docker exec vbmc vbmc add "${NAME}" --port "${VBMC_PORT}" --libvirt-uri "qemu:///system" | ||
docker exec vbmc vbmc start "${NAME}" | ||
docker exec vbmc vbmc list |