Examples/rethinkdb fixes - namespaces, api update, curl params

This commit is contained in:
Marcin Wielgus
2015-07-07 15:27:49 +02:00
parent bb6f2f7ad9
commit 0c25b1c272
7 changed files with 43 additions and 37 deletions

View File

@@ -11,4 +11,4 @@ RUN apt-get update && \
COPY ./run.sh /usr/bin/run.sh
RUN chmod u+x /usr/bin/run.sh
CMD ["/usr/bin/run.sh"]
CMD "/usr/bin/run.sh"

View File

@@ -16,14 +16,21 @@
set -o pipefail
echo Checking for other nodes
IP=""
if [[ -n "${KUBERNETES_RO_SERVICE_HOST}" ]]; then
if [[ -n "${KUBERNETES_SERVICE_HOST}" ]]; then
: ${NAMESPACE:=rethinkdb}
# try to pick up first different ip from endpoints
POD_NAMESPACE=${POD_NAMESPACE:-default}
MYHOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
URL="${KUBERNETES_RO_SERVICE_HOST}/api/v1/namespaces/${NAMESPACE}/endpoints/rethinkdb-driver"
IP=$(curl -s ${URL} | jq -s -r --arg h "${MYHOST}" '.[0].subsets | .[].addresses | [ .[].IP ] | map(select(. != $h)) | .[0]') || exit 1
echo My host: ${MYHOST}
URL="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/api/v1/namespaces/${POD_NAMESPACE}/endpoints/rethinkdb-driver"
echo "Endpont url: ${URL}"
echo "Looking for IPs..."
token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
# try to pick up first different ip from endpoints
IP=$(curl -s ${URL} --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt --header "Authorization: Bearer ${token}" \
| jq -s -r --arg h "${MYHOST}" '.[0].subsets | .[].addresses | [ .[].ip ] | map(select(. != $h)) | .[0]') || exit 1
[[ "${IP}" == null ]] && IP=""
fi