Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move WASM to components.json #4969

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
776c569
test our rework with no logic changes (kinda)
AlisonB319 Sep 12, 2024
f02e473
only download wasm once
AlisonB319 Sep 12, 2024
ce1fd94
use the right function
AlisonB319 Sep 12, 2024
0900019
try to perserve timesave
AlisonB319 Sep 13, 2024
80132e7
add something for the tester function
AlisonB319 Sep 13, 2024
9e84123
fix filepath var
AlisonB319 Sep 16, 2024
2f7e52a
general cleanup no logic changes
AlisonB319 Sep 16, 2024
9a2ec57
try switching things around
AlisonB319 Sep 16, 2024
9fd22fb
trying to figure out the URL
AlisonB319 Sep 17, 2024
271c341
Add debugging message
AlisonB319 Sep 17, 2024
f37888f
i don't think this will work with the array
AlisonB319 Sep 17, 2024
020609e
reworking all in cse_install file
AlisonB319 Sep 17, 2024
d260461
clean up functions bc why is it breaking
AlisonB319 Sep 17, 2024
13ce326
add retry to hopefully fix brokenness
AlisonB319 Sep 17, 2024
bae3f9f
small tweaks
AlisonB319 Sep 17, 2024
6fc3a56
merge master
AlisonB319 Sep 17, 2024
4c2dc8e
fix syntax problems
AlisonB319 Sep 17, 2024
6e144a9
fix function call name
AlisonB319 Sep 17, 2024
8385dd3
do pid checks
AlisonB319 Sep 17, 2024
05a88de
include curl output
AlisonB319 Sep 17, 2024
3a01366
add quotes
AlisonB319 Sep 17, 2024
c0064ef
add evaluatedUrl
AlisonB319 Sep 17, 2024
5b15b4e
more debugging
AlisonB319 Sep 17, 2024
ec54ed6
trying smt new
AlisonB319 Sep 17, 2024
cbbbdd3
trying smt new
AlisonB319 Sep 17, 2024
657ebd5
more debugging
AlisonB319 Sep 17, 2024
95bfcfa
unbound var
AlisonB319 Sep 18, 2024
4b46dd2
cleanup woo
AlisonB319 Sep 18, 2024
12564a2
fix loop
AlisonB319 Sep 18, 2024
4b9b9ea
look at the dir
AlisonB319 Sep 18, 2024
1cdd199
debugging with stop
AlisonB319 Sep 18, 2024
8df659f
more testing
AlisonB319 Sep 18, 2024
a90453e
go back to local var??
AlisonB319 Sep 18, 2024
1155c14
cleanup with the correct file path i hope
AlisonB319 Sep 18, 2024
1de539c
remove exit
AlisonB319 Sep 18, 2024
a300404
put in specific tests for wasm
AlisonB319 Sep 18, 2024
ed685a9
fix airgap e2e
AlisonB319 Sep 18, 2024
289431f
cleanup tests
AlisonB319 Sep 18, 2024
36b9505
include files in the err msg to output
AlisonB319 Sep 18, 2024
1b71288
rvt to 3
AlisonB319 Sep 18, 2024
29df8fd
correct version format
AlisonB319 Sep 18, 2024
0c24382
correct version format
AlisonB319 Sep 18, 2024
7df7d56
add vars
AlisonB319 Sep 18, 2024
d11f26a
remove first slash
AlisonB319 Sep 18, 2024
4800b90
whoops
AlisonB319 Sep 18, 2024
78c84f8
add continue statement
AlisonB319 Sep 18, 2024
f970ff8
modify testing
AlisonB319 Sep 18, 2024
4801f6f
fix e2e
AlisonB319 Sep 18, 2024
b0bc445
fix v
AlisonB319 Sep 18, 2024
8ec0df7
Merge branch 'master' into alburgess/wasm-compJson
AlisonB319 Sep 19, 2024
d546637
feat: move wasm to components.json
AlisonB319 Sep 19, 2024
8319b35
make some tweaks and update testing
AlisonB319 Sep 19, 2024
967d225
add locals
AlisonB319 Sep 19, 2024
ae86f2b
cleanup
AlisonB319 Sep 19, 2024
d6d15bd
Merge branch 'alburgess/wasm-comp2' into alburgess/wasm-compJson
AlisonB319 Sep 19, 2024
46049df
comment
AlisonB319 Sep 19, 2024
e549730
check the file
AlisonB319 Sep 19, 2024
ec3a251
add some testing for updating the binaries
AlisonB319 Sep 19, 2024
e40a0dc
add testing echos
AlisonB319 Sep 19, 2024
bb6ad61
add new comp.json
AlisonB319 Sep 19, 2024
c205bcc
make changes for spinkube
AlisonB319 Sep 19, 2024
84cbd15
remove .15 from wasm-shims
AlisonB319 Sep 19, 2024
df76975
testdata
AlisonB319 Sep 19, 2024
2062cf0
combine vars
AlisonB319 Sep 19, 2024
dcb3d30
add version v's
AlisonB319 Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion parts/linux/cloud-init/artifacts/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,48 @@
}
}
}
},
{
"name": "containerd-wasm-shims",
"downloadLocation": "/usr/local/bin",
"downloadURIs": {
"default": {
"current": {
"versionsV2": [
{
"renovateTag": "<DO_NOT_UPDATE>",
"latestVersion": "0.3.0"
},
{
"renovateTag": "<DO_NOT_UPDATE>",
"latestVersion": "0.5.1"
},
{
"renovateTag": "<DO_NOT_UPDATE>",
"latestVersion": "0.8.0"
AlisonB319 marked this conversation as resolved.
Show resolved Hide resolved
}
],
"downloadURL": "https://acs-mirror.azureedge.net/containerd-wasm-shims/v${version}/linux/${CPU_ARCH}"
}
}
}
},
{
"name": "containerd-wasm-spinkube",
"downloadLocation": "/usr/local/bin",
"downloadURIs": {
"default": {
"current": {
"versionsV2": [
{
"renovateTag": "<DO_NOT_UPDATE>",
"latestVersion": "0.15.1"
}
],
"downloadURL": "https://acs-mirror.azureedge.net/spinkube/v${version}/linux/${CPU_ARCH}"
}
}
}
}
]
}
}
193 changes: 106 additions & 87 deletions parts/linux/cloud-init/artifacts/cse_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ TELEPORTD_PLUGIN_DOWNLOAD_DIR="/opt/teleportd/downloads"
CREDENTIAL_PROVIDER_DOWNLOAD_DIR="/opt/credentialprovider/downloads"
CREDENTIAL_PROVIDER_BIN_DIR="/var/lib/kubelet/credential-provider"
TELEPORTD_PLUGIN_BIN_DIR="/usr/local/bin"
CONTAINERD_WASM_VERSIONS="v0.3.0 v0.5.1 v0.8.0 v0.15.1" # v0.15.1 is from SpinKube
MANIFEST_FILEPATH="/opt/azure/manifest.json"
COMPONENTS_FILEPATH="/opt/azure/components.json"
MAN_DB_AUTO_UPDATE_FLAG_FILEPATH="/var/lib/man-db/auto-update"
CURL_OUTPUT=/tmp/curl_verbose.out
UBUNTU_OS_NAME="UBUNTU"
MARINER_OS_NAME="MARINER"
CPU_ARCH=""
declare -a WASMSHIMPIDS=()

setCPUArch() {
CPU_ARCH=$(getCPUArch)
Expand Down Expand Up @@ -200,102 +200,122 @@ downloadSecureTLSBootstrapKubeletExecPlugin() {
fi
}

downloadContainerdWasmShims() {
declare -a wasmShimPids=()
local containerd_wasm_filepath="/usr/local/bin"
BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER="${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER:=}"

for shim_version in $CONTAINERD_WASM_VERSIONS; do
binary_version="$(echo "${shim_version}" | tr . -)"

local version_suffix
local shims_to_download=()
local shim_prefix="containerd-shim-"
local registry_path
local base_path
local shim_filename

# figure out version suffix, shims to download, and paths
if [ "$shim_version" == "v0.15.1" ]; then
version_suffix="-v2"
shims_to_download=("spin")
registry_path="oss/binaries/spinkube/containerd-shim-spin"
base_path="spinkube"
shim_filename="containerd-shim-spin-v2"
else
version_suffix="-v1"
shims_to_download=("spin" "slight")
registry_path="oss/binaries/deislabs/containerd-wasm-shims"
base_path="containerd-wasm-shims"
shim_filename="containerd-wasm-shims-linux-${CPU_ARCH}.tar.gz"
if [ "$shim_version" == "v0.8.0" ]; then
shims_to_download+=("wws")
fi
fi
# Install, download, update wasm must all be run from the same function call
# in order to ensure WASMSHIMPIDS persists correctly since in bash a new
# function call from install-dependnecies will create a new shell process.
installContainerdWasmShims(){
local download_location=${1}
PACKAGE_DOWNLOAD_URL=${2}
shift 2 # shift past the first 2 arguments to capture the list of versions
local package_versions=("$@")

local shims_to_download=("spin" "slight")
local version_suffix="-v1"
local mcr_registry_path="deislabs/containerd-wasm-shims"
local shim_filename="containerd-wasm-shims-linux-${CPU_ARCH}.tar.gz"
if [ "$shim_version" == "0.15.1" ]; then
version_suffix="-v2"
shims_to_download=("spin")
mcr_registry_path="spinkube/containerd-shim-spin"
shim_filename="containerd-shim-spin-v2"
elif [ "$shim_version" == "0.8.0" ]; then
shims_to_download+=("wws")
fi

for version in "${package_versions[@]}"; do
containerd_wasm_url=$(evalPackageDownloadURL ${PACKAGE_DOWNLOAD_URL})
downloadContainerdWasmShims $download_location $containerd_wasm_url $version $shims_to_download $version_suffix $mcr_registry_path $shim_filename
done
wait ${WASMSHIMPIDS[@]}
for version in "${package_versions[@]}"; do
updateContainerdWasmShimsPermissions $download_location $version $shims_to_download $version_suffix
done
}

# check if shims are already downloaded
shims_missing=false
for shim in "${shims_to_download[@]}"; do
if [ ! -f "${containerd_wasm_filepath}/${shim_prefix}${shim}-${binary_version}${version_suffix}" ]; then
shims_missing=true
break
fi
done
wasmFilesExist() {
local containerd_wasm_filepath=${1}
local shim_version=${2}
local shims_to_download=${3}
local version_suffix=${4}

if [ "$shims_missing" = false ]; then
# all shims are already downloaded, skip downloading
continue
local binary_version="$(echo "${shim_version}" | tr . -)"
for shim in "${shims_to_download[@]}"; do
if [ ! -f "${containerd_wasm_filepath}/containerd-shim-${shim}-v${binary_version}-${version_suffix}" ]; then
return 1 # file is missing
fi
done
return 0
}

if [[ -n ${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER} ]]; then
# download shims from container registry

local registry_url="${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER}/${registry_path}:${shim_version}-linux-${CPU_ARCH}"
local wasm_shims_tgz_tmp="${containerd_wasm_filepath}/${shim_filename}"

# if shim version is v0.15.1, the downloaded binary is already named correctly, so no need to extract
# if shim version is not v0.15.1, extract the shims and rename them to match the binary version
if [ "$shim_version" == "v0.15.1" ]; then
retrycmd_get_binary_from_registry_with_oras 120 5 "${wasm_shims_tgz_tmp}" "${registry_url}" || exit $ERR_ORAS_PULL_CONTAINERD_WASM
mv "${containerd_wasm_filepath}/containerd-shim-spin-v2" "${containerd_wasm_filepath}/containerd-shim-spin-${binary_version}-v2"
else
retrycmd_get_tarball_from_registry_with_oras 120 5 "${wasm_shims_tgz_tmp}" "${registry_url}" || exit $ERR_ORAS_PULL_CONTAINERD_WASM
tar -zxf "$wasm_shims_tgz_tmp" -C "$containerd_wasm_filepath"
for shim in "${shims_to_download[@]}"; do
mv "${containerd_wasm_filepath}/${shim_prefix}${shim}-${shim_version}${version_suffix}" "${containerd_wasm_filepath}/${shim_prefix}${shim}-${binary_version}${version_suffix}"
done
fi
downloadContainerdWasmShims() {
local containerd_wasm_filepath=${1}
local containerd_wasm_url=${2}
local shim_version=${3}
local shims_to_download=${4}
local version_suffix=${5}
local mcr_registry_path=${6}
local shim_filename=${7}

rm -f "$wasm_shims_tgz_tmp"
else
# download shims from acs-mirro
local base_url="https://acs-mirror.azureedge.net/${base_path}/${shim_version}/linux/${CPU_ARCH}"
local binary_version="$(echo "${shim_version}" | tr . -)" # replaces . with - == 1.2.3 -> 1-2-3

echo "containerd_wasm_filepath: $containerd_wasm_filepath, containerd_wasm_url: $containerd_wasm_url, shim_version: $shim_version, binary_version: $binary_version, shims_to_download: ${shims_to_download[@]}, version_suffix: $version_suffix, mcr_registry_path: $mcr_registry_path, shim_filename: $shim_filename"

if wasmFilesExist "$containerd_wasm_filepath" "$shim_version" "$shims_to_download" "$version_suffix"; then
return
fi

# Oras download for WASM for Network Isolated Clusters
BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER="${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER:=}"
if [[ ! -z ${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER} ]]; then
local registry_url="${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER}/oss/binaries/${mcr_registry_path}:v${shim_version}-linux-${CPU_ARCH}"
local wasm_shims_tgz_tmp="${containerd_wasm_filepath}/${shim_filename}"

# if shim version is 0.15.1, the downloaded binary is already named correctly, so no need to extract
# if shim version is not 0.15.1, extract the shims and rename them to match the binary version
if [ "$shim_version" == "0.15.1" ]; then
retrycmd_get_binary_from_registry_with_oras 120 5 "${wasm_shims_tgz_tmp}" "${registry_url}" || exit $ERR_ORAS_PULL_CONTAINERD_WASM
mv "${containerd_wasm_filepath}/containerd-shim-spin-${version_suffix}" "${containerd_wasm_filepath}/containerd-shim-spin-v${binary_version}${version_suffix}"
else
retrycmd_get_tarball_from_registry_with_oras 120 5 "${wasm_shims_tgz_tmp}" "${registry_url}" || exit $ERR_ORAS_PULL_CONTAINERD_WASM
tar -zxf "$wasm_shims_tgz_tmp" -C "$containerd_wasm_filepath"
for shim in "${shims_to_download[@]}"; do
local shim_filename="${shim_prefix}${shim}${version_suffix}"
retrycmd_if_failure 2 5 60 curl -fSLv -o "${containerd_wasm_filepath}/${shim_prefix}${shim}-${binary_version}${version_suffix}" "${base_url}/${shim_filename}" 2>&1 | tee "$CURL_OUTPUT" >/dev/null | grep -E "^(curl:.*)|([eE]rr.*)$" && (cat "$CURL_OUTPUT" && exit $ERR_KRUSTLET_DOWNLOAD_TIMEOUT) &
wasmShimPids+=($!)
mv "${containerd_wasm_filepath}/containerd-shim-${shim}-v${shim_version}${version_suffix}" "${containerd_wasm_filepath}/containerd-shim-${shim}-v${binary_version}${version_suffix}"
done
fi

rm -f "$wasm_shims_tgz_tmp"
return
fi

# install from acs-mirror
for shim in "${shims_to_download[@]}"; do
retrycmd_if_failure 30 5 60 curl -fSLv -o "$containerd_wasm_filepath/containerd-shim-${shim}-v${binary_version}${version_suffix}" "$containerd_wasm_url/containerd-shim-${shim}-${version_suffix}" 2>&1 | tee $CURL_OUTPUT >/dev/null | grep -E "^(curl:.*)|([eE]rr.*)$" && (cat $CURL_OUTPUT && exit $ERR_KRUSTLET_DOWNLOAD_TIMEOUT) &
WASMSHIMPIDS+=($!)
done
}

wait ${wasmShimPids[@]}

# set permissions for the shims
for shim_version in $CONTAINERD_WASM_VERSIONS; do
binary_version="$(echo "${shim_version}" | tr . -)"
if [ "$shim_version" == "v0.15.1" ]; then
chmod 755 "$containerd_wasm_filepath/containerd-shim-spin-${binary_version}-v2"
# spin shim v0.15.1 cannot be renamed: https://github.com/spinkube/containerd-shim-spin/issues/190
# so we rename the shim back to containerd-shim-spin-v2
mv "$containerd_wasm_filepath/containerd-shim-spin-${binary_version}-v2" "$containerd_wasm_filepath/containerd-shim-spin-v2"
else
chmod 755 "$containerd_wasm_filepath/containerd-shim-spin-${binary_version}-v1"
chmod 755 "$containerd_wasm_filepath/containerd-shim-slight-${binary_version}-v1"
if [ "$shim_version" == "v0.8.0" ]; then
chmod 755 "$containerd_wasm_filepath/containerd-shim-wws-${binary_version}-v1"
fi
fi
updateContainerdWasmShimsPermissions() {
local containerd_wasm_filepath=${1}
local shim_version=${2}
local shims_to_download=${3}
local version_suffix=${4}

local binary_version="$(echo "${shim_version}" | tr . -)"

echo "Updating permissions containerd_wasm_filepath: $containerd_wasm_filepath, shim_version: $shim_version, binary_version: $binary_version, shims_to_download: ${shims_to_download[@]}, version_suffix: $version_suffix"

if [ "$shim_version" == "0.15.1" ]; then
echo "inside the 0.15.1: $shim_version"
chmod 755 "$containerd_wasm_filepath/containerd-shim-spin-v${binary_version}-${version_suffix}"
# spin shim v0.15.1 cannot be renamed: https://github.com/spinkube/containerd-shim-spin/issues/190
# so we rename the shim back to containerd-shim-spin-v2
mv "$containerd_wasm_filepath/containerd-shim-spin-v${binary_version}-${version_suffix}" "$containerd_wasm_filepath/containerd-shim-spin-${version_suffix}"
return
fi

for shim in "${shims_to_download[@]}"; do
echo "updating for shil: $shim ----> $containerd_wasm_filepath/containerd-shim-${shim}-v${binary_version}-${version_suffix}"
chmod 755 "$containerd_wasm_filepath/containerd-shim-${shim}-v${binary_version}-${version_suffix}"
done
}

Expand All @@ -321,7 +341,6 @@ installOras() {
sudo tar -zxf "$ORAS_DOWNLOAD_DIR/${ORAS_TMP}" -C $ORAS_EXTRACTED_DIR/
rm -r "$ORAS_DOWNLOAD_DIR"
echo "Oras version $ORAS_VERSION installed successfully."

}

evalPackageDownloadURL() {
Expand Down
8 changes: 7 additions & 1 deletion parts/linux/cloud-init/artifacts/cse_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ setupCNIDirs
logs_to_events "AKS.CSE.installNetworkPlugin" installNetworkPlugin

if [ "${IS_KRUSTLET}" == "true" ]; then
logs_to_events "AKS.CSE.downloadKrustlet" downloadContainerdWasmShims
components_filepath="/opt/azure/components.json"
versions=$(jq -r '.Packages[] | select(.name == "containerd-wasm-shims") | .downloadURIs.default.current.versionsV2[].latestVersion' "$components_filepath")
downloadLocation=$(jq -r '.Packages[] | select(.name == "containerd-wasm-shims") | .downloadLocation' "$components_filepath")
downloadURL=$(jq -r '.Packages[] | select(.name == "containerd-wasm-shims") | .downloadURIs.default.current.downloadURL' "$components_filepath")

logs_to_events "AKS.CSE.downloadKrustlet" installContainerdWasmShims "$downloadLocation" "$downloadURL" "$versions"
fi


if [ "${ENABLE_SECURE_TLS_BOOTSTRAPPING}" == "true" ]; then
logs_to_events "AKS.CSE.downloadSecureTLSBootstrapKubeletExecPlugin" downloadSecureTLSBootstrapKubeletExecPlugin
fi
Expand Down
Loading
Loading