diff --git a/cni-plugin/deployment/scripts/install-cni.sh b/cni-plugin/deployment/scripts/install-cni.sh index 3752acd8..bcb277ff 100755 --- a/cni-plugin/deployment/scripts/install-cni.sh +++ b/cni-plugin/deployment/scripts/install-cni.sh @@ -31,7 +31,7 @@ set -u -e # Usage: # some_command || exit_with_error "some_command_failed: maybe try..." exit_with_error() { - echo "${1}" + log "${1}" exit 1 } @@ -53,7 +53,7 @@ CONTAINER_MOUNT_PREFIX=${CONTAINER_MOUNT_PREFIX:-/host} CONTAINER_CNI_BIN_DIR=${CONTAINER_CNI_BIN_DIR:-/opt/cni/bin} # Directory path where CNI configuration should live on the host HOST_CNI_NET="${CONTAINER_MOUNT_PREFIX}${DEST_CNI_NET_DIR}" -# Default path for when linkerd runs as a standalone CNI plugin +# Location of legacy "interface mode" file, to be automatically deleted DEFAULT_CNI_CONF_PATH="${HOST_CNI_NET}/01-linkerd-cni.conf" KUBECONFIG_FILE_NAME=${KUBECONFIG_FILE_NAME:-ZZZ-linkerd-cni-kubeconfig} @@ -63,16 +63,15 @@ KUBECONFIG_FILE_NAME=${KUBECONFIG_FILE_NAME:-ZZZ-linkerd-cni-kubeconfig} # Cleanup will remove any installed configuration from the host If there are any # *conflist files, then linkerd-cni configuration parameters will be removed -# from them; otherwise, if linkerd-cni is the only plugin, the configuration -# file will be removed. +# from them. cleanup() { # First, kill 'inotifywait' so we don't process any DELETE/CREATE events if [ "$(pgrep inotifywait)" ]; then - echo 'Sending SIGKILL to inotifywait' + log 'Sending SIGKILL to inotifywait' kill -s KILL "$(pgrep inotifywait)" fi - echo 'Removing linkerd-cni artifacts.' + log 'Removing linkerd-cni artifacts.' # Find all conflist files and print them out using a NULL separator instead of # writing each file in a new line. We will subsequently read each string and @@ -80,38 +79,31 @@ cleanup() { local cni_data='' find "${HOST_CNI_NET}" -maxdepth 1 -type f \( -iname '*conflist' \) -print0 | while read -r -d $'\0' file; do - echo "Removing linkerd-cni config from $file" + log "Removing linkerd-cni config from $file" cni_data=$(jq 'del( .plugins[]? | select( .type == "linkerd-cni" ))' "$file") # TODO (matei): we should write this out to a temp file and then do a `mv` # to be atomic. echo "$cni_data" > "$file" done - # Check whether configuration file has been created by our own cni plugin - # and if so, rm it. - if [ -e "${DEFAULT_CNI_CONF_PATH}" ]; then - echo "Cleaning up ${DEFAULT_CNI_CONF_PATH}" - rm -f "${DEFAULT_CNI_CONF_PATH}" - fi - # Remove binary and kubeconfig file if [ -e "${HOST_CNI_NET}/${KUBECONFIG_FILE_NAME}" ]; then - echo "Removing linkerd-cni kubeconfig: ${HOST_CNI_NET}/${KUBECONFIG_FILE_NAME}" + log "Removing linkerd-cni kubeconfig: ${HOST_CNI_NET}/${KUBECONFIG_FILE_NAME}" rm -f "${HOST_CNI_NET}/${KUBECONFIG_FILE_NAME}" fi if [ -e "${CONTAINER_MOUNT_PREFIX}${DEST_CNI_BIN_DIR}"/linkerd-cni ]; then - echo "Removing linkerd-cni binary: ${CONTAINER_MOUNT_PREFIX}${DEST_CNI_BIN_DIR}/linkerd-cni" + log "Removing linkerd-cni binary: ${CONTAINER_MOUNT_PREFIX}${DEST_CNI_BIN_DIR}/linkerd-cni" rm -f "${CONTAINER_MOUNT_PREFIX}${DEST_CNI_BIN_DIR}/linkerd-cni" fi - echo 'Exiting.' + log 'Exiting.' exit 0 } # Capture the usual signals and exit from the script -trap 'echo "SIGINT received, simply exiting..."; cleanup' INT -trap 'echo "SIGTERM received, simply exiting..."; cleanup' TERM -trap 'echo "SIGHUP received, simply exiting..."; cleanup' HUP +trap 'log "SIGINT received, simply exiting..."; cleanup' INT +trap 'log "SIGTERM received, simply exiting..."; cleanup' TERM +trap 'log "SIGHUP received, simply exiting..."; cleanup' HUP # Copy the linkerd-cni binary to a known location where CNI will look. install_cni_bin() { @@ -124,7 +116,7 @@ install_cni_bin() { cp "${path}" "${dir}"/ || exit_with_error "Failed to copy ${path} to ${dir}." done - echo "Wrote linkerd CNI binaries to ${dir}" + log "Wrote linkerd CNI binaries to ${dir}" } create_cni_conf() { @@ -137,10 +129,10 @@ create_cni_conf() { # If the CNI Network Config has been overwritten, then use template from file if [ -e "${CNI_NETWORK_CONFIG_FILE}" ]; then - echo "Using CNI config template from ${CNI_NETWORK_CONFIG_FILE}." + log "Using CNI config template from ${CNI_NETWORK_CONFIG_FILE}." cp "${CNI_NETWORK_CONFIG_FILE}" "${TMP_CONF}" elif [ "${CNI_NETWORK_CONFIG}" ]; then - echo 'Using CNI config template from CNI_NETWORK_CONFIG environment variable.' + log 'Using CNI config template from CNI_NETWORK_CONFIG environment variable.' cat >"${TMP_CONF}" <