---
apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-proxy-cleanup-script
  namespace: kube-system
  labels:
    app: kubernetes
    gardener.cloud/role: system-component
    origin: gardener
    role: proxy
data:
  cleanup.sh: |
    #!/bin/sh -e
    OLD_KUBE_PROXY_MODE="$(cat "$1")"
    if [ -z "${OLD_KUBE_PROXY_MODE}" ] || [ "${OLD_KUBE_PROXY_MODE}" = "${KUBE_PROXY_MODE}" ]; then
      echo "${KUBE_PROXY_MODE}" >"$1"
      echo "Nothing to cleanup - the mode didn't change."
      exit 0
    fi
    {{- if semverCompare "< 1.17" .Values.kubernetesVersion }}
    /hyperkube
    {{- if semverCompare "< 1.15" .Values.kubernetesVersion }}
    proxy
    {{- else }}
    kube-proxy
    {{- end }}
    {{- else }}
    /usr/local/bin/kube-proxy
    {{- end }} --v=2 --cleanup --config=/var/lib/kube-proxy-config/config.yaml --proxy-mode="${OLD_KUBE_PROXY_MODE}"
    echo "${KUBE_PROXY_MODE}" >"$1"
