piraeusdatastore / piraeus

High Available Datastore for Kubernetes

Home Page:https://piraeus.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Piraeus doesn't support IPv6

Frankkkkk opened this issue · comments

Hi,
Piraeus doesn't seem to support IPv6-only clusters.

I've found at least 2 IPv4-only things to fix, but there are likely many more:

diff --git a/dockerfiles/piraeus-init/bin/init-etcd.sh b/dockerfiles/piraeus-init/bin/init-etcd.sh
index 271fa6c..11d026d 100755
--- a/dockerfiles/piraeus-init/bin/init-etcd.sh
+++ b/dockerfiles/piraeus-init/bin/init-etcd.sh
@@ -5,12 +5,19 @@ pod_sts="${POD_NAME/-[0-9]*/}"
 
 cluster=$( seq 0 $(( CLUSTER_SIZE - 1 )) | xargs -tI % echo "${pod_sts}-%=http://${pod_sts}-%.${pod_sts}:${PEER_PORT}" | paste -sd "," - )
 
+if [[ $POD_IP =~ .*:.* ]]; then
+       POD_IP="[$POD_IP]"
+       LOCALHOST='[::1]'
+else
+       LOCALHOST='127.0.0.1'
+fi
+
 # write config file
 cat > /init/etc/etcd/etcd.conf << EOF
 name:                        ${POD_NAME}
 max-txn-ops:                 1024
 listen-peer-urls:            http://${POD_IP}:${PEER_PORT}
-listen-client-urls:          http://${POD_IP}:${CLIENT_PORT},http://127.0.0.1:${CLIENT_PORT}
+listen-client-urls:          http://${POD_IP}:${CLIENT_PORT},http://${LOCALHOST}:${CLIENT_PORT}
 advertise-client-urls:       http://${POD_IP}:${CLIENT_PORT}
 initial-advertise-peer-urls: http://${POD_IP}:${PEER_PORT}
 initial-cluster-token:       ${pod_sts}
diff --git a/dockerfiles/piraeus-init/bin/lib.tools.sh b/dockerfiles/piraeus-init/bin/lib.tools.sh
index 6afea1f..4d30ace 100644
--- a/dockerfiles/piraeus-init/bin/lib.tools.sh
+++ b/dockerfiles/piraeus-init/bin/lib.tools.sh
@@ -1,9 +1,19 @@
 #!/bin/bash
 
 _get_ip_by_if() {
-    ip -f inet address | grep -w "$1" | awk '/inet / {print $2}' | sed 's#/.*##'
+    if [[ $1 =~ .*:.* ]]; then
+        inet=inet6
+    else
+        inet=inet
+    fi
+    ip -f $inet address | grep -w "$1" | awk "/$inet / {print \$2}" | sed 's#/.*##'
 }
 
 _get_if_by_ip() {
-    ip -f inet address | grep -B1 "inet $1" | head -1 | awk '{print $2}' | sed 's/://g'
-}
\ No newline at end of file
+    if [[ $1 =~ .*:.* ]]; then
+        inet=inet6
+    else
+        inet=inet
+    fi
+    ip -f $inet address | grep -B1 "$inet $1" | head -1 | awk '{print $2}' | sed 's/://g'
+}

Cheers