123456789101112131415161718192021222324252627 |
- apiVersion: v1
- kind: ConfigMap
- metadata:
- name: {{ include "openvpn.fullname" . }}-routecheck
- data:
- route-check: |
- set -x
- while true
- do
- date
- /sbin/ip link list {{ .Values.dev_name }} > /dev/null 2>&1
- if [ $? -ne 0 ]; then
- __server_pod_ip=$(kubectl get po -o json | jq -r '.items[] | select(.metadata.labels.component=="application" and .metadata.labels["app.kubernetes.io/instance"]=="{{ .Release.Name }}" and .metadata.labels["app.kubernetes.io/name"]=="{{ include "openvpn.name" . }}" and .metadata.deletionTimestamp==null and .status.phase=="Running").status.podIP')
- __route_ip=$(ip route get {{ .Values.net }} | awk '{print $3}')
- if [[ $__server_pod_ip != $__route_ip ]]; then
- ip route delete {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) > /dev/null 2>&1
- ip route add {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) via $__server_pod_ip
- fi
- elif [ $(ip route show to match {{ .Values.net }} | wc -l) -gt 2 ]; then
- ip route delete {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) > /dev/null 2>&1
- elif [ $(ip route show to match {{ .Values.net }} | wc -l) -le 2 ]; then
- ip route add {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) dev {{ .Values.dev_name }}
- fi
- sleep 60
- done
- route-delete: |
- ip route delete {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) > /dev/null 2>&1
|