github.com/looshlee/cilium@v1.6.12/plugins/cilium-cni/cni-uninstall.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  function uninstall_cilium_from_flannel_master() {
     6      CNI_MASTER_DEVICE="${1}"
     7      # Those are the settings set by default from flannel
     8      [[ "$(tc filter show dev "${CNI_MASTER_DEVICE}" egress)" != "" ]] && \
     9          tc filter delete dev "${CNI_MASTER_DEVICE}" egress pref 1 handle 1 bpf || \
    10          echo 1 > "/proc/sys/net/ipv4/conf/${CNI_MASTER_DEVICE}/forwarding" && \
    11          echo 1 > "/proc/sys/net/ipv4/conf/${CNI_MASTER_DEVICE}/rp_filter" && \
    12          echo 0 > "/proc/sys/net/ipv4/conf/${CNI_MASTER_DEVICE}/accept_local" && \
    13          echo 1 > "/proc/sys/net/ipv4/conf/${CNI_MASTER_DEVICE}/send_redirects" && \
    14          echo 1 > "/proc/sys/net/ipv4/conf/all/rp_filter"
    15  }
    16  
    17  function uninstall_cilium_from_pod() {
    18      POD_VETH_SIDE_PAIR="${1}"
    19      [[ "$(tc filter show dev "${POD_VETH_SIDE_PAIR}" ingress)" != "" ]] && \
    20          tc filter delete dev "${POD_VETH_SIDE_PAIR}" ingress pref 1 handle 1 bpf || \
    21          echo 1 > "/proc/sys/net/ipv4/conf/${POD_VETH_SIDE_PAIR}/rp_filter"
    22  }
    23  
    24  function get_list_of_veth_from_bridge() {
    25      CNI_MASTER_DEVICE="${1}"
    26      echo "$(ip -o link show master "${CNI_MASTER_DEVICE}" type veth | awk '{print $2}' | sed 's/@.*//g')"
    27  }
    28  
    29  HOST_PREFIX=${HOST_PREFIX:-/host}
    30  BIN_NAME=cilium-cni
    31  CNI_DIR=${CNI_DIR:-${HOST_PREFIX}/opt/cni}
    32  
    33  echo "Removing ${CNI_DIR}/bin/cilium-cni..."
    34  rm -f ${CNI_DIR}/bin/${BIN_NAME}
    35  rm -f ${CNI_DIR}/bin/${BIN_NAME}.old
    36  
    37  if [[ "${CILIUM_FLANNEL_UNINSTALL_ON_EXIT}" == "true" ]]; then
    38      echo "Removing BPF programs from all containers and from ${CILIUM_FLANNEL_MASTER_DEVICE}"
    39      echo "Uninstalling cilium from ${CILIUM_FLANNEL_MASTER_DEVICE}"
    40      uninstall_cilium_from_flannel_master "${CILIUM_FLANNEL_MASTER_DEVICE}"
    41  
    42      for iDev in $(get_list_of_veth_from_bridge "${CILIUM_FLANNEL_MASTER_DEVICE}"); do
    43          echo "Uninstalling cilium from ${iDev}"
    44          uninstall_cilium_from_pod ${iDev}
    45      done
    46  fi