Skip to content

Commit

Permalink
Merge pull request #27 from ardaguclu/ip-already-set-check
Browse files Browse the repository at this point in the history
Check PROVISONING_INTERFACE already has IP belong to different subset
  • Loading branch information
openshift-merge-robot committed Nov 19, 2021
2 parents cee63ad + 4c83af6 commit 45a1c54
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions set-static-ip
Expand Up @@ -17,6 +17,17 @@ if [ -z "$PROVISIONING_INTERFACE" ]; then
fi

if [ -n "$PROVISIONING_INTERFACE" ]; then
# Check provisioning interface is already set to ip address
if [[ -n $(ip -o addr show dev "${PROVISIONING_INTERFACE}" scope global) ]]; then
# equality check can be done for IPv4, i.e. 172.22.0.3/24
# for IPv6 and dualstack(IPv4v6), fd00:1101::x/64 is used as fd00:1101::xxxx:xxxx:xxxx:xxxx/128
# Thus, we need to parse provisioning ip with '::'.
if ! ip -o addr show dev "${PROVISIONING_INTERFACE}" scope global | grep -q "${PROVISIONING_IP//::*/}" ; then
echo "ERROR: \"$PROVISIONING_INTERFACE\" is already set to ip address belong to different subset than \"$PROVISIONING_IP\""
exit 1
fi
fi

# Get rid of any DHCP addresses on the dedicated provisioning interface
/usr/sbin/ip address flush dev "$PROVISIONING_INTERFACE"

Expand Down

0 comments on commit 45a1c54

Please sign in to comment.