Skip to content

Commit 1b86a11

Browse files
Akrogclaude
andcommitted
Add kuttl-test-ocp target for OpenShift internal registry
Allows running kuttl tests using the OpenShift internal image registry instead of an external registry like quay.io. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7aa283b commit 1b86a11

3 files changed

Lines changed: 132 additions & 0 deletions

File tree

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(TAG)
4242
CATALOG_NAME ?= openstack-lightspeed-catalog
4343
CATALOG_CHANNEL ?= alpha
4444

45+
# OpenShift internal registry support for local development/testing.
46+
OCP_REGISTRY_NAMESPACE ?= openstack-lightspeed
47+
OCP_INTERNAL_REGISTRY ?= image-registry.openshift-image-registry.svc:5000
48+
4549
# BUNDLE_IMG defines the image:tag used for the bundle.
4650
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
4751
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(TAG)
@@ -281,6 +285,20 @@ kuttl-test: kuttl ## Run kuttl tests
281285
.PHONY: kuttl-test-run
282286
kuttl-test-run: kuttl openstack-lightspeed-deploy kuttl-test openstack-lightspeed-undeploy
283287

288+
.PHONY: ocp-registry-push
289+
ocp-registry-push: ## Push images to the OpenShift internal registry.
290+
bash scripts/ocp-registry-push.sh $(CONTAINER_TOOL) $(OCP_REGISTRY_NAMESPACE) $(IMG) $(CATALOG_IMG)
291+
292+
.PHONY: ocp-catalog-build
293+
ocp-catalog-build: opm ## Build a catalog image for the OpenShift internal registry.
294+
bash scripts/ocp-catalog-build.sh $(CONTAINER_TOOL) $(BUNDLE_IMG) $(CATALOG_IMG) $(OPM)
295+
296+
.PHONY: kuttl-test-ocp
297+
kuttl-test-ocp: IMG = $(OCP_INTERNAL_REGISTRY)/$(OCP_REGISTRY_NAMESPACE)/operator:latest
298+
kuttl-test-ocp: BUNDLE_IMG = $(OCP_INTERNAL_REGISTRY)/openshift-marketplace/operator-bundle:$(TAG)
299+
kuttl-test-ocp: CATALOG_IMG = $(OCP_INTERNAL_REGISTRY)/openshift-marketplace/operator-catalog:$(TAG)
300+
kuttl-test-ocp: docker-build bundle bundle-build ocp-catalog-build ocp-registry-push kuttl-test-run
301+
284302
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
285303
# $1 - target path with name of binary
286304
# $2 - package url which can be installed

scripts/ocp-catalog-build.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Build a catalog image for use with the OpenShift internal registry.
3+
#
4+
# OPM cannot pull bundle images from the internal registry (unreachable from dev machine),
5+
# so this script:
6+
# 1. Pushes the bundle to the internal registry via the external route
7+
# 2. Uses OPM to build the catalog index from the external route (pullable)
8+
# 3. Fixes the bundlepath in the database to use the internal registry address
9+
# 4. Builds the final catalog image
10+
#
11+
# Usage: ocp-catalog-build.sh <container-tool> <bundle-img> <catalog-img> <opm>
12+
set -euo pipefail
13+
14+
CONTAINER_TOOL="${1:?Usage: $0 <container-tool> <bundle-img> <catalog-img> <opm>}"
15+
BUNDLE_IMG="${2:?Usage: $0 <container-tool> <bundle-img> <catalog-img> <opm>}"
16+
CATALOG_IMG="${3:?Usage: $0 <container-tool> <bundle-img> <catalog-img> <opm>}"
17+
OPM="${4:?Usage: $0 <container-tool> <bundle-img> <catalog-img> <opm>}"
18+
19+
INTERNAL_PREFIX="image-registry.openshift-image-registry.svc:5000"
20+
21+
echo "==> Ensuring the OpenShift image registry default route is exposed..."
22+
oc patch configs.imageregistry.operator.openshift.io/cluster \
23+
--type merge -p '{"spec":{"defaultRoute":true}}'
24+
25+
ROUTE_HOST="$(oc get route default-route -n openshift-image-registry \
26+
-o jsonpath='{.spec.host}')"
27+
if [ -z "${ROUTE_HOST}" ]; then
28+
echo "Error: could not obtain the registry route host."
29+
exit 1
30+
fi
31+
32+
ROUTE_BUNDLE="${BUNDLE_IMG/${INTERNAL_PREFIX}/${ROUTE_HOST}}"
33+
34+
echo "==> Logging in to the registry..."
35+
${CONTAINER_TOOL} login "${ROUTE_HOST}" -u "$(oc whoami)" -p "$(oc whoami -t)" --tls-verify=false
36+
37+
echo "==> Pushing bundle image to internal registry..."
38+
${CONTAINER_TOOL} tag "${BUNDLE_IMG}" "${ROUTE_BUNDLE}"
39+
${CONTAINER_TOOL} push "${ROUTE_BUNDLE}" --tls-verify=false
40+
${CONTAINER_TOOL} rmi "${ROUTE_BUNDLE}" 2>/dev/null || true
41+
42+
echo "==> Building catalog index from external route..."
43+
WORKDIR=$(mktemp -d)
44+
# shellcheck disable=SC2064
45+
trap "rm -rf ${WORKDIR}" EXIT
46+
47+
${OPM} index add \
48+
--build-tool "${CONTAINER_TOOL}" --pull-tool none --skip-tls-verify \
49+
--generate --mode semver \
50+
--out-dockerfile "${WORKDIR}/index.Dockerfile" \
51+
--bundles "${ROUTE_BUNDLE}" \
52+
--tag "${CATALOG_IMG}"
53+
mv database "${WORKDIR}/"
54+
55+
echo "==> Fixing bundle path in catalog database..."
56+
sqlite3 "${WORKDIR}/database/index.db" \
57+
"UPDATE operatorbundle SET bundlepath = REPLACE(bundlepath, '${ROUTE_HOST}', '${INTERNAL_PREFIX}');"
58+
59+
echo "==> Building catalog image..."
60+
${CONTAINER_TOOL} build -f "${WORKDIR}/index.Dockerfile" -t "${CATALOG_IMG}" "${WORKDIR}"
61+
62+
echo "==> Catalog image built successfully: ${CATALOG_IMG}"

scripts/ocp-registry-push.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
# Push images to the OpenShift internal image registry.
3+
#
4+
# Usage: ocp-registry-push.sh <container-tool> <namespace> <image1> [image2 ...]
5+
#
6+
# Each <imageN> must use the in-cluster registry address, e.g.:
7+
# image-registry.openshift-image-registry.svc:5000/my-ns/my-image:tag
8+
set -euo pipefail
9+
10+
CONTAINER_TOOL="${1:?Usage: $0 <container-tool> <namespace> <image1> [image2 ...]}"
11+
NAMESPACE="${2:?Usage: $0 <container-tool> <namespace> <image1> [image2 ...]}"
12+
shift 2
13+
14+
if [ $# -eq 0 ]; then
15+
echo "Error: at least one image must be specified"
16+
exit 1
17+
fi
18+
19+
INTERNAL_PREFIX="image-registry.openshift-image-registry.svc:5000"
20+
21+
echo "==> Ensuring the OpenShift image registry default route is exposed..."
22+
oc patch configs.imageregistry.operator.openshift.io/cluster \
23+
--type merge -p '{"spec":{"defaultRoute":true}}'
24+
25+
echo "==> Obtaining the external registry route..."
26+
ROUTE_HOST="$(oc get route default-route -n openshift-image-registry \
27+
-o jsonpath='{.spec.host}')"
28+
if [ -z "${ROUTE_HOST}" ]; then
29+
echo "Error: could not obtain the registry route host."
30+
exit 1
31+
fi
32+
echo " External route: ${ROUTE_HOST}"
33+
34+
echo "==> Ensuring namespace '${NAMESPACE}' exists..."
35+
oc create namespace "${NAMESPACE}" --dry-run=client -o yaml | oc apply -f -
36+
37+
echo "==> Logging in to the registry..."
38+
${CONTAINER_TOOL} login "${ROUTE_HOST}" -u "$(oc whoami)" -p "$(oc whoami -t)" --tls-verify=false
39+
40+
for IMAGE in "$@"; do
41+
PUSH_IMAGE="${IMAGE/${INTERNAL_PREFIX}/${ROUTE_HOST}}"
42+
if [ "${PUSH_IMAGE}" = "${IMAGE}" ]; then
43+
echo "Warning: image '${IMAGE}' does not start with '${INTERNAL_PREFIX}', pushing as-is."
44+
fi
45+
46+
echo "==> Pushing ${IMAGE} -> ${PUSH_IMAGE}"
47+
${CONTAINER_TOOL} tag "${IMAGE}" "${PUSH_IMAGE}"
48+
${CONTAINER_TOOL} push "${PUSH_IMAGE}" --tls-verify=false
49+
${CONTAINER_TOOL} rmi "${PUSH_IMAGE}" 2>/dev/null || true
50+
done
51+
52+
echo "==> All images pushed successfully."

0 commit comments

Comments
 (0)