Skip to content

Commit

Permalink
Cleanup dual-stack VIPs logic (#1470)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Stäbler <cstabler@redhat.com>

Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
  • Loading branch information
creydr authored Oct 26, 2022
1 parent 68b07b9 commit 2c5cb67
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
4 changes: 2 additions & 2 deletions agent/04_agent_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ spec:
EOF
if [[ "${NUM_MASTERS}" > "1" ]]; then
cat >> "${MANIFESTS_PATH}/agent-cluster-install.yaml" << EOF
apiVIP: ${API_VIPs%${STRINGS_SEPARATOR}*}
ingressVIP: ${INGRESS_VIPs%${STRINGS_SEPARATOR}*}
apiVIP: ${API_VIPS%${VIPS_SEPARATOR}*}
ingressVIP: ${INGRESS_VIPS%${VIPS_SEPARATOR}*}
EOF
fi

Expand Down
54 changes: 30 additions & 24 deletions network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function wrap_if_ipv6(){
echo "$1"
}

export STRINGS_SEPARATOR=","
export VIPS_SEPARATOR=","
export PATH_CONF_DNSMASQ="/etc/NetworkManager/dnsmasq.d/openshift-${CLUSTER_NAME}.conf"

export IP_STACK=${IP_STACK:-"v6"}
Expand Down Expand Up @@ -195,22 +195,25 @@ if [ -n "${NETWORK_CONFIG_FOLDER:-}" ]; then
NETWORK_CONFIG_FOLDER="$(readlink -m $NETWORK_CONFIG_FOLDER)"
fi

function is_varset_add_comma() {
function concat_parameters_with_vipsseparator() {
# Description:
# Adds a comma between both given parameters. If only one parameter is
# given, no comma is added and only the given parameter printed. Useful
# for multiple API_VIPs or INGRESS_VIPs Example:
# 192.168.111.5,fd2e:6f44:5dd8:c956::14
# Adds ${VIPS_SEPARATOR} between all given parameters.
#
# Returns:
# Print the string using comma
# Print all given parameters with ${VIPS_SEPARATOR} in between.

ARG_NR=1
RESULT=""
for ARG in "$@"; do
RESULT+="${ARG}"
if [[ $ARG_NR -lt $# ]]; then
RESULT+="${VIPS_SEPARATOR}"
fi

# if string is *NOT* NULL/empty
if [[ $# -ge 2 ]]; then
echo "$1,$2"
else
echo "$1"
fi
ARG_NR=$((ARG_NR+1))
done

echo "${RESULT}"
}

function get_vips() {
Expand All @@ -224,14 +227,17 @@ function get_vips() {
# None
#
if [[ -n "${EXTERNAL_SUBNET_V4}" ]]; then
API_VIPs=$(dig +noall +answer "api.${CLUSTER_DOMAIN}" @$(network_ip ${BAREMETAL_NETWORK_NAME}) | awk '{print $NF}')
INGRESS_VIPs=$(nth_ip $EXTERNAL_SUBNET_V4 4)
API_VIPS_V4=$(dig +noall +answer "api.${CLUSTER_DOMAIN}" @$(network_ip ${BAREMETAL_NETWORK_NAME}) | awk '{print $NF}')
INGRESS_VIPS_V4=$(nth_ip $EXTERNAL_SUBNET_V4 4)
fi

if [[ -n "${EXTERNAL_SUBNET_V6}" ]]; then
API_VIPs=$(is_varset_add_comma ${API_VIPs} $(dig -t AAAA +noall +answer "api.${CLUSTER_DOMAIN}" @$(network_ip ${BAREMETAL_NETWORK_NAME}) | awk '{print $NF}'))
INGRESS_VIPs=$(is_varset_add_comma ${INGRESS_VIPs} $(nth_ip $EXTERNAL_SUBNET_V6 4))
API_VIPS_V6=$(dig -t AAAA +noall +answer "api.${CLUSTER_DOMAIN}" @$(network_ip ${BAREMETAL_NETWORK_NAME}) | awk '{print $NF}')
INGRESS_VIPS_V6=$(nth_ip $EXTERNAL_SUBNET_V6 4)
fi

API_VIPS=$(concat_parameters_with_vipsseparator ${API_VIPS_V4:-} ${API_VIPS_V6:-})
INGRESS_VIPS=$(concat_parameters_with_vipsseparator ${INGRESS_VIPS_V4:-} ${INGRESS_VIPS_V6:-})
}


Expand All @@ -247,7 +253,7 @@ function add_dnsmasq_multi_entry() {
#
# Returns:
# None
for i in ${2//${STRINGS_SEPARATOR}/ }; do
for i in ${2//${VIPS_SEPARATOR}/ }; do
if [ "${1}" = "apivip" ] ; then
echo "address=/api.${CLUSTER_DOMAIN}/${i}" | sudo tee -a "${PATH_CONF_DNSMASQ}"
fi
Expand All @@ -258,16 +264,16 @@ function add_dnsmasq_multi_entry() {
done
}

set_api_and_ingress_vip() {
function set_api_and_ingress_vip() {
# NOTE: This is equivalent to the external API DNS record pointing the API to the API VIP
if [ "$MANAGE_BR_BRIDGE" == "y" ] ; then
get_vips

# make sure the dns_masq config file is cleaned up (add_dnsmasq_multi_entry() only appends)
rm -f "${PATH_CONF_DNSMASQ}"

add_dnsmasq_multi_entry "apivip" "${API_VIPs}"
add_dnsmasq_multi_entry "ingressvip" "${INGRESS_VIPs}"
add_dnsmasq_multi_entry "apivip" "${API_VIPS}"
add_dnsmasq_multi_entry "ingressvip" "${INGRESS_VIPS}"

echo "listen-address=::1" | sudo tee -a "${PATH_CONF_DNSMASQ}"

Expand All @@ -279,10 +285,10 @@ set_api_and_ingress_vip() {
else
# Specific for users *NOT* using devscript with KVM (virsh) for deploy. (Reads: baremetal)
if [[ -z "${EXTERNAL_SUBNET_V4}" ]]; then
API_VIPs=$(dig -t AAAA +noall +answer "api.${CLUSTER_DOMAIN}" | awk '{print $NF}')
API_VIPS=$(dig -t AAAA +noall +answer "api.${CLUSTER_DOMAIN}" | awk '{print $NF}')
else
API_VIPs=$(dig +noall +answer "api.${CLUSTER_DOMAIN}" | awk '{print $NF}')
API_VIPS=$(dig +noall +answer "api.${CLUSTER_DOMAIN}" | awk '{print $NF}')
fi
INGRESS_VIPs=$(dig +noall +answer "test.apps.${CLUSTER_DOMAIN}" | awk '{print $NF}')
INGRESS_VIPS=$(dig +noall +answer "test.apps.${CLUSTER_DOMAIN}" | awk '{print $NF}')
fi
}
13 changes: 6 additions & 7 deletions ocp_install_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ function renderVIPs() {
#
# Returns:
# YAML formatted resource
STRINGS_SEPARATOR=","
resource="${2}";
FIELD_VALUES="${2}";

echo " ${1}"
for data in ${resource//${STRINGS_SEPARATOR}/ }; do
for data in ${FIELD_VALUES//${VIPS_SEPARATOR}/ }; do
echo " - ${data}"
done
}
Expand All @@ -156,19 +155,19 @@ function setVIPs() {
"apivips")
if printf '4.12\n%s\n' "$(openshift_version)" | sort -V -C; then
# OCP version is equals or newer as 4.12 and supports the new VIPs fields
renderVIPs "apiVIPs:" "${API_VIPs}"
renderVIPs "apiVIPs:" "${API_VIPS}"
else
# OCP version is older as 4.12 and does not support the new VIPs fields
echo " apiVIP: ${API_VIPs%${STRINGS_SEPARATOR}*}"
echo " apiVIP: ${API_VIPS%${VIPS_SEPARATOR}*}"
fi
;;
"ingressvips")
if printf '4.12\n%s\n' "$(openshift_version)" | sort -V -C; then
# OCP version is equals or newer as 4.12 and supports the new VIPs fields
renderVIPs "ingressVIPs:" "${INGRESS_VIPs}"
renderVIPs "ingressVIPs:" "${INGRESS_VIPS}"
else
# OCP version is older as 4.12 and does not support the new VIPs fields
echo " ingressVIP: ${INGRESS_VIPs%${STRINGS_SEPARATOR}*}"
echo " ingressVIP: ${INGRESS_VIPS%${VIPS_SEPARATOR}*}"
fi
;;
esac
Expand Down

0 comments on commit 2c5cb67

Please sign in to comment.