Skip to content

Commit 992da07

Browse files
committed
test: side-load the PR/CI-built NPD image into node e2e
The node e2e "NodeProblemDetector" test deploys a pod running NODE_PROBLEM_DETECTOR_IMAGE. To exercise the image built from this PR/CI run rather than one pulled from a registry, build a single-arch image archive, upload it next to the release tarball, and have the node e2e VM import it into containerd with `ctr images import` -- no registry involved. - Makefile: add build-image-archive (linux/amd64, docker-archive output). - build.sh: build and upload the archive for pr/ci; record its URL in the env file alongside the local image ref. - test/sideload-image.sh: instance startup-script that downloads the archive and imports it into the k8s.io containerd namespace once containerd is up. Requires a companion test-infra change to the ci-/pull-npd-e2e-node jobs (--instance-metadata=startup-script<test/sideload-image.sh,npd-image-url=... and --prepull-images=false). That change is backward compatible and can land first; until both are in, the e2e prepull still pulls from a registry. Signed-off-by: Davanum Srinivas <davanum@gmail.com>
1 parent 8a5df6d commit 992da07

3 files changed

Lines changed: 76 additions & 6 deletions

File tree

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ NPD_NAME_VERSION?=node-problem-detector-$(VERSION)
6363
# TARBALL is the name of release tar. Include binary version by default.
6464
TARBALL=$(NPD_NAME_VERSION).tar.gz
6565

66+
# IMAGE_ARCHIVE is the single-arch (linux/amd64) image tarball built by
67+
# `build-image-archive` for side-loading onto node e2e VMs.
68+
IMAGE_ARCHIVE?=node-problem-detector-image.tar
69+
6670
# IMAGE_TAGS contains the image tags of the node problem detector container image.
6771
IMAGE_TAGS=--tag $(REGISTRY)/node-problem-detector:$(TAG)
6872
IMAGE_TAGS_WINDOWS=--tag $(REGISTRY)/node-problem-detector-windows:$(TAG)
@@ -304,6 +308,12 @@ build-container: clean Dockerfile
304308
docker buildx create --platform $(DOCKER_PLATFORMS) --use
305309
docker buildx build --platform $(DOCKER_PLATFORMS) $(IMAGE_TAGS) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
306310

311+
# build-image-archive builds the linux/amd64 image into a docker-archive tarball
312+
# ($(IMAGE_ARCHIVE)) for side-loading onto node e2e VMs with `ctr images import`.
313+
build-image-archive: clean Dockerfile
314+
docker buildx create --platform linux/amd64 --use
315+
docker buildx build --platform linux/amd64 --output type=docker,dest=$(IMAGE_ARCHIVE) $(IMAGE_TAGS) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
316+
307317
build-container-windows: clean Dockerfile.windows
308318
docker buildx create --platform windows/amd64 --use
309319
docker buildx build --platform windows/amd64 $(IMAGE_TAGS_WINDOWS) -f Dockerfile.windows .

test/build.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ set -o pipefail
2323

2424

2525
NPD_STAGING_PATH=${NPD_STAGING_PATH:-"gs://k8s-staging-npd"}
26-
NPD_STAGING_REGISTRY=${NPD_STAGING_REGISTRY:-"gcr.io/node-problem-detector-staging"}
26+
NPD_STAGING_REGISTRY=${NPD_STAGING_REGISTRY:-"gcr.io/k8s-staging-npd"}
27+
# IMAGE_ARCHIVE is a single-arch (linux/amd64) image tarball that the node e2e
28+
# VM side-loads into containerd (see test/sideload-image.sh), so the test runs
29+
# the image built from this PR/CI run without pushing to a registry.
30+
IMAGE_ARCHIVE=${IMAGE_ARCHIVE:-"node-problem-detector-image.tar"}
2731
PR_ENV_FILENAME=${PR_ENV_FILENAME:-"pr.env"}
2832
CI_ENV_FILENAME=${CI_ENV_FILENAME:-"ci.env"}
2933
CI_CUSTOM_FLAGS_ENV_FILENAME=${CI_CUSTOM_FLAGS_ENV_FILENAME:-"ci-custom-flags.env"}
@@ -81,6 +85,7 @@ export NODE_PROBLEM_DETECTOR_RELEASE_PATH=${UPLOAD_PATH/gs:\/\//${GCS_URL_PREFIX
8185
export NODE_PROBLEM_DETECTOR_VERSION=${VERSION}
8286
export NODE_PROBLEM_DETECTOR_TAR_HASH=$(sha1sum ${ROOT_PATH}/node-problem-detector-${VERSION}-linux_amd64.tar.gz | cut -d ' ' -f1)
8387
export EXTRA_ENVS=NODE_PROBLEM_DETECTOR_IMAGE=${REGISTRY}/node-problem-detector:${TAG}
88+
export NODE_PROBLEM_DETECTOR_IMAGE_ARCHIVE_URL=${UPLOAD_PATH/gs:\/\//${GCS_URL_PREFIX}}/${IMAGE_ARCHIVE}
8489
EOF
8590

8691
if [[ -n "${NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS:-}" ]]; then
@@ -129,7 +134,8 @@ function build-pr() {
129134
export REGISTRY="${NPD_STAGING_REGISTRY}/pr/${PR}"
130135
export VERSION=$(get-version)
131136
export TAG="${VERSION}"
132-
make push-tar
137+
make push-tar build-image-archive
138+
gsutil cp "${ROOT_PATH}/${IMAGE_ARCHIVE}" "${UPLOAD_PATH}/"
133139
write-env-file ${PR_ENV_FILENAME}
134140
}
135141

@@ -139,10 +145,11 @@ function build-ci() {
139145
export REGISTRY="${NPD_STAGING_REGISTRY}/ci"
140146
export VERSION="$(get-version)-$(date +%Y%m%d.%H%M)"
141147
export TAG="${VERSION}"
142-
# e2e tests consume the tarball, not the container
143-
# this is simpler to manage in the infra, and we still ensure the container
144-
# build works locally
145-
make push-tar build-container
148+
# The cluster e2e jobs consume the tarball; the node e2e test side-loads the
149+
# image archive built here (see test/sideload-image.sh). Nothing is pushed to
150+
# a registry.
151+
make push-tar build-image-archive
152+
gsutil cp "${ROOT_PATH}/${IMAGE_ARCHIVE}" "${UPLOAD_PATH}/"
146153

147154
# Create the env file with and without custom flags at the same time.
148155
build-npd-custom-flags

test/sideload-image.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Copyright 2026 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Side-loads the node-problem-detector image built by this PR/CI run onto a
18+
# node e2e VM so the kubernetes "NodeProblemDetector" test exercises that image
19+
# instead of pulling one from a registry.
20+
#
21+
# It is wired in as the instance startup-script by the ci-/pull-npd-e2e-node
22+
# jobs, and reads the archive URL (uploaded by test/build.sh) from instance
23+
# metadata. With --prepull-images=false and the pod's IfNotPresent policy, the
24+
# imported image is used without any registry pull. No-op when the metadata is
25+
# absent, so the job is safe to enable before build.sh starts publishing it.
26+
27+
set -o errexit
28+
set -o nounset
29+
set -o pipefail
30+
31+
readonly META="http://metadata.google.internal/computeMetadata/v1/instance/attributes"
32+
33+
url="$(curl -sf -H 'Metadata-Flavor: Google' "${META}/npd-image-url" || true)"
34+
if [[ -z "${url}" ]]; then
35+
echo "npd-image-url instance metadata not set; nothing to side-load"
36+
exit 0
37+
fi
38+
39+
echo "Downloading node-problem-detector image archive from ${url}"
40+
curl -fsSL --retry 5 --retry-delay 3 -o /tmp/npd-image.tar "${url}"
41+
42+
# init.yaml restarts containerd near the end of node setup; wait for it before
43+
# importing into the CRI (k8s.io) namespace that the kubelet uses.
44+
for _ in $(seq 1 90); do
45+
if ctr -n k8s.io version >/dev/null 2>&1; then
46+
break
47+
fi
48+
sleep 2
49+
done
50+
51+
echo "Importing node-problem-detector image into containerd"
52+
ctr -n k8s.io images import /tmp/npd-image.tar
53+
ctr -n k8s.io images ls | grep node-problem-detector || true

0 commit comments

Comments
 (0)