generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from BenTheElder/e2e-again
add containerd to e2e tests
- Loading branch information
Showing
5 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
//go:build linux && !noe2e | ||
// +build linux,!noe2e | ||
|
||
/* | ||
Copyright 2023 The Kubernetes 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. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestE2EContainerdPull(t *testing.T) { | ||
t.Parallel() | ||
containerdVersions := []string{"1.6.20", "1.7.0"} | ||
for i := range containerdVersions { | ||
containerdVersion := containerdVersions[i] | ||
t.Run("v"+containerdVersion, func(t *testing.T) { | ||
testE2EContainerdPull(t, containerdVersion) | ||
}) | ||
} | ||
} | ||
|
||
func testE2EContainerdPull(t *testing.T, containerdVersion string) { | ||
t.Parallel() | ||
// install containerd and image puller tool | ||
installDir := filepath.Join(binDir, "containerd-"+containerdVersion) | ||
// nolint:gosec | ||
installCmd := exec.Command(filepath.Join(repoRoot, "hack", "tools", "ci-install-containerd.sh")) | ||
installCmd.Env = append(installCmd.Env, | ||
"CONTAINERD_VERSION="+containerdVersion, | ||
"CONTAINERD_INSTALL_DIR="+installDir, | ||
) | ||
installCmd.Stderr = os.Stderr | ||
if err := installCmd.Run(); err != nil { | ||
t.Fatalf("Failed to install containerd: %v", err) | ||
} | ||
|
||
// start rootless containerd, which only needs to be able to pull images | ||
tmpDir, err := os.MkdirTemp("", "containerd") | ||
if err != nil { | ||
t.Fatalf("Failed to setup tmpdir: %v", err) | ||
} | ||
t.Cleanup(func() { | ||
os.RemoveAll(tmpDir) | ||
}) | ||
socketAddress := filepath.Join(tmpDir, "containerd.sock") | ||
// nolint:gosec | ||
containerdCmd := exec.Command( | ||
filepath.Join(installDir, "containerd"), | ||
// config generated by ci-install-containerd.sh | ||
"--config="+filepath.Join(installDir, "containerd-config.toml"), | ||
"--root="+filepath.Join(tmpDir, "root"), | ||
"--state="+filepath.Join(tmpDir, "state"), | ||
"--address="+socketAddress, | ||
"--log-level=trace", | ||
) | ||
containerdCmd.Stderr = os.Stderr | ||
if err := containerdCmd.Start(); err != nil { | ||
t.Fatalf("Failed to start containerd: %v", err) | ||
} | ||
t.Cleanup(func() { | ||
if err := containerdCmd.Process.Signal(os.Interrupt); err != nil { | ||
t.Fatalf("failed to signal containerd: %v", err) | ||
} | ||
// kill if it doesn't exit gracefully after 1s | ||
done := make(chan error) | ||
go func() { done <- containerdCmd.Wait() }() | ||
select { | ||
case <-done: | ||
// exited | ||
case <-time.After(time.Second): | ||
// timed out | ||
if err := containerdCmd.Process.Kill(); err != nil { | ||
t.Fatalf("Failed to kill containerd: %v", err) | ||
} | ||
} | ||
}) | ||
|
||
// pull test images | ||
for i := range testCases { | ||
tc := &testCases[i] | ||
t.Run(tc.Name, func(t *testing.T) { | ||
t.Parallel() | ||
// nolint:gosec | ||
pullCmd := exec.Command(filepath.Join(installDir, "ctr"), "--address="+socketAddress, "content", "fetch", tc.Ref()) | ||
testPull(t, tc, pullCmd) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023 The Kubernetes 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. | ||
|
||
# script to ensure containerd binaries for e2e testing | ||
set -o errexit -o nounset -o pipefail | ||
|
||
# cd to repo root | ||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd -P)" | ||
cd "${REPO_ROOT}" | ||
|
||
# script inputs, install dir should be versioned | ||
readonly CONTAINERD_VERSION="${CONTAINERD_VERSION:?}" | ||
readonly CONTAINERD_INSTALL_DIR="${CONTAINERD_INSTALL_DIR:?}" | ||
|
||
containerd_path="${CONTAINERD_INSTALL_DIR}/containerd" | ||
if [[ -f "${containerd_path}" ]] && "${containerd_path}" --version | grep -q "${CONTAINERD_VERSION}"; then | ||
echo "Already have ${containerd_path} ${CONTAINERD_VERSION}" | ||
else | ||
# downlod containerd to bindir | ||
mkdir -p "${CONTAINERD_INSTALL_DIR}" | ||
wget -qO- \ | ||
"https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION}/containerd-${CONTAINERD_VERSION}-linux-amd64.tar.gz" \ | ||
| tar -C "${CONTAINERD_INSTALL_DIR}/" -zxvf - --strip-components=1 | ||
fi | ||
|
||
# generate config for current user | ||
cat <<EOF >"${CONTAINERD_INSTALL_DIR}"/containerd-config.toml | ||
# own socket as as current user. | ||
# we will be running as this user and only fetching | ||
[grpc] | ||
uid = $(id -u) | ||
gid = $(id -g) | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters