Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add upgrade e2e tests #299

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ jobs:
with:
go-version-file: "go.mod"
- run: make e2e
upgrade-e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Run the upgrade e2e test
run: make test-upgrade-e2e
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ verify: tidy fmt vet generate ## Verify the current code generation and lint
lint: $(GOLANGCI_LINT) ## Run golangci linter.
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS)

.PHONY: test-upgrade-e2e
test-upgrade-e2e: kind-cluster cert-manager build-container kind-load image-registry run-latest-release wait pre-upgrade-setup compare-catalog deploy wait ## Run upgrade e2e tests on a local kind cluster
test-upgrade-e2e:
${MAKE} compare-catalog
${MAKE} kind-cluster-cleanup

.PHONY: run-latest-release
run-latest-release:
kubectl apply -f https://github.com/operator-framework/catalogd/releases/latest/download/catalogd.yaml

.PHONY: pre-upgrade-setup
pre-upgrade-setup:
test/tools/imageregistry/pre-upgrade-setup.sh

.PHONY: compare-catalog
compare-catalog:
test/tools/imageregistry/compare-catalog.sh # compare test catalog with expected contents
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the actual upgrade comparisons be written in a separate Go test suite instead of using a shell script?

I think this would make it easier to communicate with the catalogd HTTP server and be easier to extend the test suite in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitathomas In operator-framework/operator-controller#1003 I started with simple bash, but we ended up extending checks there so I replacing post-upgrade-checks with go test.

You might want to take a similar approach.

I think this would make it easier to communicate with the catalogd HTTP server and be easier to extend the test suite in the future.

We run go test from outside of the cluster. Instead of kubectl port-forward & curl which I suggested earlier we will have to proxy somehow with client-go. We cam probably take some inspiration from kubectl port-forward


##@ Build

BINARIES=manager
Expand Down Expand Up @@ -185,6 +203,7 @@ undeploy: $(KUSTOMIZE) ## Undeploy Catalogd from the K8s cluster specified in ~/

wait:
kubectl wait --for=condition=Available --namespace=$(CATALOGD_NAMESPACE) deployment/catalogd-controller-manager --timeout=60s
kubectl wait --for=condition=Ready --namespace=$(CATALOGD_NAMESPACE) certificate/catalogd-catalogserver-cert # Avoid upgrade test flakes when reissuing cert

.PHONY: cert-manager
cert-manager:
Expand Down
20 changes: 20 additions & 0 deletions test/tools/imageregistry/compare-catalog.pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
name: catalogd-compare
namespace: catalogd-e2e
spec:
containers:
- image: radial/busyboxplus:curl
imagePullPolicy: IfNotPresent
command: ["sh", "-c", "curl -k https://catalogd-catalogserver.olmv1-system.svc.cluster.local/catalogs/test-catalog/all.json | diff build-contents/expected_all.json -"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to get rid of hardcoded test-catalog

name: compare-catalog-contents
volumeMounts:
- mountPath: /build-contents
name: build-contents
readOnly: true
restartPolicy: Never
volumes:
- configMap:
name: catalogd-e2e.build-contents
name: build-contents
16 changes: 16 additions & 0 deletions test/tools/imageregistry/compare-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e

# compare-catalog.sh compares the contents of the clusterCatalog created by registry.sh
# matches the expected contents in testdata/catalogs/test-catalog/expected_all.json.

# delete any pods persisting from earlier tests
kubectl delete --ignore-not-found --wait -f test/tools/imageregistry/compare-catalog.pod.yaml
kubectl create -f test/tools/imageregistry/compare-catalog.pod.yaml
# wait till pod terminates
kubectl wait -f test/tools/imageregistry/compare-catalog.pod.yaml --for=jsonpath='{.status.containerStatuses[0].state.terminated}'
kubectl logs --all-containers=true -f -n catalogd-e2e catalogd-compare
Comment on lines +8 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider using kubectl port-forward for this? Sounds like it is going to be easier to request the catalog: no need for a temporary pod.

if [ "$(kubectl get -f test/tools/imageregistry/compare-catalog.pod.yaml -o jsonpath={.status.containerStatuses[0].state.terminated.exitCode})" -ne 0 ]; then
exit 1
fi
21 changes: 21 additions & 0 deletions test/tools/imageregistry/pre-upgrade-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -euo pipefail

TEST_CATALOG_NAME=${TEST_CATALOG_NAME:-"test-catalog"}
TEST_CATALOG_IMAGE=${TEST_CATALOG_IMAGE:-"docker-registry.catalogd-e2e.svc:5000/test-catalog:e2e"}

kubectl apply -f - << EOF
apiVersion: catalogd.operatorframework.io/v1alpha1
kind: ClusterCatalog
metadata:
name: ${TEST_CATALOG_NAME}
spec:
source:
type: image
image:
ref: ${TEST_CATALOG_IMAGE}
insecureSkipTLSVerify: true
EOF

kubectl wait --for=condition=Unpacked --timeout=60s ClusterCatalog $TEST_CATALOG_NAME