From 558e24dae194cae92c09610e9f174c368081fd78 Mon Sep 17 00:00:00 2001
From: Jack Henschel <jack.henschel@cern.ch>
Date: Mon, 16 May 2022 09:29:26 +0200
Subject: [PATCH] Add argument for switching publishing of IPv6 records on and
 off

---
 integration-tests.yaml |  2 ++
 publish_dns.sh         | 12 ++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/integration-tests.yaml b/integration-tests.yaml
index db489a4..d4c1258 100644
--- a/integration-tests.yaml
+++ b/integration-tests.yaml
@@ -31,6 +31,8 @@ spec:
           - "example.com"
           # whether to update the external view
           - "false"
+          # whether to publish IPv6 records
+          - "true"
         env:
           - name: DRY_RUN
             value: "true"
diff --git a/publish_dns.sh b/publish_dns.sh
index 20fbf89..a3fbad9 100755
--- a/publish_dns.sh
+++ b/publish_dns.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-if [[ "$#" -ne 4 ]]; then
+if [[ "$#" -ne 5 ]]; then
   echo "Not all arguments have been provided" 1>&2
   exit 1
 fi
@@ -9,6 +9,7 @@ INGRESS_CONTROLLER=$1
 DNS_MANAGER=$2
 ZONE=$3
 REGISTER_IN_EXTERNAL_VIEW=$4
+PUBLISH_IPV6=$5
 
 NSUPDATE_FILE="/tmp/ingress.nsupdate"
 TTL=60
@@ -61,9 +62,12 @@ while sleep 1; do
       continue
     fi
 
-    # first do a reverse lookup of the IPv4 addresses, then do an AAAA lookup for the IPv6 addresses
-    REVERSE_DNS_HOSTNAMES=$(for i in ${IPV4_ADDRESSES}; do dig @"${DNS_MANAGER}" +short -x "$i"; done)
-    IPV6_ADDRESSES=$(for i in ${REVERSE_DNS_HOSTNAMES}; do dig @"${DNS_MANAGER}" +short "$i" AAAA; done)
+    # Sometimes we might want to disable publishing AAAA records for IPv6 addresses of our nodes due to connectivity issues
+    if [ "$PUBLISH_IPV6" = "true" ]; then
+        # first do a reverse lookup of the IPv4 addresses, then do an AAAA lookup for the IPv6 addresses
+        REVERSE_DNS_HOSTNAMES=$(for i in ${IPV4_ADDRESSES}; do dig @"${DNS_MANAGER}" +short -x "$i"; done)
+        IPV6_ADDRESSES=$(for i in ${REVERSE_DNS_HOSTNAMES}; do dig @"${DNS_MANAGER}" +short "$i" AAAA; done)
+    fi
 
     cat <<EOF > ${NSUPDATE_FILE}
 server ${DNS_MANAGER}
-- 
GitLab