Skip to content

Commit 94e5712

Browse files
author
Per Goncalves da Silva
committed
add internal registry
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 442c42d commit 94e5712

File tree

10 files changed

+471
-25
lines changed

10 files changed

+471
-25
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ jobs:
2222
- uses: actions/setup-go@v5
2323
with:
2424
go-version-file: "go.mod"
25-
# add the fixtures changed flag (UPDATE_FIXTURES) to the job output to others can use it
26-
- name: Rebuild fixtures if necessary
27-
id: fixtures
28-
run: |
29-
UPDATE_FIXTURES="$(scripts/e2e_test_fixtures.sh --check)"
30-
if [ "${UPDATE_FIXTURES}" == "true" ]; then
31-
# rebuild fixtures and export the images to .tar.gz files with --save
32-
scripts/e2e_test_fixtures.sh --save
33-
fi
34-
35-
# Add UPDATE_FIXTURES to the job output
36-
echo "UPDATE_FIXTURES=${UPDATE_FIXTURES}" >> $GITHUB_OUTPUT
37-
3825
# build binaries and image for e2e test (includes experimental features)
3926
- name: Build OLM Image
4027
run: |
@@ -106,7 +93,7 @@ jobs:
10693
KIND_CREATE_OPTS="--kubeconfig=${E2E_KUBECONFIG_ROOT}/kubeconfig-${i}" \
10794
HELM_INSTALL_OPTS="--kubeconfig ${E2E_KUBECONFIG_ROOT}/kubeconfig-${i}" \
10895
UPDATE_FIXTURES="${{ needs.build.outputs.UPDATE_FIXTURES }}" \
109-
make kind-create deploy;
96+
make kind-create image-registry build-and-load-e2e-fixture-images deploy;
11097
done
11198
11299
# run non-flakes if matrix-id is not 'flakes'

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,26 @@ kind-create: kind-clean #HELP Create a new kind cluster $KIND_CLUSTER_NAME (defa
210210
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_CLUSTER_IMAGE) $(KIND_CREATE_OPTS)
211211
$(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME)
212212

213+
.PHONY: image-registry
214+
E2E_REGISTRY_NAME := docker-registry
215+
E2E_REGISTRY_NAMESPACE := olm-e2e
216+
export REGISTRY_ROOT := $(E2E_REGISTRY_NAME).$(E2E_REGISTRY_NAMESPACE).svc:5000
217+
export CATALOG_IMG := $(REGISTRY_ROOT)/test-catalog:e2e
218+
image-registry: ## Setup in-cluster image registry
219+
./scripts/image_registry.sh "$(E2E_REGISTRY_NAMESPACE)" "$(E2E_REGISTRY_NAME)"
220+
221+
.PHONY: build-and-load-e2e-fixture-images
222+
build-and-load-e2e-fixture-images: # Build e2e fixture images and either kind-load or push them to an on-cluster registry
223+
# build and kind-load fixture images
224+
scripts/e2e_test_fixtures.sh --kind-load
225+
226+
# push the test-catalog to an on-cluster registry
227+
./scripts/publish_e2e_catalog.sh $(E2E_REGISTRY_NAMESPACE) $(CATALOG_IMG)
228+
213229
.PHONY: deploy
214230
OLM_IMAGE := quay.io/operator-framework/olm:local
215231
deploy: $(KIND) $(HELM) #HELP Deploy OLM to kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) using $OLM_IMAGE (default: quay.io/operator-framework/olm:local)
216232
$(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME)
217-
@if [ "${UPDATE_FIXTURES}" = "true" ]; then \
218-
scripts/e2e_test_fixtures.sh --kind-load --skip-build; \
219-
fi
220233
$(HELM) upgrade --install olm deploy/chart \
221234
--set debug=true \
222235
--set olm.image.ref=$(OLM_IMAGE) \

scripts/e2e_test_fixtures.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ if [ "$BUILD" = "true" ]; then
128128
# See catalog_e2e_test.go
129129
# let's just reuse one of the other catalogs for this - the tests don't care about the content
130130
# only that a catalog's content can be extracted and served by a different container
131+
# There is no point in kind-loading this image since the image pull policy is AlwaysPull
132+
# This image will be published in an on cluster registry
131133
${CONTAINER_RUNTIME} tag "${INDEX_V2}" "${TEST_CATALOG_IMAGE}"
132134
fi
133135

@@ -139,7 +141,6 @@ if [ "$LOAD_KIND" = true ]; then
139141
${KIND} load docker-image --name="${KIND_CLUSTER_NAME}" "${BUNDLE_V2_DEP_IMAGE}"
140142
${KIND} load docker-image --name="${KIND_CLUSTER_NAME}" "${INDEX_V1}"
141143
${KIND} load docker-image --name="${KIND_CLUSTER_NAME}" "${INDEX_V2}"
142-
${KIND} load docker-image --name="${KIND_CLUSTER_NAME}" "${TEST_CATALOG_IMAGE}"
143144
fi
144145

145146
# Assumes images are already built
@@ -152,8 +153,6 @@ if [ "${SAVE}" = true ]; then
152153

153154
${CONTAINER_RUNTIME} save "${INDEX_V1}" | gzip > indexv1.tar.gz
154155
${CONTAINER_RUNTIME} save "${INDEX_V2}" | gzip > indexv2.tar.gz
155-
156-
${CONTAINER_RUNTIME} save "${TEST_CATALOG_IMAGE}" | gzip > testcatalog.tar.gz
157156
fi
158157

159158
# Assumes images are already built
@@ -167,7 +166,4 @@ if [ "$PUSH" = true ]; then
167166
# push indexes
168167
${CONTAINER_RUNTIME} push "${INDEX_V1}"
169168
${CONTAINER_RUNTIME} push "${INDEX_V2}"
170-
171-
# push test catalog
172-
${CONTAINER_RUNTIME} push "${TEST_CATALOG_IMAGE}"
173169
fi

scripts/generate_registry_cert.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
help="
6+
generate_registry_cert.sh is a script to generate the self-signed certificates used by the internal registry.
7+
Usage:
8+
generate_registry_cert.sh [NAMESPACE] [NAME]
9+
10+
Argument Descriptions:
11+
- NAMESPACE is the namespace that should be created and is the namespace in which the image registry will be created
12+
- NAME is the name that should be used for the image registry Deployment and Service
13+
"
14+
15+
if [[ "$#" -ne 2 ]]; then
16+
echo "Illegal number of arguments passed"
17+
echo "${help}"
18+
exit 1
19+
fi
20+
21+
namespace=$1
22+
name=$2
23+
24+
# Generate ECDSA private key
25+
openssl ecparam -genkey -name prime256v1 -out tls.key
26+
27+
# Create CSR configuration file (csr.conf)
28+
cat <<EOF > csr.conf
29+
[ req ]
30+
prompt = no
31+
distinguished_name = dn
32+
x509_extensions = v3_req
33+
req_extensions = req_ext
34+
35+
[ dn ]
36+
CN = ${name}.${namespace}.svc
37+
38+
[ req_ext ]
39+
subjectAltName = @alt_names
40+
41+
[ alt_names ]
42+
DNS.1 = ${name}.${namespace}.svc
43+
DNS.2 = ${name}.${namespace}.cluster.local
44+
EOF
45+
46+
# Generate CSR
47+
openssl req -new -key tls.key -out tls.csr -config csr.conf
48+
49+
# Create certificate configuration file (cert.conf)
50+
cat <<EOF > cert.conf
51+
[ req ]
52+
prompt = no
53+
distinguished_name = dn
54+
x509_extensions = v3_req
55+
req_extensions = req_ext
56+
57+
[ dn ]
58+
CN = ${name}.${namespace}.svc
59+
60+
[ v3_req ]
61+
subjectAltName = @alt_names
62+
basicConstraints = CA:TRUE
63+
64+
[ alt_names ]
65+
DNS.1 = ${name}.${namespace}.svc
66+
DNS.2 = ${name}.${namespace}.cluster.local
67+
EOF
68+
69+
# Generate self-signed certificate
70+
openssl req -x509 -key tls.key -in tls.csr -out tls.crt -days 3650 -config cert.conf
71+
72+
# Remove temporary files
73+
rm -rf cert.conf csr.conf tls.csr

scripts/image_registry.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#! /bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
set -x
8+
9+
help="
10+
image_registry.sh is a script to stand up an image registry within a cluster.
11+
Usage:
12+
image_registry.sh [NAMESPACE] [NAME]
13+
14+
Argument Descriptions:
15+
- NAMESPACE is the namespace that should be created and is the namespace in which the image registry will be created
16+
- NAME is the name that should be used for the image registry Deployment and Service
17+
"
18+
19+
if [[ "$#" -ne 2 ]]; then
20+
echo "Illegal number of arguments passed"
21+
echo "${help}"
22+
exit 1
23+
fi
24+
25+
namespace=$1
26+
name=$2
27+
28+
# Generate self-signed TLS certificate
29+
./scripts/generate_registry_cert.sh "${namespace}" "${name}"
30+
31+
# Read and base64 encode the certificate and key files
32+
CERT_FILE=$(cat "tls.crt" | base64 | tr -d '\n')
33+
KEY_FILE=$(cat "tls.key" | base64 | tr -d '\n')
34+
35+
kubectl apply -f - << EOF
36+
apiVersion: v1
37+
kind: Namespace
38+
metadata:
39+
name: ${namespace}
40+
---
41+
apiVersion: v1
42+
kind: Secret
43+
metadata:
44+
name: ${namespace}-registry
45+
namespace: ${namespace}
46+
type: Opaque
47+
data:
48+
tls.crt: "${CERT_FILE}"
49+
tls.key: "${KEY_FILE}"
50+
---
51+
apiVersion: apps/v1
52+
kind: Deployment
53+
metadata:
54+
name: ${name}
55+
namespace: ${namespace}
56+
labels:
57+
app: registry
58+
spec:
59+
replicas: 1
60+
selector:
61+
matchLabels:
62+
app: registry
63+
template:
64+
metadata:
65+
labels:
66+
app: registry
67+
spec:
68+
containers:
69+
- name: registry
70+
image: registry:2
71+
volumeMounts:
72+
- name: certs-vol
73+
mountPath: "/certs"
74+
env:
75+
- name: REGISTRY_HTTP_TLS_CERTIFICATE
76+
value: "/certs/tls.crt"
77+
- name: REGISTRY_HTTP_TLS_KEY
78+
value: "/certs/tls.key"
79+
volumes:
80+
- name: certs-vol
81+
secret:
82+
secretName: ${namespace}-registry
83+
---
84+
apiVersion: v1
85+
kind: Service
86+
metadata:
87+
name: ${name}
88+
namespace: ${namespace}
89+
spec:
90+
selector:
91+
app: registry
92+
ports:
93+
- port: 5000
94+
targetPort: 5000
95+
EOF
96+
97+
kubectl wait --for=condition=Available -n "${namespace}" "deploy/${name}" --timeout=60s
98+
99+
# Alternatively, just generate the pair once and save it to the repo. But then in 10 years we might need to generate a new certificate!
100+
rm -rf tls.crt tls.key

scripts/publish_e2e_catalog.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#! /bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
help="
8+
build-push-e2e-catalog.sh is a script to build and push the e2e catalog image using kaniko.
9+
Usage:
10+
build-push-e2e-catalog.sh [NAMESPACE] [TAG]
11+
12+
Argument Descriptions:
13+
- NAMESPACE is the namespace the kaniko Job should be created in
14+
- TAG is the full tag used to build and push the catalog image
15+
"
16+
17+
if [[ "$#" -ne 2 ]]; then
18+
echo "Illegal number of arguments passed"
19+
echo "${help}"
20+
exit 1
21+
fi
22+
23+
namespace=$1
24+
tag=$2
25+
26+
OPM_VERSION=${OPM_VERSION:-"latest"}
27+
28+
echo "${namespace}" "${tag}"
29+
30+
# Delete existing configmaps
31+
kubectl delete configmap -n "${namespace}" test-catalog.dockerfile --ignore-not-found
32+
kubectl delete configmap -n "${namespace}" test-catalog.build-contents --ignore-not-found
33+
34+
kubectl create configmap -n "${namespace}" --from-file=test/images/test-catalog/dockerfile test-catalog.dockerfile
35+
kubectl create configmap -n "${namespace}" --from-file=test/images/test-catalog/configs test-catalog.build-contents
36+
37+
kubectl apply -f - << EOF
38+
apiVersion: batch/v1
39+
kind: Job
40+
metadata:
41+
name: kaniko
42+
namespace: "${namespace}"
43+
spec:
44+
template:
45+
spec:
46+
containers:
47+
- name: kaniko
48+
image: gcr.io/kaniko-project/executor:latest
49+
args: [ "--build-arg=OPM_VERSION=${OPM_VERSION}",
50+
"--dockerfile=/workspace/dockerfile",
51+
"--context=/workspace",
52+
"--destination=${tag}",
53+
"--verbosity=trace",
54+
"--skip-tls-verify"]
55+
volumeMounts:
56+
- name: dockerfile
57+
mountPath: /workspace/
58+
- name: build-contents
59+
mountPath: /workspace/configs/
60+
restartPolicy: Never
61+
volumes:
62+
- name: dockerfile
63+
configMap:
64+
name: test-catalog.dockerfile
65+
items:
66+
- key: dockerfile
67+
path: dockerfile
68+
- name: build-contents
69+
configMap:
70+
name: test-catalog.build-contents
71+
EOF
72+
73+
kubectl wait --for=condition=Complete -n "${namespace}" jobs/kaniko --timeout=60s

test/e2e/catalog_e2e_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141
openshiftregistryFQDN = "image-registry.openshift-image-registry.svc:5000"
4242
catsrcImage = "docker://quay.io/olmtest/catsrc-update-test:"
4343
badCSVDir = "bad-csv"
44+
testCatalogImage = "docker-registry.olm-e2e.svc:5000/test-catalog:e2e"
4445
)
4546

4647
var _ = Describe("Starting CatalogSource e2e tests", func() {
@@ -49,7 +50,6 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
4950
c operatorclient.ClientInterface
5051
crc versioned.Interface
5152
packageserverClient *packageserverclientset.Clientset
52-
testCatalogImage string
5353
)
5454

5555
BeforeEach(func() {
@@ -68,7 +68,6 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
6868
c = ctx.Ctx().KubeClient()
6969
crc = ctx.Ctx().OperatorClient()
7070
packageserverClient = packageserverclientset.NewForConfigOrDie(ctx.Ctx().RESTConfig())
71-
testCatalogImage = fmt.Sprintf("quay.io/olmtest/test-catalog:v%s", testOpmVersion)
7271
})
7372

7473
AfterEach(func() {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/expected_all.json
2+
..*

0 commit comments

Comments
 (0)