Skip to content

Commit 208c718

Browse files
committed
Use OCI_BIN to determine where to load images from in integration tests
Modified the Makefile to respect the `OCI_BIN` environment variable, switching from `kind load docker-image` to `kind load image-archive`. This change enables support for both Docker and Podman, depending on the value of `OCI_BIN`. Updated the integration test suite to utilise the new loadimagearchive addon instead of the original loadimage addon. The addon also respects the `OCI_BIN` variable, ensuring images are loaded into kind clusters from the correct container engine. Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
1 parent 32e2dcc commit 208c718

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SHELL = /usr/bin/env bash -o pipefail
7373
# Image building tool (docker / podman) - docker is preferred in CI
7474
OCI_BIN_PATH := $(shell which docker 2>/dev/null || which podman)
7575
OCI_BIN ?= $(shell basename ${OCI_BIN_PATH})
76+
export OCI_BIN
7677

7778
GOARCH ?= $(shell go env GOHOSTARCH)
7879
PLATFORM ?= $(shell go env GOHOSTOS)/$(shell go env GOHOSTARCH)
@@ -355,7 +356,7 @@ push-images: ## Push bpfman-agent and bpfman-operator images.
355356

356357
.PHONY: load-images-kind
357358
load-images-kind: ## Load bpfman-agent, and bpfman-operator images into the running local kind devel cluster.
358-
kind load docker-image ${BPFMAN_OPERATOR_IMG} ${BPFMAN_AGENT_IMG} --name ${KIND_CLUSTER_NAME}
359+
./hack/kind-load-image.sh ${KIND_CLUSTER_NAME} ${BPFMAN_OPERATOR_IMG} ${BPFMAN_AGENT_IMG}
359360

360361
.PHONY: bundle-build
361362
bundle-build: ## Build the bundle image.

hack/kind-load-image.sh

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Load container images into a specified kind (Kubernetes IN Docker)
4+
# cluster. Save images from either Docker or Podman, depending on the
5+
# OCI_BIN environment variable. Defaults to Docker if OCI_BIN is not
6+
# set.
7+
#
8+
# Usage:
9+
# ./kind-load-image.sh [-v] <KIND-CLUSTER-NAME> <IMAGE-REFERENCE> [<IMAGE-REFERENCE> ...]
10+
#
11+
# Arguments:
12+
# -v Verbose mode; echo commands before executing them.
13+
# KIND-CLUSTER-NAME Specify the name of the kind cluster.
14+
# IMAGE-REFERENCE Specify one or more image references
15+
# (e.g., quay.io/bpfman/bpfman:latest).
16+
#
17+
# Example:
18+
# ./kind-load-image.sh -v my-cluster quay.io/bpfman/bpfman:latest quay.io/bpfman/bpfman-operator:latest
19+
#
20+
# The script:
21+
# 1. Save each specified image as a tar file using the specified
22+
# OCI_BIN (Docker or Podman).
23+
# 2. Load each tar file into the specified kind cluster.
24+
# 3. Clean up temporary files created during the process.
25+
#
26+
# Ensure that the specified kind cluster is already running before
27+
# executing the script.
28+
29+
set -o errexit
30+
set -o nounset
31+
set -o pipefail
32+
33+
# Parse options
34+
verbose=0
35+
if [ "$1" = "-v" ]; then
36+
verbose=1
37+
shift
38+
fi
39+
40+
if [ $# -lt 2 ]; then
41+
echo "Usage: ${0##*/} [-v] <KIND_CLUSTER_NAME> <IMAGE REFERENCE> [<IMAGE REFERENCE> ...]"
42+
exit 1
43+
fi
44+
45+
kind_cluster_name="$1"
46+
shift
47+
48+
: "${OCI_BIN:=docker}"
49+
50+
tmp_dir=$(mktemp -d -t bpfman-XXXXXX)
51+
52+
cleanup() {
53+
rm -r "$tmp_dir"
54+
}
55+
56+
trap cleanup EXIT
57+
58+
save_args=""
59+
if [ "$OCI_BIN" = "podman" ]; then
60+
save_args="--quiet"
61+
fi
62+
63+
counter=1
64+
for image_reference in "$@"; do
65+
tar_file="$tmp_dir/image-$counter.tar"
66+
67+
if [ $verbose -eq 1 ]; then
68+
echo "$OCI_BIN save $save_args --output \"$tar_file\" \"$image_reference\""
69+
fi
70+
"$OCI_BIN" save $save_args --output "$tar_file" "$image_reference"
71+
72+
if [ $verbose -eq 1 ]; then
73+
echo "kind load image-archive --name \"$kind_cluster_name\" \"$tar_file\""
74+
fi
75+
kind load image-archive --name "$kind_cluster_name" "$tar_file"
76+
77+
counter=$((counter + 1))
78+
done

test/integration/suite_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
14-
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/loadimage"
1514
"github.com/kong/kubernetes-testing-framework/pkg/clusters/types/kind"
1615
"github.com/kong/kubernetes-testing-framework/pkg/environments"
1716
"k8s.io/apimachinery/pkg/api/errors"
@@ -22,6 +21,8 @@ import (
2221
"github.com/bpfman/bpfman-operator/internal"
2322
"github.com/bpfman/bpfman-operator/pkg/client/clientset"
2423
bpfmanHelpers "github.com/bpfman/bpfman-operator/pkg/helpers"
24+
25+
"github.com/bpfman/bpfman-operator/test/integration/loadimagearchive"
2526
)
2627

2728
var (
@@ -50,6 +51,11 @@ const (
5051
func TestMain(m *testing.M) {
5152
logf.SetLogger(zap.New())
5253

54+
ociBin := os.Getenv("OCI_BIN")
55+
if ociBin == "" {
56+
ociBin = "docker" // default if OCI_BIN is not set.
57+
}
58+
5359
// check that we have the bpfman-agent, and bpfman-operator images to use for the tests.
5460
// generally the runner of the tests should have built these from the latest
5561
// changes prior to the tests and fed them to the test suite.
@@ -64,7 +70,7 @@ func TestMain(m *testing.M) {
6470

6571
// to use the provided bpfman-agent, and bpfman-operator images we will need to add
6672
// them as images to load in the test cluster via an addon.
67-
loadImages, err := loadimage.NewBuilder().WithImage(bpfmanAgentImage)
73+
loadImages, err := loadimagearchive.NewBuilder(ociBin).WithImage(bpfmanAgentImage)
6874
exitOnErr(err)
6975
loadImages, err = loadImages.WithImage(bpfmanOperatorImage)
7076
exitOnErr(err)
@@ -93,7 +99,7 @@ func TestMain(m *testing.M) {
9399
})
94100
}
95101

96-
// deploy the BPFMAN Operator and revelevant CRDs
102+
// deploy the BPFMAN Operator and relevant CRDs.
97103
fmt.Println("INFO: deploying bpfman operator to test cluster")
98104
exitOnErr(clusters.KustomizeDeployForCluster(ctx, env.Cluster(), bpfmanKustomize))
99105
if !keepKustomizeDeploys {

0 commit comments

Comments
 (0)