Skip to content

Commit

Permalink
OCTOPUS-512: improve route support between pvs instances and harden u…
Browse files Browse the repository at this point in the history
…pload_rhcos_image when the ibmcloud command is out-of-date

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
  • Loading branch information
prb112 committed Oct 27, 2023
1 parent 7560d97 commit 1e76679
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
90 changes: 90 additions & 0 deletions modules/4_pvs_support/files/static-route.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

################################################################
# Copyright 2023 - IBM Corporation. All rights reserved
# SPDX-License-Identifier: Apache-2.0
################################################################

# This script updates the dhcpd config.

# Desired results:
# option rfc3442-classless-static-routes code 121 = array of integer 8;
# option rfc3442-classless-static-routes 24, 10, 248, 0, 192, 168, 200, 1;

# We shouldn't need the following, copying here for future dev, if needed.
# option ms-classless-static-routes code 249 = array of integer 8;
# option ms-classless-static-routes 24, 10, 248, 0, 192, 168, 200, 1;

if [ ! -f /etc/dhcp/classless-static-routes.conf ]
then
cat << EOF > /etc/dhcp/classless-static-routes.conf
option rfc3442-classless-static-routes code 121 = array of integer 8;
EOF

source route.env

# Gateway formated
GATEWAY_FORMAT="$(echo ${PVS_GATEWAY} | sed 's|\.|,|g')"
echo "GATEWAY_FORMAT: ${GATEWAY_FORMAT}"

# CONDITIONAL_COMMA [,]
# SUBNET_MASK /24
# SUBNET 10, 248, 0,
# 192, 168, 200, 1 GATEWAY_FORMAT
echo -n "option rfc3442-classless-static-routes" >> /etc/dhcp/classless-static-routes.conf
PRIOR=""
for i in "${!entries[@]}"; do
echo "Creating static-route entry: ${entries[$i]}"
if [ -n "${PRIOR}" ]
then
echo -n "," >> /etc/dhcp/classless-static-routes.conf
else
PRIOR="IN-USE"
fi

SUBNET_MASK=$(echo ${entries[$i]} | sed 's|/| |g' | awk '{print $NF}')

# Dev Test:
#SUBNET=$(echo "192.168.200.0/24" | sed 's|/| |g' | awk '{print $1}' | sed 's|\.| |g')
SUBNET=($(echo ${entries[$i]} | sed 's|/| |g' | awk '{print $1}' | sed 's|\.| |g'))

# DHCPD requires a mask in a special form. We're relying on subnet masks and greatest bits determining how many numbers we include.
SUBNET_STR=""
if [ ${SUBNET_MASK} -gt 25 ]
then
echo "subnet needs four places"
SUBNET_STR="${SUBNET[0]},${SUBNET[1]},${SUBNET[2]},${SUBNET[3]}"
elif [ ${SUBNET_MASK} -gt 16 ]
then
echo "subnet needs tree places"
SUBNET_STR="${SUBNET[0]},${SUBNET[1]},${SUBNET[2]}"
elif [ ${SUBNET_MASK} -gt 8 ]
then
echo "subnet needs two places"
SUBNET_STR="${SUBNET[0]},${SUBNET[1]}"
else
echo "subnet needs one place"
SUBNET_STR="${SUBNET[0]}"
fi
echo ${SUBNET_STR}

echo -n " ${SUBNET_MASK}, ${SUBNET_STR}, ${GATEWAY_FORMAT}" >> /etc/dhcp/classless-static-routes.conf
done
echo ";" >> /etc/dhcp/classless-static-routes.conf

echo "Static routes are:"
cat /etc/dhcp/classless-static-routes.conf

echo "Restarting the dhcpd"
systemctl restart dhcpd

# Need to login to each Power Node
for NODE_IP in $(oc get nodes -l kubernetes.io/arch=ppc64le -owide --no-headers=true| awk '
{print $6}')
do
ssh core@${NODE_IP} sudo systemctl restart NetworkManager
done

else
echo "Skipping the static route assignement, file exists"
fi
14 changes: 14 additions & 0 deletions modules/4_pvs_support/pvs_support.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,25 @@ resource "null_resource" "setup" {
destination = "ocp4-upi-compute-powervs-ibmcloud/intel/support/route-env3.sh"
}

# Copies the custom routes for dhcp
provisioner "file" {
source = "${path.module}/files/static-route.sh"
destination = "/root/ocp4-upi-compute-powervs-ibmcloud/intel/support/static-route.sh"
}

# Copies the custom route for env3
provisioner "file" {
content = templatefile("${path.module}/templates/route.env.tpl", local.cidrs)
destination = "/root/ocp4-upi-compute-powervs-ibmcloud/intel/support/route.env"
}

provisioner "remote-exec" {
inline = [<<EOF
cd ocp4-upi-compute-powervs-ibmcloud/intel/support
bash route-env3.sh
bash static-route.sh
echo 'Running ocp4-upi-compute-powervs-ibmcloud/intel/ playbook...'
ANSIBLE_LOG_PATH=/root/.openshift/ocp4-upi-compute-powervs-ibmcloud-support-main.log ansible-playbook -e @vars/vars.yaml tasks/main.yml --become
EOF
Expand Down
17 changes: 17 additions & 0 deletions modules/4_pvs_support/templates/route.env.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

################################################################
# Copyright 2023 - IBM Corporation. All rights reserved
# SPDX-License-Identifier: Apache-2.0
################################################################

# Variables:
export PVS_GATEWAY=${gateway}

# The template (bash array) is going to be filled with the ipv4 cidrs
# entries[1]=10.248.0.0/24
declare -a entries
%{ for index, cidr in cidrs_ipv4 ~}
entries[${format("%d", index + 1)}]="${cidr}"
%{ endfor ~}
export PVS_GATEWAY
2 changes: 2 additions & 0 deletions modules/5_image/files/upload_rhcos_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ if [ -z "$(command -v ibmcloud)" ]
then
echo "ibmcloud CLI doesn't exist, installing"
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
else
ibmcloud update -f
fi

ibmcloud login --apikey "${API_KEY}" -r "${REGION}" -g "${RESOURCE_GROUP}"
Expand Down

0 comments on commit 1e76679

Please sign in to comment.