| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Copyright The containerd Authors. |
| 4 |
|
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
# you may not use this file except in compliance with the License. |
| 7 |
# You may obtain a copy of the License at |
| 8 |
|
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
|
| 17 |
set -euo pipefail |
| 18 |
|
| 19 |
CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/" |
| 20 |
REPO="${CONTEXT}../../" |
| 21 |
SNAPSHOTTER_SOCK_PATH=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock |
| 22 |
|
| 23 |
source "${CONTEXT}/const.sh" |
| 24 |
source "${REPO}/script/util/utils.sh" |
| 25 |
|
| 26 |
CNI_PLUGINS_VERSION=$(get_version_from_arg "${REPO}/Dockerfile" "CNI_PLUGINS_VERSION") |
| 27 |
CRI_TOOLS_VERSION=$(get_version_from_arg "${REPO}/Dockerfile" "CRI_TOOLS_VERSION") |
| 28 |
GINKGO_VERSION=v1.16.5 |
| 29 |
|
| 30 |
if [ "${CRI_NO_RECREATE:-}" != "true" ] ; then |
| 31 |
echo "Preparing node image..." |
| 32 |
|
| 33 |
TARGET_STAGE= |
| 34 |
if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then |
| 35 |
TARGET_STAGE="--target kind-builtin-snapshotter" |
| 36 |
fi |
| 37 |
|
| 38 |
docker build ${DOCKER_BUILD_ARGS:-} -t "${NODE_BASE_IMAGE_NAME}" ${TARGET_STAGE} "${REPO}" |
| 39 |
docker build ${DOCKER_BUILD_ARGS:-} -t "${PREPARE_NODE_IMAGE}" --target containerd-base "${REPO}" |
| 40 |
fi |
| 41 |
|
| 42 |
TMP_CONTEXT=$(mktemp -d) |
| 43 |
IMAGE_LIST=$(mktemp) |
| 44 |
function cleanup { |
| 45 |
local ORG_EXIT_CODE="${1}" |
| 46 |
rm -rf "${TMP_CONTEXT}" || true |
| 47 |
rm "${IMAGE_LIST}" || true |
| 48 |
exit "${ORG_EXIT_CODE}" |
| 49 |
} |
| 50 |
trap 'cleanup "$?"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM |
| 51 |
|
| 52 |
BUILTIN_HACK_INST= |
| 53 |
if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then |
| 54 |
# Special configuration for CRI containerd + builtin stargz snapshotter |
| 55 |
cat <<EOF > "${TMP_CONTEXT}/containerd.hack.toml" |
| 56 |
version = 2 |
| 57 |
|
| 58 |
[debug] |
| 59 |
format = "json" |
| 60 |
level = "debug" |
| 61 |
[plugins."io.containerd.grpc.v1.cri".containerd] |
| 62 |
default_runtime_name = "runc" |
| 63 |
snapshotter = "stargz" |
| 64 |
disable_snapshot_annotations = false |
| 65 |
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] |
| 66 |
runtime_type = "io.containerd.runc.v2" |
| 67 |
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.test-handler] |
| 68 |
runtime_type = "io.containerd.runc.v2" |
| 69 |
[plugins."io.containerd.snapshotter.v1.stargz"] |
| 70 |
cri_keychain_image_service_path = "${SNAPSHOTTER_SOCK_PATH}" |
| 71 |
metadata_store = "memory" |
| 72 |
[plugins."io.containerd.snapshotter.v1.stargz".cri_keychain] |
| 73 |
enable_keychain = true |
| 74 |
EOF |
| 75 |
BUILTIN_HACK_INST="COPY containerd.hack.toml /etc/containerd/config.toml" |
| 76 |
fi |
| 77 |
|
| 78 |
cat <<EOF > "${TMP_CONTEXT}/test.conflist" |
| 79 |
{ |
| 80 |
"cniVersion": "0.4.0", |
| 81 |
"name": "containerd-net", |
| 82 |
"plugins": [ |
| 83 |
{ |
| 84 |
"type": "bridge", |
| 85 |
"bridge": "cni0", |
| 86 |
"isGateway": true, |
| 87 |
"ipMasq": true, |
| 88 |
"promiscMode": true, |
| 89 |
"ipam": { |
| 90 |
"type": "host-local", |
| 91 |
"ranges": [ |
| 92 |
[{ |
| 93 |
"subnet": "10.88.0.0/16" |
| 94 |
}] |
| 95 |
], |
| 96 |
"routes": [ |
| 97 |
{ "dst": "0.0.0.0/0" } |
| 98 |
] |
| 99 |
} |
| 100 |
}, |
| 101 |
{ |
| 102 |
"type": "portmap", |
| 103 |
"capabilities": {"portMappings": true} |
| 104 |
} |
| 105 |
] |
| 106 |
} |
| 107 |
EOF |
| 108 |
|
| 109 |
USE_METADATA_STORE="memory" |
| 110 |
if [ "${METADATA_STORE:-}" != "" ] ; then |
| 111 |
USE_METADATA_STORE="${METADATA_STORE}" |
| 112 |
fi |
| 113 |
|
| 114 |
SNAPSHOTTER_CONFIG_FILE=/etc/containerd-stargz-grpc/config.toml |
| 115 |
if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then |
| 116 |
SNAPSHOTTER_CONFIG_FILE=/etc/containerd/config.toml |
| 117 |
fi |
| 118 |
|
| 119 |
# Prepare the testing node |
| 120 |
cat <<EOF > "${TMP_CONTEXT}/Dockerfile" |
| 121 |
# Legacy builder that doesn't support TARGETARCH should set this explicitly using --build-arg. |
| 122 |
# If TARGETARCH isn't supported by the builder, the default value is "amd64". |
| 123 |
|
| 124 |
FROM ${NODE_BASE_IMAGE_NAME} |
| 125 |
ARG TARGETARCH |
| 126 |
|
| 127 |
ENV PATH=$PATH:/usr/local/go/bin |
| 128 |
ENV GOPATH=/go |
| 129 |
# Do not install git and its dependencies here which will cause failure of building the image |
| 130 |
RUN apt-get update && apt-get install -y --no-install-recommends make && \ |
| 131 |
curl -Ls https://dl.google.com/go/go1.19.linux-\${TARGETARCH:-amd64}.tar.gz | tar -C /usr/local -xz && \ |
| 132 |
go install github.com/onsi/ginkgo/ginkgo@${GINKGO_VERSION} && \ |
| 133 |
mkdir -p \${GOPATH}/src/github.com/kubernetes-sigs/cri-tools /tmp/cri-tools && \ |
| 134 |
curl -sL https://github.com/kubernetes-sigs/cri-tools/archive/refs/tags/v${CRI_TOOLS_VERSION}.tar.gz | tar -C /tmp/cri-tools -xz && \ |
| 135 |
mv /tmp/cri-tools/cri-tools-${CRI_TOOLS_VERSION}/* \${GOPATH}/src/github.com/kubernetes-sigs/cri-tools/ && \ |
| 136 |
cd \${GOPATH}/src/github.com/kubernetes-sigs/cri-tools && \ |
| 137 |
make && make install -e BINDIR=\${GOPATH}/bin && \ |
| 138 |
curl -Ls https://github.com/containernetworking/plugins/releases/download/v${CNI_PLUGINS_VERSION}/cni-plugins-linux-\${TARGETARCH:-amd64}-v${CNI_PLUGINS_VERSION}.tgz | tar xzv -C /opt/cni/bin && \ |
| 139 |
systemctl disable kubelet |
| 140 |
|
| 141 |
COPY ./test.conflist /etc/cni/net.d/test.conflist |
| 142 |
|
| 143 |
${BUILTIN_HACK_INST} |
| 144 |
|
| 145 |
RUN sed -i 's/^metadata_store.*/metadata_store = "${USE_METADATA_STORE}"/g' "${SNAPSHOTTER_CONFIG_FILE}" |
| 146 |
|
| 147 |
ENTRYPOINT [ "/usr/local/bin/entrypoint", "/sbin/init" ] |
| 148 |
EOF |
| 149 |
docker build -t "${NODE_TEST_IMAGE_NAME}" ${DOCKER_BUILD_ARGS:-} "${TMP_CONTEXT}" |
| 150 |
|
| 151 |
echo "Testing..." |
| 152 |
"${CONTEXT}/test-legacy.sh" "${IMAGE_LIST}" |
| 153 |
"${CONTEXT}/test-stargz.sh" "${IMAGE_LIST}" |