1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#!/bin/bash
# Copyright The containerd Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/"
REPO="${CONTEXT}../../"
REGISTRY_HOST="cri-registry"
TEST_NODE_NAME="cri-testenv-container"
CONTAINERD_SOCK=unix:///run/containerd/containerd.sock
SNAPSHOTTER_SOCK=unix:///run/containerd-stargz-grpc/containerd-stargz-grpc.sock
PREPARE_NODE_NAME="cri-prepare-node"
source "${CONTEXT}/const.sh"
source "${REPO}/script/util/utils.sh"
IMAGE_LIST="${1}"
TMP_CONTEXT=$(mktemp -d)
DOCKER_COMPOSE_YAML=$(mktemp)
CONTAINERD_CONFIG=$(mktemp)
SNAPSHOTTER_CONFIG=$(mktemp)
TMPFILE=$(mktemp)
LOG_FILE=$(mktemp)
MIRROR_TMP=$(mktemp -d)
function cleanup {
ORG_EXIT_CODE="${1}"
docker-compose -f "${DOCKER_COMPOSE_YAML}" down -v || true
rm -rf "${TMP_CONTEXT}" || true
rm "${DOCKER_COMPOSE_YAML}" || true
rm "${CONTAINERD_CONFIG}" || true
rm "${SNAPSHOTTER_CONFIG}" || true
rm "${TMPFILE}" || true
rm "${LOG_FILE}" || true
rm -rf "${MIRROR_TMP}" || true
exit "${ORG_EXIT_CODE}"
}
trap 'cleanup "$?"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM
# Prepare the testing node and registry
cat <<EOF > "${DOCKER_COMPOSE_YAML}"
version: "3.3"
services:
cri-testenv-service:
image: ${NODE_TEST_IMAGE_NAME}
container_name: ${TEST_NODE_NAME}
privileged: true
tmpfs:
- /tmp:exec,mode=777
volumes:
- /dev/fuse:/dev/fuse
- "critest-containerd-data:/var/lib/containerd"
- "critest-containerd-stargz-grpc-data:/var/lib/containerd-stargz-grpc"
image-prepare:
image: "${PREPARE_NODE_IMAGE}"
container_name: "${PREPARE_NODE_NAME}"
privileged: true
entrypoint:
- sleep
- infinity
tmpfs:
- /tmp:exec,mode=777
environment:
- TOOLS_DIR=/tools/
volumes:
- "critest-prepare-containerd-data:/var/lib/containerd"
- "critest-prepare-containerd-stargz-grpc-data:/var/lib/containerd-stargz-grpc"
- "${REPO}:/go/src/github.com/containerd/stargz-snapshotter:ro"
- "${MIRROR_TMP}:/tools/"
registry:
image: registry:2
container_name: ${REGISTRY_HOST}
volumes:
critest-containerd-data:
critest-containerd-stargz-grpc-data:
critest-prepare-containerd-data:
critest-prepare-containerd-stargz-grpc-data:
EOF
docker-compose -f "${DOCKER_COMPOSE_YAML}" up -d --force-recreate
CONNECTED=
for i in $(seq 100) ; do
if docker exec "${TEST_NODE_NAME}" curl -k --head "http://${REGISTRY_HOST}:5000/v2/" ; then
CONNECTED=true
break
fi
echo "Fail(${i}). Retrying..."
sleep 1
done
if [ "${CONNECTED}" != "true" ] ; then
echo "Failed to connect to containerd"
exit 1
fi
# Mirror and optimize all images used in tests
echo "${REGISTRY_HOST}:5000" > "${MIRROR_TMP}/host"
cp "${IMAGE_LIST}" "${MIRROR_TMP}/list"
cp "${REPO}/script/cri-containerd/mirror.sh" "${MIRROR_TMP}/mirror.sh"
docker exec "${PREPARE_NODE_NAME}" /bin/bash /tools/mirror.sh
# Configure mirror registries for containerd and snapshotter
docker exec "${TEST_NODE_NAME}" cat /etc/containerd/config.toml > "${CONTAINERD_CONFIG}"
docker exec "${TEST_NODE_NAME}" cat /etc/containerd-stargz-grpc/config.toml > "${SNAPSHOTTER_CONFIG}"
cat "${IMAGE_LIST}" | sed -E 's/^([^/]*).*/\1/g' | sort | uniq | while read DOMAIN ; do
echo "Adding mirror config: ${DOMAIN}"
cat <<EOF >> "${CONTAINERD_CONFIG}"
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${DOMAIN}"]
endpoint = ["http://${REGISTRY_HOST}:5000"]
EOF
if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then
cat <<EOF >> "${CONTAINERD_CONFIG}"
[plugins."io.containerd.snapshotter.v1.stargz".registry.mirrors."${DOMAIN}"]
endpoint = ["http://${REGISTRY_HOST}:5000"]
EOF
else
cat <<EOF >> "${SNAPSHOTTER_CONFIG}"
[[resolver.host."${DOMAIN}".mirrors]]
host = "${REGISTRY_HOST}:5000"
insecure = true
EOF
fi
done
echo "==== Containerd config ===="
cat "${CONTAINERD_CONFIG}"
echo "==== Snapshotter config ===="
cat "${SNAPSHOTTER_CONFIG}"
docker cp "${CONTAINERD_CONFIG}" "${TEST_NODE_NAME}":/etc/containerd/config.toml
docker cp "${SNAPSHOTTER_CONFIG}" "${TEST_NODE_NAME}":/etc/containerd-stargz-grpc/config.toml
# Replace digests specified in testing tool to stargz-formatted one
docker exec "${PREPARE_NODE_NAME}" ctr-remote i ls
cat "${IMAGE_LIST}" | grep "@sha256:" | while read IMAGE ; do
URL_PATH=$(echo "${IMAGE}" | sed -E 's/^[^/]*//g' | sed -E 's/@.*//g')
MIRROR_TAG="${REGISTRY_HOST}:5000${URL_PATH}"
OLD_DIGEST=$(echo "${IMAGE}" | sed -E 's/.*(sha256:[a-z0-9]*).*/\1/g')
echo "Getting the digest of : ${MIRROR_TAG}"
NEW_DIGEST=$(docker exec "${PREPARE_NODE_NAME}" ctr-remote i ls name=="${MIRROR_TAG}" \
| grep "sha256" | sed -E 's/.*(sha256:[a-z0-9]*).*/\1/g')
echo "Converting: ${OLD_DIGEST} => ${NEW_DIGEST}"
docker exec "${TEST_NODE_NAME}" \
find /go/src/github.com/kubernetes-sigs/cri-tools/pkg -type f -exec \
sed -i -e "s|${OLD_DIGEST}|${NEW_DIGEST}|g" {} \;
done
# Rebuild cri testing tool
docker exec "${TEST_NODE_NAME}" /bin/bash -c \
"cd /go/src/github.com/kubernetes-sigs/cri-tools && make && make install -e BINDIR=/go/bin"
# Varidate the runtime through CRI
if [ "${BUILTIN_SNAPSHOTTER:-}" != "true" ] ; then
docker exec "${TEST_NODE_NAME}" systemctl restart stargz-snapshotter
fi
docker exec "${TEST_NODE_NAME}" systemctl restart containerd
CONNECTED=
for i in $(seq 100) ; do
if docker exec "${TEST_NODE_NAME}" ctr version ; then
CONNECTED=true
break
fi
echo "Fail(${i}). Retrying..."
sleep 1
done
if [ "${CONNECTED}" != "true" ] ; then
echo "Failed to connect to containerd"
exit 1
fi
echo "===== VERSION INFORMATION ====="
docker exec "${TEST_NODE_NAME}" runc --version
docker exec "${TEST_NODE_NAME}" containerd --version
echo "==============================="
docker exec "${TEST_NODE_NAME}" /go/bin/critest --runtime-endpoint=${CONTAINERD_SOCK} --image-endpoint=${SNAPSHOTTER_SOCK}
echo "Check if stargz snapshotter is working"
docker exec "${TEST_NODE_NAME}" \
ctr-remote --namespace=k8s.io snapshot --snapshotter=stargz ls \
| sed -E '1d' > "${TMPFILE}"
if ! [ -s "${TMPFILE}" ] ; then
echo "No snapshots created; stargz snapshotter might be connected to containerd"
exit 1
fi
echo "Check all remote snapshots are created successfully"
if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then
docker exec "${TEST_NODE_NAME}" journalctl -u containerd \
| grep "${LOG_REMOTE_SNAPSHOT}" \
| sed -E 's/^[^\{]*(\{.*)$/\1/g' > "${LOG_FILE}"
else
docker exec "${TEST_NODE_NAME}" journalctl -u stargz-snapshotter \
| grep "${LOG_REMOTE_SNAPSHOT}" \
| sed -E 's/^[^\{]*(\{.*)$/\1/g' > "${LOG_FILE}"
fi
check_remote_snapshots "${LOG_FILE}"
exit 0
|