Skip to content

Commit

Permalink
Add stats and metadata wasm plugin into proxy image (istio#20259)
Browse files Browse the repository at this point in the history
* add stats and mx wasm plugin into proxy image

* simplify wasm plugins downloading

* format & clean up
  • Loading branch information
bianpengyuan authored and istio-testing committed Jan 21, 2020
1 parent a0fce32 commit 07dedc3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ $(ISTIO_OUT)/istio_is_init: bin/init.sh istio.deps | $(ISTIO_OUT)
ISTIO_OUT=$(ISTIO_OUT) ISTIO_BIN=$(ISTIO_BIN) bin/init.sh
touch $(ISTIO_OUT)/istio_is_init

# init.sh downloads envoy
# init.sh downloads envoy and webassembly plugins
${ISTIO_OUT}/envoy: init
${ISTIO_ENVOY_LINUX_DEBUG_PATH}: init
${ISTIO_ENVOY_LINUX_RELEASE_PATH}: init
Expand Down
38 changes: 38 additions & 0 deletions bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ function download_envoy_if_necessary () {
fi
}

# Downloads WebAssembly based plugin if it doesn't already exist.
# Params:
# $1: The URL of the WebAssembly file to be downloaded.
# $2: The full path of the output file.
function download_wasm_if_necessary () {
download_file_dir="$(dirname "$2")"
download_file_name="$(basename "$1")"
download_file_path="${download_file_dir}/${download_file_name}"
if [[ ! -f "${download_file_path}" ]] ; then
# Enter the output directory.
mkdir -p "${download_file_dir}"
pushd "${download_file_dir}"

# Download the WebAssembly plugin files to the output directory.
echo "Downloading WebAssembly file: ${DOWNLOAD_COMMAND} $1 to ${download_file_path}"
if [[ ${DOWNLOAD_COMMAND} == curl* ]]; then
time ${DOWNLOAD_COMMAND} --header "${AUTH_HEADER:-}" "$1" -o "${download_file_name}"
elif [[ ${DOWNLOAD_COMMAND} == wget* ]]; then
time ${DOWNLOAD_COMMAND} --header "${AUTH_HEADER:-}" "$1" -O "${download_file_name}"
fi

# Copy the webassembly file to the output location
cp "${download_file_path}" "$2"
popd
fi
}

# Included for support on macOS.
function realpath () {
python -c "import os; print(os.path.realpath('$1'))"
Expand Down Expand Up @@ -196,6 +223,17 @@ else
ISTIO_ENVOY_NATIVE_PATH=${ISTIO_ENVOY_LINUX_RELEASE_PATH}
fi

# Donwload WebAssembly plugin files
WASM_RELEASE_DIR=${ISTIO_ENVOY_LINUX_RELEASE_DIR}
if [[ "$LOCAL_OS" == "Darwin" ]]; then
WASM_RELEASE_DIR=${ISTIO_ENVOY_MACOS_RELEASE_DIR}
fi
for plugin in stats metadata_exchange
do
FILTER_WASM_URL="${ISTIO_ENVOY_BASE_URL}/${plugin}-${ISTIO_ENVOY_VERSION}.wasm"
download_wasm_if_necessary "${FILTER_WASM_URL}" "${WASM_RELEASE_DIR}"/"${plugin//_/-}"-filter.wasm
done

# Copy native envoy binary to ISTIO_OUT
echo "Copying ${ISTIO_ENVOY_NATIVE_PATH} to ${ISTIO_OUT}/envoy"
cp -f "${ISTIO_ENVOY_NATIVE_PATH}" "${ISTIO_OUT}/envoy"
Expand Down
3 changes: 3 additions & 0 deletions pilot/docker/Dockerfile.proxyv2
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ COPY envoy_pilot.yaml.tmpl /etc/istio/proxy/envoy_pilot.yaml.tmpl
COPY envoy_policy.yaml.tmpl /etc/istio/proxy/envoy_policy.yaml.tmpl
COPY envoy_telemetry.yaml.tmpl /etc/istio/proxy/envoy_telemetry.yaml.tmpl

COPY stats-filter.wasm /etc/istio/proxy/stats-filter.wasm
COPY metadata-exchange-filter.wasm /etc/istio/proxy/metadata-exchange-filter.wasm

# The pilot-agent will bootstrap Envoy.
ENTRYPOINT ["/usr/local/bin/pilot-agent"]
2 changes: 2 additions & 0 deletions tools/istio-docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ docker.proxyv2: pilot/docker/envoy_pilot.yaml.tmpl
docker.proxyv2: pilot/docker/envoy_policy.yaml.tmpl
docker.proxyv2: pilot/docker/envoy_telemetry.yaml.tmpl
docker.proxyv2: $(ISTIO_DOCKER)/istio-iptables
docker.proxyv2: $(ISTIO_ENVOY_LINUX_RELEASE_DIR)/stats-filter.wasm
docker.proxyv2: $(ISTIO_ENVOY_LINUX_RELEASE_DIR)/metadata-exchange-filter.wasm
$(DOCKER_RULE)

# Proxy using TPROXY interception - but no core dumps
Expand Down

0 comments on commit 07dedc3

Please sign in to comment.