Skip to content

Commit 66ecaac

Browse files
authored
Test Registry (#1425)
Adds a bare-bones test registry and a folder tree for our test images. Signed-off-by: dtfranz <[email protected]>
1 parent 6bda277 commit 66ecaac

35 files changed

+484
-203
lines changed

Makefile

+12-14
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
165165
$(UNIT_TEST_DIRS) \
166166
-test.gocoverdir=$(ROOT_DIR)/coverage/unit
167167

168-
image-registry: ## Setup in-cluster image registry
169-
./hack/test/image-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME)
170-
171-
build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and push it to the image registry
172-
./hack/test/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(LOCAL_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V1)
173-
./hack/test/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(LOCAL_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V2)
168+
.PHONY: image-registry
169+
E2E_REGISTRY_IMAGE=localhost/e2e-test-registry:devel
170+
image-registry: export GOOS=linux
171+
image-registry: export GOARCH=amd64
172+
image-registry: ## Build the testdata catalog used for e2e tests and push it to the image registry
173+
go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o ./testdata/registry/bin/registry ./testdata/registry/registry.go
174+
go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o ./testdata/push/bin/push ./testdata/push/push.go
175+
$(CONTAINER_RUNTIME) build -f ./testdata/Dockerfile -t $(E2E_REGISTRY_IMAGE) ./testdata
176+
$(CONTAINER_RUNTIME) save $(E2E_REGISTRY_IMAGE) | $(KIND) load image-archive /dev/stdin --name $(KIND_CLUSTER_NAME)
177+
./testdata/build-test-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME) $(E2E_REGISTRY_IMAGE)
174178

175179
# When running the e2e suite, you can set the ARTIFACT_PATH variable to the absolute path
176180
# of the directory for the operator-controller e2e tests to store the artifacts, which
@@ -181,7 +185,7 @@ build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and pus
181185
test-e2e: KIND_CLUSTER_NAME := operator-controller-e2e
182186
test-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/e2e
183187
test-e2e: GO_BUILD_FLAGS := -cover
184-
test-e2e: run image-registry build-push-e2e-catalog registry-load-bundles e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster
188+
test-e2e: run image-registry e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster
185189

186190
.PHONY: extension-developer-e2e
187191
extension-developer-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/cert-manager
@@ -205,7 +209,7 @@ post-upgrade-checks:
205209
test-upgrade-e2e: KIND_CLUSTER_NAME := operator-controller-upgrade-e2e
206210
test-upgrade-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog
207211
test-upgrade-e2e: export TEST_CLUSTER_EXTENSION_NAME := test-package
208-
test-upgrade-e2e: kind-cluster run-latest-release image-registry build-push-e2e-catalog registry-load-bundles pre-upgrade-setup docker-build kind-load kind-deploy post-upgrade-checks kind-clean #HELP Run upgrade e2e tests on a local kind cluster
212+
test-upgrade-e2e: kind-cluster run-latest-release image-registry pre-upgrade-setup docker-build kind-load kind-deploy post-upgrade-checks kind-clean #HELP Run upgrade e2e tests on a local kind cluster
209213

210214
.PHONY: e2e-coverage
211215
e2e-coverage:
@@ -231,12 +235,6 @@ kind-cluster: $(KIND) #EXHELP Standup a kind cluster.
231235
kind-clean: $(KIND) #EXHELP Delete the kind cluster.
232236
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)
233237

234-
registry-load-bundles: ## Load selected e2e testdata container images created in kind-load-bundles into registry
235-
testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v1.0.0 prometheus-operator.v1.0.0 prometheus-operator.v1.0.0
236-
testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v1.0.1 prometheus-operator.v1.0.1 prometheus-operator.v1.0.0
237-
testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v1.2.0 prometheus-operator.v1.2.0 prometheus-operator.v1.0.0
238-
testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v2.0.0 prometheus-operator.v2.0.0 prometheus-operator.v1.0.0
239-
240238
#SECTION Build
241239

242240
ifeq ($(origin VERSION), undefined)

hack/test/build-push-e2e-catalog.sh

-66
This file was deleted.

test/e2e/cluster_extension_install_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) {
550550

551551
// patch imageRef tag on test-catalog image with v2 image
552552
t.Log("By patching the catalog ImageRef to point to the v2 catalog")
553-
updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("LOCAL_REGISTRY_HOST"))
553+
updatedCatalogImage := fmt.Sprintf("%s/test-catalog:v2", os.Getenv("LOCAL_REGISTRY_HOST"))
554554
err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage)
555555
require.NoError(t, err)
556556
require.EventuallyWithT(t, func(ct *assert.CollectT) {

testdata/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
push/bin
2+
registry/bin

testdata/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from gcr.io/distroless/static:nonroot
2+
3+
WORKDIR /
4+
5+
COPY registry/bin/registry registry
6+
COPY push/bin/push push
7+
8+
COPY images images
9+
10+
EXPOSE 5000
11+
12+
USER 65532:65532

hack/test/image-registry.sh renamed to testdata/build-test-registry.sh

+44-7
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
#! /bin/bash
1+
#!/bin/bash
22

33
set -o errexit
44
set -o nounset
55
set -o pipefail
66

77
help="
8-
image-registry.sh is a script to stand up an image registry within a cluster.
8+
build-test-registry.sh is a script to stand up an image registry within a cluster.
99
Usage:
10-
image-registry.sh [NAMESPACE] [NAME] [CERT_REF]
10+
build-test-registry.sh [NAMESPACE] [NAME] [IMAGE]
1111
1212
Argument Descriptions:
1313
- NAMESPACE is the namespace that should be created and is the namespace in which the image registry will be created
1414
- NAME is the name that should be used for the image registry Deployment and Service
15-
- CERT_REF is the reference to the CA certificate that should be used to serve the image registry over HTTPS, in the
16-
format of 'Issuer/<issuer-name>' or 'ClusterIssuer/<cluster-issuer-name>'
15+
- IMAGE is the name of the image that should be used to run the image registry
1716
"
1817

19-
if [[ "$#" -ne 2 ]]; then
18+
if [[ "$#" -ne 3 ]]; then
2019
echo "Illegal number of arguments passed"
2120
echo "${help}"
2221
exit 1
2322
fi
2423

2524
namespace=$1
2625
name=$2
26+
image=$3
2727

2828
kubectl apply -f - << EOF
2929
apiVersion: v1
@@ -69,7 +69,12 @@ spec:
6969
spec:
7070
containers:
7171
- name: registry
72-
image: registry:2
72+
image: ${image}
73+
imagePullPolicy: IfNotPresent
74+
command:
75+
- /registry
76+
args:
77+
- "--registry-address=:5000"
7378
volumeMounts:
7479
- name: certs-vol
7580
mountPath: "/certs"
@@ -100,3 +105,35 @@ spec:
100105
EOF
101106

102107
kubectl wait --for=condition=Available -n "${namespace}" "deploy/${name}" --timeout=60s
108+
109+
kubectl apply -f - << EOF
110+
apiVersion: batch/v1
111+
kind: Job
112+
metadata:
113+
name: ${name}-push
114+
namespace: "${namespace}"
115+
spec:
116+
template:
117+
spec:
118+
restartPolicy: Never
119+
containers:
120+
- name: push
121+
image: ${image}
122+
command:
123+
- /push
124+
args:
125+
- "--registry-address=${name}.${namespace}.svc:5000"
126+
- "--images-path=/images"
127+
volumeMounts:
128+
- name: certs-vol
129+
mountPath: "/certs"
130+
env:
131+
- name: SSL_CERT_DIR
132+
value: "/certs/"
133+
volumes:
134+
- name: certs-vol
135+
secret:
136+
secretName: ${namespace}-registry
137+
EOF
138+
139+
kubectl wait --for=condition=Complete -n "${namespace}" "job/${name}-push" --timeout=60s

testdata/bundles/registry-v1/build-push-e2e-bundle.sh

-84
This file was deleted.

testdata/bundles/registry-v1/prometheus-operator.v1.0.0/Dockerfile

-15
This file was deleted.

testdata/catalogs/test-catalog-v1.Dockerfile

-6
This file was deleted.

testdata/catalogs/test-catalog-v2.Dockerfile

-6
This file was deleted.

testdata/catalogs/test-catalog-v1/catalog.yaml renamed to testdata/images/catalogs/test-catalog/v1/configs/catalog.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ properties:
3232
schema: olm.bundle
3333
name: prometheus-operator.1.0.1
3434
package: prometheus
35-
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.1
35+
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0
3636
properties:
3737
- type: olm.package
3838
value:
@@ -42,7 +42,7 @@ properties:
4242
schema: olm.bundle
4343
name: prometheus-operator.1.2.0
4444
package: prometheus
45-
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.2.0
45+
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0
4646
properties:
4747
- type: olm.package
4848
value:
@@ -63,7 +63,7 @@ entries:
6363
schema: olm.bundle
6464
name: prometheus-mirrored-operator.1.2.0
6565
package: prometheus-mirrored
66-
image: mirrored-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.2.0
66+
image: mirrored-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0
6767
properties:
6868
- type: olm.package
6969
value:

testdata/catalogs/test-catalog-v2/catalog.yaml renamed to testdata/images/catalogs/test-catalog/v2/configs/catalog.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ entries:
1313
schema: olm.bundle
1414
name: prometheus-operator.2.0.0
1515
package: prometheus
16-
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v2.0.0
16+
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0
1717
properties:
1818
- type: olm.package
1919
value:

0 commit comments

Comments
 (0)