# If you encounter "SSL certification error (subject name does not match the host name)", you may try to set DOCKER_VERNEMQ_KUBERNETES_INSECURE to "1".
# Cluster discovery implementation based on https://github.com/thesandlord/kubernetes-pod-ip-finder
insecure=""
if env | grep-q"KUBE_VERNEMQ_DISCOVERY_URL";then
if env | grep-q"DOCKER_VERNEMQ_KUBERNETES_INSECURE";then
response=$(curl ${KUBE_VERNEMQ_DISCOVERY_URL})
insecure="--insecure"
IFS=','
fi
nodes=($(echo"$response" | tr -d'[]"'))
length=$(echo${#nodes[@]})
if env | grep-q"DOCKER_VERNEMQ_DISCOVERY_KUBERNETES";then
for i in"${nodes[@]}"
# Let's set our nodename correctly
VERNEMQ_KUBERNETES_SUBDOMAIN=$(curl -X GET $insecure--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt https://kubernetes.default.svc.cluster.local/api/v1/namespaces/$DOCKER_VERNEMQ_KUBERNETES_NAMESPACE/pods?labelSelector=app=$DOCKER_VERNEMQ_KUBERNETES_APP_LABEL-H"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" | jq '.items[0].spec.subdomain' | sed 's/"//g' | tr '\n''\0')
echo"Anyway, we won't attempt to join any cluster."
break
fi
if[$kube_pod_name!=$MY_POD_NAME]
then
echo"Will join an existing Kubernetes cluster with discovery node at ${kube_pod_name}.${VERNEMQ_KUBERNETES_SUBDOMAIN}.${DOCKER_VERNEMQ_KUBERNETES_NAMESPACE}.svc.cluster.local"