From 794543065a238b1a6ce1c826b1fdf23db91c9651 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Fri, 5 Jan 2018 06:38:25 +0000 Subject: [PATCH] Add script to automatically update containerd with newest cri plugin. Signed-off-by: Lantao Liu --- hack/install-deps.sh | 43 +++++++++++++++++++++++++++++++++---- hack/test-integration.sh | 4 +++- hack/test-utils.sh | 10 ++++++--- integration/restart_test.go | 7 ++++++ integration/test_utils.go | 1 + 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/hack/install-deps.sh b/hack/install-deps.sh index 7fb1ba9ee..74c3b75ad 100755 --- a/hack/install-deps.sh +++ b/hack/install-deps.sh @@ -50,6 +50,11 @@ fi # and configurations in cluster. INSTALL_CNI=${INSTALL_CNI:-true} +# COOK_CONTAINERD indicates whether to update containerd with newest +# cri plugin before install. This is mainly used for testing new cri +# plugin change. +COOK_CONTAINERD=${COOK_CONTAINERD:-false} + CONTAINERD_DIR=${DESTDIR}/usr/local RUNC_DIR=${DESTDIR} CNI_DIR=${DESTDIR}/opt/cni @@ -61,6 +66,7 @@ RUNC_PKG=github.com/opencontainers/runc CNI_PKG=github.com/containernetworking/plugins CONTAINERD_PKG=github.com/containerd/containerd CRITOOL_PKG=github.com/kubernetes-incubator/cri-tools +CRI_CONTAINERD_PKG=github.com/containerd/cri-containerd # Create a temporary GOPATH for make install.deps. TMPGOPATH=$(mktemp -d /tmp/cri-containerd-install-deps.XXXX) @@ -73,9 +79,9 @@ GOPATH=${TMPGOPATH} # 2) Version. # 3) Repo name (optional); checkout_repo() { - pkg=$1 - version=$2 - repo=${3:-""} + local -r pkg=$1 + local -r version=$2 + local repo=${3:-""} if [ -z "${repo}" ]; then repo=${pkg} fi @@ -134,7 +140,36 @@ fi # Install containerd checkout_repo ${CONTAINERD_PKG} ${CONTAINERD_VERSION} ${CONTAINERD_REPO} cd ${GOPATH}/src/${CONTAINERD_PKG} -make +if ${COOK_CONTAINERD}; then + # Verify that vendor.conf is in sync with containerd before cook containerd, + # this is a hard requirement. + if ! ${ROOT}/hack/update-vendor.sh -only-verify; then + echo "Please run hack/update-vendor.sh before cook containerd." + exit 1 + fi + # Import cri plugin into containerd. + # TODO(random-liu): Remove this after containerd starts to vendor cri plugin. + echo "import _ \"${CRI_CONTAINERD_PKG}\"" >> cmd/containerd/builtins_linux.go + # 1. Copy all cri-containerd vendors into containerd vendor. This makes sure + # all dependencies introduced by cri-containerd will be updated. There might + # be unnecessary vendors introduced, but it still builds. + cp -rT ${ROOT}/vendor/ vendor/ + # 2. Remove containerd repo itself from vendor. + rm -rf vendor/${CONTAINERD_PKG} + # 3. Create cri-containerd vendor in containerd vendor, and copy the newest + # cri-containerd there. + if [ -d "vendor/${CRI_CONTAINERD_PKG}" ]; then + rm -rf vendor/${CRI_CONTAINERD_PKG}/* + else + mkdir -p vendor/${CRI_CONTAINERD_PKG} + fi + cp -rT ${ROOT} vendor/${CRI_CONTAINERD_PKG} + # 4. Remove the extra vendor in cri-containerd. + rm -rf vendor/${CRI_CONTAINERD_PKG}/vendor + # After the 4 steps above done, we have a containerd with newest cri-containerd + # plugin. +fi +make BUILDTAGS="${BUILDTAGS}" # containerd make install requires `go` to work. Explicitly # set PATH to make sure it can find `go` even with `sudo`. ${sudo} sh -c "PATH=${PATH} make install -e DESTDIR=${CONTAINERD_DIR}" diff --git a/hack/test-integration.sh b/hack/test-integration.sh index f2c99ff9f..64cbd97c6 100755 --- a/hack/test-integration.sh +++ b/hack/test-integration.sh @@ -29,7 +29,9 @@ mkdir -p ${REPORT_DIR} test_setup ${REPORT_DIR} # Run integration test. -sudo ${ROOT}/_output/integration.test --test.run="${FOCUS}" --test.v +# Set STANDALONE_CRI_CONTAINERD so that integration test can see it. +# Some integration test needs the env to skip itself. +sudo STANDALONE_CRI_CONTAINERD=${STANDALONE_CRI_CONTAINERD} ${ROOT}/_output/integration.test --test.run="${FOCUS}" --test.v test_exit_code=$? test_teardown diff --git a/hack/test-utils.sh b/hack/test-utils.sh index adf4b975d..dea502161 100644 --- a/hack/test-utils.sh +++ b/hack/test-utils.sh @@ -21,6 +21,8 @@ source ${ROOT}/hack/versions CRI_CONTAINERD_FLAGS=${CRI_CONTAINERD_FLAGS:-""} # RESTART_WAIT_PERIOD is the period to wait before restarting cri-containerd/containerd. RESTART_WAIT_PERIOD=${RESTART_WAIT_PERIOD:-10} +# STANDALONE_CRI_CONTAINERD indicates whether to run standalone cri-containerd. +STANDALONE_CRI_CONTAINERD=${STANDALONE_CRI_CONTAINERD:-true} CRICONTAINERD_SOCK=/var/run/cri-containerd.sock @@ -48,9 +50,11 @@ test_setup() { readiness_check "sudo ctr version" # Start cri-containerd - keepalive "sudo ${ROOT}/_output/cri-containerd --alsologtostderr --v 4 ${CRI_CONTAINERD_FLAGS}" \ - ${RESTART_WAIT_PERIOD} &> ${report_dir}/cri-containerd.log & - cri_containerd_pid=$! + if ${STANDALONE_CRI_CONTAINERD}; then + keepalive "sudo ${ROOT}/_output/cri-containerd --alsologtostderr --v 4 ${CRI_CONTAINERD_FLAGS}" \ + ${RESTART_WAIT_PERIOD} &> ${report_dir}/cri-containerd.log & + cri_containerd_pid=$! + fi readiness_check "sudo ${GOPATH}/bin/crictl --runtime-endpoint=${CRICONTAINERD_SOCK} info" } diff --git a/integration/restart_test.go b/integration/restart_test.go index 768b45fc9..494f92b8e 100644 --- a/integration/restart_test.go +++ b/integration/restart_test.go @@ -31,8 +31,12 @@ import ( ) // Restart test must run sequentially. +// NOTE(random-liu): Current restart test only support standalone cri-containerd mode. func TestSandboxAcrossCRIContainerdRestart(t *testing.T) { + if os.Getenv(standaloneEnvKey) == "false" { + t.Skip("Skip because cri-containerd does not run in standalone mode") + } ctx := context.Background() sandboxNS := "sandbox-restart-cri-containerd" sandboxes := []struct { @@ -149,6 +153,9 @@ func TestSandboxAcrossCRIContainerdRestart(t *testing.T) { // teardown the network properly. // This test uses host network sandbox to avoid resource leakage. func TestSandboxDeletionAcrossCRIContainerdRestart(t *testing.T) { + if os.Getenv(standaloneEnvKey) == "false" { + t.Skip("Skip because cri-containerd does not run in standalone mode") + } ctx := context.Background() sandboxNS := "sandbox-delete-restart-cri-containerd" t.Logf("Make sure no sandbox is running before test") diff --git a/integration/test_utils.go b/integration/test_utils.go index 58080a9fc..06f755033 100644 --- a/integration/test_utils.go +++ b/integration/test_utils.go @@ -41,6 +41,7 @@ const ( containerdEndpoint = "/run/containerd/containerd.sock" criContainerdEndpoint = "/var/run/cri-containerd.sock" criContainerdRoot = "/var/lib/cri-containerd" + standaloneEnvKey = "STANDALONE_CRI_CONTAINERD" ) var (