github.com/looshlee/cilium@v1.6.12/plugins/cilium-cni/cni-install.sh (about) 1 #!/bin/sh 2 3 set -e 4 5 # Backwards compatibility 6 if [ ! -z "${CILIUM_FLANNEL_MASTER_DEVICE}" ]; then 7 CILIUM_CNI_CHAINING_MODE="flannel" 8 fi 9 10 HOST_PREFIX=${HOST_PREFIX:-/host} 11 12 case "$CILIUM_CNI_CHAINING_MODE" in 13 "flannel") 14 until ip link show "${CILIUM_FLANNEL_MASTER_DEVICE}" &>/dev/null ; do 15 echo "Waiting for ${CILIUM_FLANNEL_MASTER_DEVICE} to be initialized" 16 sleep 1s 17 done 18 CNI_CONF_NAME=${CNI_CONF_NAME:-04-flannel-cilium-cni.conflist} 19 ;; 20 "generic-veth") 21 CNI_CONF_NAME=${CNI_CONF_NAME:-05-cilium.conflist} 22 ;; 23 "portmap") 24 CNI_CONF_NAME=${CNI_CONF_NAME:-05-cilium.conflist} 25 ;; 26 "aws-cni") 27 CNI_CONF_NAME=${CNI_CONF_NAME:-05-cilium.conflist} 28 ;; 29 *) 30 CNI_CONF_NAME=${CNI_CONF_NAME:-05-cilium.conf} 31 ;; 32 esac 33 34 BIN_NAME=cilium-cni 35 CNI_DIR=${CNI_DIR:-${HOST_PREFIX}/opt/cni} 36 CILIUM_CNI_CONF=${CILIUM_CNI_CONF:-${HOST_PREFIX}/etc/cni/net.d/${CNI_CONF_NAME}} 37 38 if [ ! -d ${CNI_DIR}/bin ]; then 39 mkdir -p ${CNI_DIR}/bin 40 fi 41 42 # Install the CNI loopback driver if not installed already 43 if [ ! -f ${CNI_DIR}/bin/loopback ]; then 44 echo "Installing loopback driver..." 45 46 # Don't fail hard if this fails as it is usually not required 47 cp /cni/loopback ${CNI_DIR}/bin/ || true 48 fi 49 50 echo "Installing ${BIN_NAME} to ${CNI_DIR}/bin/ ..." 51 52 # Move an eventual old existing binary out of the way, we can't delete it 53 # as it might be in use right now. 54 if [ -f "${CNI_DIR}/bin/${BIN_NAME}" ]; then 55 rm -f ${CNI_DIR}/bin/${BIN_NAME}.old || true 56 mv ${CNI_DIR}/bin/${BIN_NAME} ${CNI_DIR}/bin/${BIN_NAME}.old 57 fi 58 59 cp /opt/cni/bin/${BIN_NAME} ${CNI_DIR}/bin/ 60 61 if [ "${CILIUM_CUSTOM_CNI_CONF}" = "true" ]; then 62 echo "Using custom ${CILIUM_CNI_CONF}..." 63 exit 0 64 fi 65 66 echo "Installing new ${CILIUM_CNI_CONF}..." 67 case "$CILIUM_CNI_CHAINING_MODE" in 68 "flannel") 69 cat > ${CNI_CONF_NAME} <<EOF 70 { 71 "cniVersion": "0.3.1", 72 "name": "cbr0", 73 "plugins": [ 74 { 75 "type": "flannel", 76 "delegate": { 77 "hairpinMode": true, 78 "isDefaultGateway": true 79 } 80 }, 81 { 82 "type": "portmap", 83 "capabilities": { 84 "portMappings": true 85 } 86 }, 87 { 88 "name": "cilium", 89 "type": "cilium-cni" 90 } 91 ] 92 } 93 EOF 94 ;; 95 96 "portmap") 97 cat > ${CNI_CONF_NAME} <<EOF 98 { 99 "cniVersion": "0.3.1", 100 "name": "portmap", 101 "plugins": [ 102 { 103 "name": "cilium", 104 "type": "cilium-cni" 105 }, 106 { 107 "type": "portmap", 108 "capabilities": {"portMappings": true} 109 } 110 ] 111 } 112 EOF 113 ;; 114 115 "aws-cni") 116 cat > ${CNI_CONF_NAME} <<EOF 117 { 118 "cniVersion": "0.3.1", 119 "name": "aws-cni", 120 "plugins": [ 121 { 122 "name": "aws-cni", 123 "type": "aws-cni", 124 "vethPrefix": "eni" 125 }, 126 { 127 "type": "portmap", 128 "capabilities": {"portMappings": true}, 129 "snat": true 130 }, 131 { 132 "name": "cilium", 133 "type": "cilium-cni" 134 } 135 ] 136 } 137 EOF 138 ;; 139 140 *) 141 cat > ${CNI_CONF_NAME} <<EOF 142 { 143 "cniVersion": "0.3.1", 144 "name": "cilium", 145 "type": "cilium-cni" 146 } 147 EOF 148 ;; 149 esac 150 151 if [ ! -d $(dirname $CILIUM_CNI_CONF) ]; then 152 mkdir -p $(dirname $CILIUM_CNI_CONF) 153 fi 154 155 mv ${CNI_CONF_NAME} ${CILIUM_CNI_CONF} 156 157 # Allow switching between chaining and direct CNI mode by removing the 158 # currently unused configuration file 159 case "${CNI_CONF_NAME}" in 160 "05-cilium.conf") 161 rm ${HOST_PREFIX}/etc/cni/net.d/05-cilium.conflist || true 162 ;; 163 "05-cilium.conflist") 164 rm ${HOST_PREFIX}/etc/cni/net.d/05-cilium.conf || true 165 ;; 166 esac