Skip to content

Commit a44a1cb

Browse files
authored
Merge pull request #3296 from apostasie/dev-kube
Kube on the CI
2 parents 4bac741 + 97c5492 commit a44a1cb

10 files changed

+497
-157
lines changed

.github/workflows/test-kube.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This pipeline purpose is solely meant to run a subset of our test suites against a kube cluster
2+
name: kube
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- 'release/**'
9+
pull_request:
10+
paths-ignore:
11+
- '**.md'
12+
13+
env:
14+
ROOTFUL: true
15+
16+
jobs:
17+
linux:
18+
runs-on: "ubuntu-24.04"
19+
timeout-minutes: 40
20+
steps:
21+
- uses: actions/[email protected]
22+
with:
23+
fetch-depth: 1
24+
- name: "Run Kube integration tests"
25+
run: |
26+
./hack/build-integration-kube.sh
27+
sudo ./_output/nerdctl exec nerdctl-test-control-plane bash -c -- 'export TMPDIR="$HOME"/tmp; mkdir -p "$TMPDIR"; cd /nerdctl-source; /usr/local/go/bin/go test ./cmd/nerdctl/ -test.only-kube'

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,14 @@ jobs:
284284
timeout_minutes: 30
285285
max_attempts: 2
286286
retry_on: error
287-
command: go test -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.kill-daemon
287+
command: go test -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon
288288
- name: "Ensure that the IPv6 integration test suite is compatible with Docker"
289289
uses: nick-fields/retry@v3
290290
with:
291291
timeout_minutes: 30
292292
max_attempts: 2
293293
retry_on: error
294-
command: go test -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.kill-daemon -test.ipv6
294+
command: go test -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon -test.only-ipv6
295295

296296
test-integration-windows:
297297
runs-on: windows-2022

Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ RUN curl -o nydus-static.tgz -fsSL --proto '=https' --tlsv1.2 "https://github.co
319319
mv nydus-static/nydus-image nydus-static/nydusd nydus-static/nydusify /usr/bin/ && \
320320
rm nydus-static.tgz
321321
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=github.com/containerd/nerdctl/v2/cmd/nerdctl/...", \
322-
"--", "-timeout=60m", "-args", "-test.kill-daemon"]
322+
"--", "-timeout=60m", "-args", "-test.allow-kill-daemon"]
323323

324324
FROM test-integration AS test-integration-rootless
325325
# Install SSH for creating systemd user session.
@@ -345,7 +345,7 @@ COPY ./Dockerfile.d/test-integration-rootless.sh /
345345
CMD ["/test-integration-rootless.sh", \
346346
"gotestsum", "--format=testname", "--rerun-fails=2", "--raw-command", \
347347
"--", "/usr/local/go/bin/go", "tool", "test2json", "-t", "-p", "github.com/containerd/nerdctl/v2/cmd/nerdctl", \
348-
"/usr/local/bin/nerdctl.test", "-test.v", "-test.timeout=60m", "-test.kill-daemon"]
348+
"/usr/local/bin/nerdctl.test", "-test.v", "-test.timeout=60m", "-test.allow-kill-daemon"]
349349

350350
# test for CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns
351351
FROM test-integration-rootless AS test-integration-rootless-port-slirp4netns
@@ -354,6 +354,6 @@ RUN chown -R rootless:rootless /home/rootless/.config
354354

355355
FROM test-integration AS test-integration-ipv6
356356
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=github.com/containerd/nerdctl/v2/cmd/nerdctl/...", \
357-
"--", "-timeout=60m", "-args", "-test.kill-daemon", "-test.ipv6"]
357+
"--", "-timeout=60m", "-args", "-test.allow-kill-daemon", "-test.only-ipv6"]
358358

359359
FROM base AS demo
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"strings"
21+
"testing"
22+
23+
"gotest.tools/v3/icmd"
24+
25+
"github.com/containerd/nerdctl/v2/pkg/testutil"
26+
)
27+
28+
func TestKubeCommitPush(t *testing.T) {
29+
t.Parallel()
30+
31+
base := testutil.NewBaseForKube(t)
32+
tID := testutil.Identifier(t)
33+
34+
var containerID string
35+
36+
setup := func() {
37+
testutil.KubectlHelper(base, "run", "--image", testutil.CommonImage, tID, "--", "sleep", "Inf").
38+
AssertOK()
39+
40+
testutil.KubectlHelper(base, "wait", "pod", tID, "--for=condition=ready", "--timeout=1m").
41+
AssertOK()
42+
43+
testutil.KubectlHelper(base, "exec", tID, "--", "mkdir", "-p", "/tmp/whatever").
44+
AssertOK()
45+
46+
cmd := testutil.KubectlHelper(base, "get", "pods", tID, "-o", "jsonpath={ .status.containerStatuses[0].containerID }")
47+
cmd.Run()
48+
containerID = strings.TrimPrefix(cmd.Out(), "containerd://")
49+
}
50+
51+
tearDown := func() {
52+
testutil.KubectlHelper(base, "delete", "pod", tID).Run()
53+
}
54+
55+
tearDown()
56+
t.Cleanup(tearDown)
57+
setup()
58+
59+
t.Run("test commit / push on Kube (https://github.com/containerd/nerdctl/issues/827)", func(t *testing.T) {
60+
t.Log("This test is meant to verify that we can commit / push an image from a pod." +
61+
"Currently, this is broken, hence the test assumes it will fail. Once the problem is fixed, we should just" +
62+
"change the expectation to 'success'.")
63+
64+
base.Cmd("commit", containerID, "registry.example.com/my-app:v1").AssertOK()
65+
base.Cmd("push", "registry.example.com/my-app:v1").Assert(icmd.Expected{
66+
ExitCode: 1,
67+
Err: "failed to create a tmp single-platform image",
68+
})
69+
})
70+
}

cmd/nerdctl/container_run_restart_linux_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestRunRestart(t *testing.T) {
4141
}
4242
base := testutil.NewBase(t)
4343
if !base.DaemonIsKillable {
44-
t.Skip("daemon is not killable (hint: set \"-test.kill-daemon\")")
44+
t.Skip("daemon is not killable (hint: set \"-test.allow-kill-daemon\")")
4545
}
4646
t.Log("NOTE: this test may take a while")
4747

hack/build-integration-canary.sh

+6-144
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
# shellcheck disable=SC2034,SC2015
1818
set -o errexit -o errtrace -o functrace -o nounset -o pipefail
19+
root="$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)"
20+
readonly root
21+
# shellcheck source=/dev/null
22+
. "$root/scripts/lib.sh"
1923

2024
######################
2125
# Definitions
@@ -67,141 +71,6 @@ STARGZ_SNAPSHOTTER_CHECKSUM=linux
6771
# We specifically want the static ones
6872
TINI_CHECKSUM=static
6973

70-
71-
######################
72-
# Lib
73-
######################
74-
75-
# Simple logger
76-
readonly LOG_LEVEL_DEBUG=0
77-
readonly LOG_LEVEL_INFO=1
78-
readonly LOG_LEVEL_WARNING=2
79-
readonly LOG_LEVEL_ERROR=3
80-
81-
readonly LOG_COLOR_BLACK=0
82-
readonly LOG_COLOR_RED=1
83-
readonly LOG_COLOR_GREEN=2
84-
readonly LOG_COLOR_YELLOW=3
85-
readonly LOG_COLOR_BLUE=4
86-
readonly LOG_COLOR_MAGENTA=5
87-
readonly LOG_COLOR_CYAN=6
88-
readonly LOG_COLOR_WHITE=7
89-
readonly LOG_COLOR_DEFAULT=9
90-
91-
readonly LOG_STYLE_DEBUG=( setaf "$LOG_COLOR_WHITE" )
92-
readonly LOG_STYLE_INFO=( setaf "$LOG_COLOR_GREEN" )
93-
readonly LOG_STYLE_WARNING=( setaf "$LOG_COLOR_YELLOW" )
94-
readonly LOG_STYLE_ERROR=( setaf "$LOG_COLOR_RED" )
95-
96-
_log::log(){
97-
local level
98-
local style
99-
local numeric_level
100-
local message="$2"
101-
102-
level="$(printf "%s" "$1" | tr '[:lower:]' '[:upper:]')"
103-
numeric_level="$(printf "LOG_LEVEL_%s" "$level")"
104-
style="LOG_STYLE_${level}[@]"
105-
106-
[ "${!numeric_level}" -ge "$LOG_LEVEL" ] || return 0
107-
108-
[ ! "$TERM" ] || [ ! -t 2 ] || >&2 tput "${!style}" 2>/dev/null || true
109-
>&2 printf "[%s] %s: %s\n" "$(date 2>/dev/null || true)" "$(printf "%s" "$level" | tr '[:lower:]' '[:upper:]')" "$message"
110-
[ ! "$TERM" ] || [ ! -t 2 ] || >&2 tput op 2>/dev/null || true
111-
}
112-
113-
log::init(){
114-
local _ll
115-
# Default log to warning if unspecified
116-
_ll="$(printf "LOG_LEVEL_%s" "${NERDCTL_CI_LOG_LEVEL:-warning}" | tr '[:lower:]' '[:upper:]')"
117-
# Default to 3 (warning) if unrecognized
118-
LOG_LEVEL="${!_ll:-3}"
119-
}
120-
121-
log::debug(){
122-
_log::log debug "$@"
123-
}
124-
125-
log::info(){
126-
_log::log info "$@"
127-
}
128-
129-
log::warning(){
130-
_log::log warning "$@"
131-
}
132-
133-
log::error(){
134-
_log::log error "$@"
135-
}
136-
137-
# Helpers
138-
host::require(){
139-
local binary="$1"
140-
command -v "$binary" >/dev/null || {
141-
log::error "You need $binary for this script to work, and it cannot be found in your path"
142-
exit 1
143-
}
144-
}
145-
146-
fs::mktemp(){
147-
mktemp -dq "${TMPDIR:-/tmp}/$prefix.XXXXXX" 2>/dev/null || mktemp -dq || {
148-
log::error "Failed to create temporary directory"
149-
exit 1
150-
}
151-
}
152-
153-
http::get(){
154-
local args=(curl --proto '=https' --tlsv1.2 -fsSL)
155-
args+=("$@")
156-
157-
log::debug "${args[*]}"
158-
"${args[@]}"
159-
}
160-
161-
http::checksum(){
162-
local urls=("$@")
163-
local url
164-
165-
local prefix="nerdctl-checksum"
166-
167-
local temp
168-
temp="$(fs::mktemp)"
169-
170-
for url in "${urls[@]}"; do
171-
http::get -o "$temp/${url##*/}" "$url"
172-
done
173-
174-
cd "$temp"
175-
shasum -a 256 ./*
176-
cd - >/dev/null || true
177-
}
178-
179-
# Github API helpers
180-
# Set GITHUB_TOKEN to use authenticated requests to workaround limitations
181-
github::request(){
182-
local endpoint="$1"
183-
local args=(
184-
-H "Accept: application/vnd.github+json"
185-
-H "X-GitHub-Api-Version: 2022-11-28"
186-
)
187-
188-
[ "${GITHUB_TOKEN:-}" == "" ] || args+=(-H "Authorization: Bearer $GITHUB_TOKEN")
189-
190-
http::get "${args[@]}" https://api.github.com/"$endpoint"
191-
}
192-
193-
github::tags::getlatest(){
194-
local repo="$1"
195-
github::request "repos/$repo/tags" |
196-
jq -rc .[0].name
197-
}
198-
199-
github::releases::latest(){
200-
local repo="$1"
201-
github::request "repos/$repo/releases" |
202-
jq -rc .[]
203-
}
204-
20574
version::compare(){
20675
local raw_version_fd="$1"
20776
local parsed
@@ -304,7 +173,7 @@ latest::release(){
304173
higher_data="$line"
305174
higher_readable="$(echo "$line" | jq -rc .name | sed -E 's/(.*[ ])?(v?[0-9][0-9.a-z-]+).*/\2/')"
306175
fi
307-
done < <(github::releases::latest "$repo")
176+
done < <(github::releases "$repo")
308177

309178
log::info " >>> latest release detected: $higher_readable"
310179
}
@@ -314,7 +183,7 @@ latest::tag(){
314183
local repo="$1"
315184

316185
log::info "Analyzing tags for $repo"
317-
github::tags::getlatest "$repo"
186+
github::tags::latest "$repo"
318187
}
319188

320189
# Once a latest release has been retrieved for a given project, you can get the url to the asset matching OS and ARCH
@@ -342,13 +211,6 @@ assets::get(){
342211
}
343212
}
344213

345-
log::init
346-
host::require jq
347-
host::require curl
348-
host::require shasum
349-
host::require docker
350-
host::require tput
351-
352214
######################
353215
# Script
354216
######################

0 commit comments

Comments
 (0)