cm-router.yaml 847 B

1234567891011121314151617181920
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: {{ include "openvpn.fullname" . }}-routecheck
  5. data:
  6. route.sh: |
  7. while sleep 60
  8. do
  9. /sbin/ip link list {{ .Values.dev_name }} > /dev/null 2>&1
  10. if [ $? -ne 0 ]; then
  11. __server_pod_ip=$(kubectl get po -o json | jq -r '.items[] | select(.metadata.labels.component=="application") | select(.status.phase=="Running").status.podIP')
  12. __route_ip=$(ip route get {{ .Values.net }} | awk '{print $3}')
  13. if [[ $__server_pod_ip != $__route_ip ]]; then
  14. ip route delete {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) > /dev/null 2>&1
  15. ip route add {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) via $__server_pod_ip
  16. fi
  17. fi
  18. done
  19. finish.sh: |
  20. ip route delete {{ .Values.net }}/$(mask2cdr {{ .Values.mask }}) > /dev/null 2>&1