Skip to content

Commit

Permalink
Linting issues with shell formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Jun 10, 2024
1 parent 9ce29dd commit 19e22d8
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 165 deletions.
48 changes: 24 additions & 24 deletions capt/scripts/create_vms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ set -euo pipefail
# Create VMs

function main() {
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
declare BRIDGE_NAME="$(yq eval '.kind.bridgeName' "$STATE_FILE")"
declare CPUS="$(yq eval '.vm.cpusPerVM' "$STATE_FILE")"
declare MEM="$(yq eval '.vm.memInMBPerVM' "$STATE_FILE")"
declare DISK_SIZE="$(yq eval '.vm.diskSizeInGBPerVM' "$STATE_FILE")"
declare DISK_PATH="$(yq eval '.vm.diskPath' "$STATE_FILE")"
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
declare BRIDGE_NAME="$(yq eval '.kind.bridgeName' "$STATE_FILE")"
declare CPUS="$(yq eval '.vm.cpusPerVM' "$STATE_FILE")"
declare MEM="$(yq eval '.vm.memInMBPerVM' "$STATE_FILE")"
declare DISK_SIZE="$(yq eval '.vm.diskSizeInGBPerVM' "$STATE_FILE")"
declare DISK_PATH="$(yq eval '.vm.diskPath' "$STATE_FILE")"

while IFS=$',' read -r name mac; do
# create the VM
virt-install \
--description "CAPT VM" \
--ram "$MEM" --vcpus "$CPUS" \
--os-variant "ubuntu20.04" \
--graphics "vnc" \
--boot "uefi,firmware.feature0.name=enrolled-keys,firmware.feature0.enabled=no,firmware.feature1.name=secure-boot,firmware.feature1.enabled=yes" \
--noautoconsole \
--noreboot \
--import \
--connect "qemu:///system" \
--name "$name" \
--disk "path=$DISK_PATH/$name-disk.img,bus=virtio,size=10,sparse=yes" \
--network "bridge:$BRIDGE_NAME,mac=$mac"
done < <(yq e '.vm.details.[] | [key, .mac] | @csv' "$STATE_FILE")
while IFS=$',' read -r name mac; do
# create the VM
virt-install \
--description "CAPT VM" \
--ram "$MEM" --vcpus "$CPUS" \
--os-variant "ubuntu20.04" \
--graphics "vnc" \
--boot "uefi,firmware.feature0.name=enrolled-keys,firmware.feature0.enabled=no,firmware.feature1.name=secure-boot,firmware.feature1.enabled=yes" \
--noautoconsole \
--noreboot \
--import \
--connect "qemu:///system" \
--name "$name" \
--disk "path=$DISK_PATH/$name-disk.img,bus=virtio,size=10,sparse=yes" \
--network "bridge:$BRIDGE_NAME,mac=$mac"
done < <(yq e '.vm.details.[] | [key, .mac] | @csv' "$STATE_FILE")
}

main "$@"
main "$@"
34 changes: 17 additions & 17 deletions capt/scripts/generate_bmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ set -euo pipefail
# This script creates the BMC machine yaml files needed for the CAPT playground.

function main() {
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")

rm -f "$OUTPUT_DIR"/bmc-machine*.yaml
rm -f "$OUTPUT_DIR"/bmc-machine*.yaml

namespace=$(yq eval '.namespace' "$STATE_FILE")
bmc_ip=$(yq eval '.virtualBMC.ip' "$STATE_FILE")
namespace=$(yq eval '.namespace' "$STATE_FILE")
bmc_ip=$(yq eval '.virtualBMC.ip' "$STATE_FILE")

while IFS=$',' read -r name port; do
export NODE_NAME="$name"
export BMC_IP="$bmc_ip"
export BMC_PORT="$port"
export NAMESPACE="$namespace"
envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" < templates/bmc-machine.tmpl > "$OUTPUT_DIR"/bmc-machine-"$NODE_NAME".yaml
unset NODE_NAME
unset BMC_IP
unset BMC_PORT
unset NAMESPACE
done < <(yq e '.vm.details.[] | [key, .bmc.port] | @csv' "$STATE_FILE")
while IFS=$',' read -r name port; do
export NODE_NAME="$name"
export BMC_IP="$bmc_ip"
export BMC_PORT="$port"
export NAMESPACE="$namespace"
envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" <templates/bmc-machine.tmpl >"$OUTPUT_DIR"/bmc-machine-"$NODE_NAME".yaml
unset NODE_NAME
unset BMC_IP
unset BMC_PORT
unset NAMESPACE
done < <(yq e '.vm.details.[] | [key, .bmc.port] | @csv' "$STATE_FILE")
}

main "$@"
main "$@"
40 changes: 20 additions & 20 deletions capt/scripts/generate_hardware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
set -euo pipefail

function main() {
# Generate hardware
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
declare -r NS=$(yq eval '.namespace' "$STATE_FILE")
# Generate hardware
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
declare -r NS=$(yq eval '.namespace' "$STATE_FILE")

rm -f "$OUTPUT_DIR"/hardware*.yaml
rm -f "$OUTPUT_DIR"/hardware*.yaml

while IFS=$',' read -r name mac role ip gateway; do
export NODE_NAME="$name"
export NODE_MAC="$mac"
export NODE_ROLE="$role"
export NODE_IP="$ip"
export GATEWAY_IP="$gateway"
export NAMESPACE="$NS"
envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" < templates/hardware.tmpl > "$OUTPUT_DIR"/hardware-"$NODE_NAME".yaml
unset NODE_ROLE
unset NODE_NAME
unset NODE_IP
unset NODE_MAC
unset GATEWAY_IP
done < <(yq e '.vm.details.[] | [key, .mac, .role, .ip, .gateway] | @csv' "$STATE_FILE")
while IFS=$',' read -r name mac role ip gateway; do
export NODE_NAME="$name"
export NODE_MAC="$mac"
export NODE_ROLE="$role"
export NODE_IP="$ip"
export GATEWAY_IP="$gateway"
export NAMESPACE="$NS"
envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" <templates/hardware.tmpl >"$OUTPUT_DIR"/hardware-"$NODE_NAME".yaml
unset NODE_ROLE
unset NODE_NAME
unset NODE_IP
unset NODE_MAC
unset GATEWAY_IP
done < <(yq e '.vm.details.[] | [key, .mac, .role, .ip, .gateway] | @csv' "$STATE_FILE")

}

main "$@"
main "$@"
19 changes: 9 additions & 10 deletions capt/scripts/generate_secret.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
# Generate secret. All machines share the same secret. The only customization is the namespace, user name, and password.

function main() {
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
export NAMESPACE=$(yq eval '.namespace' "$STATE_FILE")
export BMC_USER_BASE64=$(yq eval '.virtualBMC.user' "$STATE_FILE" | tr -d '\n' | base64)
export BMC_PASS_BASE64=$(yq eval '.virtualBMC.pass' "$STATE_FILE" | tr -d '\n' | base64)
declare -r STATE_FILE="$1"
declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE")
export NAMESPACE=$(yq eval '.namespace' "$STATE_FILE")
export BMC_USER_BASE64=$(yq eval '.virtualBMC.user' "$STATE_FILE" | tr -d '\n' | base64)
export BMC_PASS_BASE64=$(yq eval '.virtualBMC.pass' "$STATE_FILE" | tr -d '\n' | base64)

envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" < templates/bmc-secret.tmpl > "$OUTPUT_DIR"/bmc-secret.yaml
unset BMC_USER_BASE64
unset BMC_PASS_BASE64
unset NAMESPACE
envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" <templates/bmc-secret.tmpl >"$OUTPUT_DIR"/bmc-secret.yaml
unset BMC_USER_BASE64
unset BMC_PASS_BASE64
unset NAMESPACE
}

main "$@"

92 changes: 46 additions & 46 deletions capt/scripts/generate_state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This script generates the state data needed for creating the CAPT playground.

# state file spec
cat <<EOF > /dev/null
cat <<EOF >/dev/null
---
clusterName: "capt-playground"
outputDir: "/home/tink/repos/tinkerbell/cluster-api-provider-tinkerbell/playground/output"
Expand Down Expand Up @@ -72,61 +72,61 @@ EOF
set -euo pipefail

function generate_mac() {
declare NODE_NAME="$1"
declare NODE_NAME="$1"

echo "$NODE_NAME" | md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/'
echo "$NODE_NAME" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/'
}

function main() {
# read in the config.yaml file and populate the .state file
declare CONFIG_FILE="$1"
declare STATE_FILE="$2"
# read in the config.yaml file and populate the .state file
declare CONFIG_FILE="$1"
declare STATE_FILE="$2"

# update outputDir to be a fully qualified path
output_dir=$(yq eval '.outputDir' "$CONFIG_FILE")
if [[ "$output_dir" = /* ]]; then
echo
else
current_dir=$(pwd)
output_dir="$current_dir/$output_dir"
fi
config_file=$(realpath "$CONFIG_FILE")
state_file="$STATE_FILE"
# update outputDir to be a fully qualified path
output_dir=$(yq eval '.outputDir' "$CONFIG_FILE")
if [[ $output_dir == /* ]]; then
echo
else
current_dir=$(pwd)
output_dir="$current_dir/$output_dir"
fi
config_file=$(realpath "$CONFIG_FILE")
state_file="$STATE_FILE"

cp -a "$config_file" "$state_file"
yq e -i '.outputDir = "'$output_dir'"' "$state_file"
cp -a "$config_file" "$state_file"
yq e -i '.outputDir = "'$output_dir'"' "$state_file"

# totalNodes
total_nodes=$(($(yq eval '.counts.controlPlanes' "$state_file") + $(yq eval '.counts.workers' "$state_file") + $(yq eval '.counts.spares' "$state_file")))
yq e -i ".totalNodes = $total_nodes" "$state_file"
# totalNodes
total_nodes=$(($(yq eval '.counts.controlPlanes' "$state_file") + $(yq eval '.counts.workers' "$state_file") + $(yq eval '.counts.spares' "$state_file")))
yq e -i ".totalNodes = $total_nodes" "$state_file"

# populate vmNames
base_name=$(yq eval '.vm.baseName' "$state_file")
base_ipmi_port=6230
for i in $(seq 1 $total_nodes); do
name="$base_name$i"
mac=$(generate_mac "$name")
yq e -i ".vm.details.$name.mac = \"$mac\"" "$state_file"
yq e -i ".vm.details.$name.bmc.port = $(($base_ipmi_port + $i))" "$state_file"
# set the node role
if [[ $i -le $(yq eval '.counts.controlPlanes' "$state_file") ]]; then
yq e -i ".vm.details.$name.role = \"control-plane\"" "$state_file"
elif [[ $i -le $(($(yq eval '.counts.controlPlanes' "$state_file") + $(yq eval '.counts.workers' "$state_file"))) ]]; then
yq e -i ".vm.details.$name.role = \"worker\"" "$state_file"
else
yq e -i ".vm.details.$name.role = \"spare\"" "$state_file"
fi
unset name
unset mac
done
# populate vmNames
base_name=$(yq eval '.vm.baseName' "$state_file")
base_ipmi_port=6230
for i in $(seq 1 $total_nodes); do
name="$base_name$i"
mac=$(generate_mac "$name")
yq e -i ".vm.details.$name.mac = \"$mac\"" "$state_file"
yq e -i ".vm.details.$name.bmc.port = $((base_ipmi_port + i))" "$state_file"
# set the node role
if [[ $i -le $(yq eval '.counts.controlPlanes' "$state_file") ]]; then
yq e -i ".vm.details.$name.role = \"control-plane\"" "$state_file"
elif [[ $i -le $(($(yq eval '.counts.controlPlanes' "$state_file") + $(yq eval '.counts.workers' "$state_file"))) ]]; then
yq e -i ".vm.details.$name.role = \"worker\"" "$state_file"
else
yq e -i ".vm.details.$name.role = \"spare\"" "$state_file"
fi
unset name
unset mac
done

# populate kind.kubeconfig
yq e -i '.kind.kubeconfig = "'$output_dir'/kind.kubeconfig"' "$state_file"
# populate kind.kubeconfig
yq e -i '.kind.kubeconfig = "'$output_dir'/kind.kubeconfig"' "$state_file"

# populate the expected OS version in the raw image name (22.04 -> 2204)
os_version=$(yq eval '.versions.os' "$state_file")
os_version=$(echo "$os_version" | tr -d '.')
yq e -i '.os.version = "'$os_version'"' "$state_file"
# populate the expected OS version in the raw image name (22.04 -> 2204)
os_version=$(yq eval '.versions.os' "$state_file")
os_version=$(echo "$os_version" | tr -d '.')
yq e -i '.os.version = "'$os_version'"' "$state_file"
}

main "$@"
76 changes: 38 additions & 38 deletions capt/scripts/update_state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ set -euo pipefail
# this script updates the state file with the generated hardware data

function main() {
declare -r STATE_FILE="$1"
declare CLUSTER_NAME=$(yq eval '.clusterName' "$STATE_FILE")
declare GATEWAY_IP=$(docker inspect -f '{{ .NetworkSettings.Networks.kind.Gateway }}' "$CLUSTER_NAME"-control-plane)
declare NODE_IP_BASE=$(awk -F"." '{print $1"."$2".10.20"}' <<< "$GATEWAY_IP")
declare NODE_BASE=$(yq eval '.vm.baseName' "$STATE_FILE")
declare IP_LAST_OCTET=$(echo "$NODE_IP_BASE" | cut -d. -f4)

yq e -i '.kind.gatewayIP = "'$GATEWAY_IP'"' "$STATE_FILE"
yq e -i '.kind.nodeIPBase = "'$NODE_IP_BASE'"' "$STATE_FILE"

# set an ip and gateway per node
idx=1
while IFS=$',' read -r name; do
v=$(echo "$NODE_IP_BASE" | awk -F"." '{print $1"."$2"."$3}').$((IP_LAST_OCTET + idx))
((idx++))
yq e -i ".vm.details.$name.ip = \"$v\"" "$STATE_FILE"
yq e -i ".vm.details.$name.gateway = \"$GATEWAY_IP\"" "$STATE_FILE"
unset v
done < <(yq e '.vm.details.[] | [key] | @csv' "$STATE_FILE")

# set the Tinkerbell Load Balancer IP (VIP)
offset=50
t_lb=$(echo "$NODE_IP_BASE" | awk -F"." '{print $1"."$2"."$3}').$((IP_LAST_OCTET + idx + offset))
yq e -i '.tinkerbell.vip = "'$t_lb'"' "$STATE_FILE"

# set the cluster control plane load balancer IP (VIP)
cp_lb=$(echo "$NODE_IP_BASE" | awk -F"." '{print $1"."$2"."$3}').$((IP_LAST_OCTET + idx + offset + 1))
yq e -i '.cluster.controlPlane.vip = "'$cp_lb'"' "$STATE_FILE"

# set the cluster pod cidr
POD_CIDR=$(awk -F"." '{print $1".100.0.0/16"}' <<< "$GATEWAY_IP")
yq e -i '.cluster.podCIDR = "'$POD_CIDR'"' "$STATE_FILE"

# set the KinD bridge name
network_id=$(docker network inspect -f '{{.Id}}' kind)
bridge_name="br-${network_id:0:12}"
yq e -i '.kind.bridgeName = "'$bridge_name'"' "$STATE_FILE"
declare -r STATE_FILE="$1"
declare CLUSTER_NAME=$(yq eval '.clusterName' "$STATE_FILE")
declare GATEWAY_IP=$(docker inspect -f '{{ .NetworkSettings.Networks.kind.Gateway }}' "$CLUSTER_NAME"-control-plane)
declare NODE_IP_BASE=$(awk -F"." '{print $1"."$2".10.20"}' <<<"$GATEWAY_IP")
declare NODE_BASE=$(yq eval '.vm.baseName' "$STATE_FILE")
declare IP_LAST_OCTET=$(echo "$NODE_IP_BASE" | cut -d. -f4)

yq e -i '.kind.gatewayIP = "'$GATEWAY_IP'"' "$STATE_FILE"
yq e -i '.kind.nodeIPBase = "'$NODE_IP_BASE'"' "$STATE_FILE"

# set an ip and gateway per node
idx=1
while IFS=$',' read -r name; do
v=$(echo "$NODE_IP_BASE" | awk -F"." '{print $1"."$2"."$3}').$((IP_LAST_OCTET + idx))
((idx++))
yq e -i ".vm.details.$name.ip = \"$v\"" "$STATE_FILE"
yq e -i ".vm.details.$name.gateway = \"$GATEWAY_IP\"" "$STATE_FILE"
unset v
done < <(yq e '.vm.details.[] | [key] | @csv' "$STATE_FILE")

# set the Tinkerbell Load Balancer IP (VIP)
offset=50
t_lb=$(echo "$NODE_IP_BASE" | awk -F"." '{print $1"."$2"."$3}').$((IP_LAST_OCTET + idx + offset))
yq e -i '.tinkerbell.vip = "'$t_lb'"' "$STATE_FILE"

# set the cluster control plane load balancer IP (VIP)
cp_lb=$(echo "$NODE_IP_BASE" | awk -F"." '{print $1"."$2"."$3}').$((IP_LAST_OCTET + idx + offset + 1))
yq e -i '.cluster.controlPlane.vip = "'$cp_lb'"' "$STATE_FILE"

# set the cluster pod cidr
POD_CIDR=$(awk -F"." '{print $1".100.0.0/16"}' <<<"$GATEWAY_IP")
yq e -i '.cluster.podCIDR = "'$POD_CIDR'"' "$STATE_FILE"

# set the KinD bridge name
network_id=$(docker network inspect -f '{{.Id}}' kind)
bridge_name="br-${network_id:0:12}"
yq e -i '.kind.bridgeName = "'$bridge_name'"' "$STATE_FILE"

}

main "$@"
main "$@"
Loading

0 comments on commit 19e22d8

Please sign in to comment.