Skip to content

Commit

Permalink
Merge pull request #226 from BenTheElder/e2e-again
Browse files Browse the repository at this point in the history
add containerd to e2e tests
  • Loading branch information
k8s-ci-robot authored Apr 17, 2023
2 parents c3e216b + 72d724f commit c0a3102
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 6 deletions.
11 changes: 9 additions & 2 deletions cmd/archeio/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ and `make e2e-test-local`. We run `make e2e-test` against the staging instance.
These are limited to clients we can run locally and in containerize CI
without privilege escalation (e.g. [crane] again).

Results are at TODO: add testgrid pointer once these are merged and running
These run immediately in the staging deploy jobs and
continuously against the staging instance here:

https://testgrid.k8s.io/sig-k8s-infra-registry#registry-sandbox-e2e-gcp
https://testgrid.k8s.io/sig-k8s-infra-registry#registry-sandbox-e2e-aws

`make e2e-test-local` runs against PRs to ensure the e2e tests themselves work
and must pass before merge.

### Cluster e2e Testing

Expand All @@ -61,7 +68,7 @@ regions.

This E2E CI should be consulted before promoting code to stable release + registry.k8s.io.

Results are visible in [testgrid] at: https://testgrid.k8s.io/sig-k8s-infra-oci-proxy#Summary
Results are visible in [testgrid] at: https://testgrid.k8s.io/sig-k8s-infra-registry#Summary

The Kubernetes project itself has substantial assorted CI usage of the production instance
and many CI jobs that primarily exist for other purposes will alert us if pulling from it fails.
Expand Down
107 changes: 107 additions & 0 deletions cmd/archeio/internal/e2e/e2e_containerd_linux_test.go
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)
})
}
}
3 changes: 2 additions & 1 deletion hack/make-rules/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ go_test_opts=(
if [[ "${MODE}" = 'unit' ]]; then
go_test_opts+=('-tags=nointegration,noe2e')
elif [[ "${MODE}" = 'integration' ]]; then
go_test_opts+=('-run' '^TestIntegration')
go_test_opts+=('-run' '^TestIntegration' '-tags=noe2e')
else
go_test_opts+=('-tags=noe2e')
MODE="all"
fi

Expand Down
45 changes: 45 additions & 0 deletions hack/tools/ci-install-containerd.sh
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
4 changes: 1 addition & 3 deletions hack/tools/ci-install-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
# limitations under the License.

# script to install shellcheck in CI
set -o errexit
set -o nounset
set -o pipefail
set -o errexit -o nounset -o pipefail

# cd to repo root
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd -P)"
Expand Down

0 comments on commit c0a3102

Please sign in to comment.