Skip to content

Commit d7e0602

Browse files
committed
fix(e2e): set up variables for non-bare e2e runs
1 parent d636997 commit d7e0602

17 files changed

+237
-199
lines changed

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,20 @@ run-local-shift:
6969
. ./scripts/install_local.sh local build/resources
7070
rm -rf build
7171

72+
# useful if running e2e directly with `go test -tags=bare`
7273
setup-bare:
7374
. ./scripts/build_bare.sh
7475
. ./scripts/package-release.sh 1.0.0-e2e test/e2e/resources test/e2e/e2e-bare-values.yaml
75-
. ./scripts/install_bare.sh e2e test/e2e/resources
76+
. ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources
7677

7778
e2e:
78-
export NAMESPACE=default
79-
go test ./test/e2e/...
79+
go test -v -timeout 20m ./test/e2e/... -namespace=default -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager
8080

8181
e2e-local:
8282
. ./scripts/build_local.sh
8383
. ./scripts/run_e2e_local.sh $(TEST)
8484

85-
e2e-bare:
86-
. ./scripts/build_bare.sh
85+
e2e-bare: setup-bare
8786
. ./scripts/run_e2e_bare.sh $(TEST)
8887

8988
e2e-local-shift:

manifests/0000_30_11-catalog-operator.deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
- /bin/catalog
2727
- '-namespace'
2828
- openshift-operator-lifecycle-manager
29+
- -debug
2930
image: quay.io/coreos/olm@sha256:1639d570809c5827810a1870763016e8c046283632d47e0b47183c82f8e515f2
3031
imagePullPolicy: IfNotPresent
3132
ports:

scripts/build_bare.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ if [ -z "$NO_MINIKUBE" ]; then
1212
umask 0077 && kubectl config view --minify --flatten --context=minikube > minikube.kubeconfig
1313
fi
1414

15-
kubectl delete crds --all
16-
kubectl delete namespace e2e || true
17-
kubectl wait --for=delete namespace/e2e || true
18-
kubectl create namespace e2e
15+
timestamp=$(date +%s)
16+
namespace="e2e-tests-${timestamp}-$RANDOM"
17+
printf "${namespace}" > e2e.namespace
1918

20-
# only used for package server, other operators run locally
21-
docker build -t quay.io/coreos/olm:local .
19+
kubectl delete crds --all
20+
kubectl create namespace ${namespace}

scripts/install_bare.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ do
2828
kubectl apply -f ${f};
2929
fi
3030
done
31-
32-
# wait for package server to be ready
33-
#kubectl rollout status -w deployment.apps/package-server --namespace=${namespace}

scripts/run_e2e_bare.sh

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
#!/usr/bin/env bash
22

33
# Note: run from root
4-
# Individual tests can be run by calling ./test/e2e/run_e2e_local.sh TestName
4+
# Individual tests can be run by calling ./test/e2e/run_e2e_bare.sh TestName
55

66
set -e
77

8-
timestamp=$(date +%s)
9-
namespace="e2e-tests-${timestamp}-$RANDOM"
10-
11-
function cleanup {
12-
kubectl delete namespace ${namespace}
13-
rm -rf test/e2e/resources
14-
}
15-
16-
function cleanupAndExit {
17-
exitCode=$?
18-
if [ "$exitCode" -ne "0" ]; then
19-
echo "error running tests. logs written to package.log";
20-
kubectl -n ${namespace} logs -l app=package-server > package.log
21-
else
22-
cleanup
23-
fi
24-
25-
exit $exitCode
26-
}
27-
28-
trap cleanupAndExit SIGINT SIGTERM EXIT
29-
30-
31-
kubectl create namespace ${namespace}
32-
33-
./scripts/package-release.sh 1.0.0-e2e test/e2e/resources test/e2e/e2e-bare-values.yaml
34-
./scripts/install_bare.sh ${namespace} test/e2e/resources
35-
368
# run tests
379
if [ -z "$1" ]; then
3810
test_flags="";
@@ -41,4 +13,5 @@ else
4113
fi
4214

4315
echo "${test_flags}"
44-
go test -tags=bare -mod=vendor -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 20m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace}
16+
go test -c -tags=bare -mod=vendor -v -o e2e-bare github.com/operator-framework/operator-lifecycle-manager/test/e2e
17+
./e2e-bare -test.v -test.timeout 20m ${test_flags} -kubeconfig=minikube.kubeconfig -namespace=$(cat e2e.namespace) -olmNamespace=operator-lifecycle-manager

scripts/run_e2e_local.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ trap cleanupAndExit SIGINT SIGTERM EXIT
4141
./scripts/install_local.sh ${namespace} test/e2e/resources
4242

4343
# run tests
44-
e2e_kubeconfig=${KUBECONFIG:-~/.kube/config}
45-
KUBECONFIG=${e2e_kubeconfig} NAMESPACE=${namespace} go test -v -mod=vendor -timeout 20m ./test/e2e/... ${1/[[:alnum:]-]*/-run ${1}}
44+
if [ -z "$1" ]; then
45+
test_flags="";
46+
else
47+
test_flags="-test.run ${1}"
48+
fi
49+
50+
echo "${test_flags}"
51+
go test -mod=vendor -tags=local -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 20m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace} -olmNamespace=${namespace}

test/e2e/catalog_e2e_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package e2e
44

55
import (
66
"fmt"
7-
"github.com/coreos/go-semver/semver"
87
"testing"
98

9+
"github.com/coreos/go-semver/semver"
1010
"github.com/stretchr/testify/require"
1111
appsv1 "k8s.io/api/apps/v1"
1212
extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
@@ -37,22 +37,21 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) {
3737

3838
crdPlural := genName("ins")
3939
crdName := crdPlural + ".cluster.com"
40-
crd := newCRD(crdName, testNamespace, crdPlural)
40+
crd := newCRD(crdName, crdPlural)
4141
namedStrategy := newNginxInstallStrategy(genName("dep-"), nil, nil)
4242
csv := newCSV(packageStable, testNamespace, "", *semver.New("0.1.0"), []extv1beta1.CustomResourceDefinition{crd}, nil, namedStrategy)
4343

4444
c := newKubeClient(t)
4545
crc := newCRClient(t)
4646

4747
catalogSourceName := genName("mock-ocs")
48-
_, cleanupCatalogSource, err := createInternalCatalogSource(t, c, crc, catalogSourceName, testNamespace, manifests, []extv1beta1.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv})
48+
_, cleanupCatalogSource, err := createInternalCatalogSource(t, c, crc, catalogSourceName, operatorNamespace, manifests, []extv1beta1.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv})
4949
require.NoError(t, err)
5050
defer cleanupCatalogSource()
5151

5252
// ensure the mock catalog exists and has been synced by the catalog operator
53-
catalogSource, err := fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced)
53+
catalogSource, err := fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced)
5454
require.NoError(t, err)
55-
t.Logf("catalogSource: %+v", catalogSource)
5655

5756
// get catalog operator deployment
5857
deployment, err := getOperatorDeployment(c, labels.Set{"app": "catalog-operator"})
@@ -67,7 +66,7 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) {
6766

6867
// check for last synced update to catalogsource
6968
t.Log("Checking for catalogsource lastSync updates")
70-
_, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, func(cs *v1alpha1.CatalogSource) bool {
69+
_, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, func(cs *v1alpha1.CatalogSource) bool {
7170
if cs.Status.LastSync.After(catalogSource.Status.LastSync.Time) {
7271
t.Logf("lastSync updated: %s -> %s", catalogSource.Status.LastSync, cs.Status.LastSync)
7372
return true
@@ -79,7 +78,7 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) {
7978
}
8079

8180
func getOperatorDeployment(c operatorclient.ClientInterface, operatorLabels labels.Set) (*appsv1.Deployment, error) {
82-
deployments, err := c.ListDeploymentsWithLabels(testNamespace, operatorLabels)
81+
deployments, err := c.ListDeploymentsWithLabels(operatorNamespace, operatorLabels)
8382
if err != nil || deployments == nil || len(deployments.Items) != 1 {
8483
return nil, fmt.Errorf("Error getting single operator deployment for label: %v", operatorLabels)
8584
}
@@ -96,7 +95,7 @@ func rescaleDeployment(c operatorclient.ClientInterface, deployment *appsv1.Depl
9695
}
9796

9897
waitForScaleup := func() (bool, error) {
99-
fetchedDeployment, err := c.GetDeployment(testNamespace, deployment.GetName())
98+
fetchedDeployment, err := c.GetDeployment(operatorNamespace, deployment.GetName())
10099
if err != nil {
101100
return true, err
102101
}

test/e2e/csv_e2e_test.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func newNginxDeployment(name string) appsv1.DeploymentSpec {
116116
Containers: []v1.Container{
117117
{
118118
Name: genName("nginx"),
119-
Image: "nginx:1.7.9",
119+
Image: "bitnami/nginx:latest",
120120
Ports: []v1.ContainerPort{
121121
{
122122
ContainerPort: 80,
@@ -202,6 +202,9 @@ func fetchCSV(t *testing.T, c versioned.Interface, name string, checker csvCondi
202202
return checker(fetched), nil
203203
})
204204

205+
if err != nil {
206+
t.Logf("never got correct status: %#v", fetched.Status)
207+
}
205208
return fetched, err
206209
}
207210

@@ -715,13 +718,30 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) {
715718
require.NoError(t, err)
716719
defer cleanupCSV()
717720

718-
fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
721+
fmt.Println("checking for deployment")
722+
// Poll for deployment to be ready
723+
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
724+
dep, err := c.GetDeployment(testNamespace, depName)
725+
if k8serrors.IsNotFound(err) {
726+
fmt.Printf("deployment %s not found", depName)
727+
return false, nil
728+
} else if err != nil {
729+
fmt.Printf("unexpected error fetching deployment %s", depName)
730+
return false, err
731+
}
732+
if dep.Status.UpdatedReplicas == *(dep.Spec.Replicas) &&
733+
dep.Status.Replicas == *(dep.Spec.Replicas) &&
734+
dep.Status.AvailableReplicas == *(dep.Spec.Replicas) {
735+
fmt.Printf("deployment ready")
736+
return true, nil
737+
}
738+
fmt.Printf("deployment not ready")
739+
return false, nil
740+
})
719741
require.NoError(t, err)
720742

721-
// Should create deployment
722-
dep, err := c.GetDeployment(testNamespace, depName)
743+
fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
723744
require.NoError(t, err)
724-
require.Equal(t, depName, dep.Name)
725745

726746
// Fetch cluster service version again to check for unnecessary control loops
727747
sameCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
@@ -883,11 +903,6 @@ func TestCreateCSVRequirementsMetAPIService(t *testing.T) {
883903
fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
884904
require.NoError(t, err)
885905

886-
// Should create deployment
887-
dep, err := c.GetDeployment(testNamespace, depName)
888-
require.NoError(t, err)
889-
require.Equal(t, depName, dep.Name)
890-
891906
// Fetch cluster service version again to check for unnecessary control loops
892907
sameCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
893908
require.NoError(t, err)
@@ -994,12 +1009,12 @@ func TestCreateCSVWithOwnedAPIService(t *testing.T) {
9941009
// Induce a cert rotation
9951010
fetchedCSV.Status.CertsLastUpdated = metav1.Now()
9961011
fetchedCSV.Status.CertsRotateAt = metav1.Now()
997-
fetchedCSV, err = crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).UpdateStatus(fetchedCSV)
1012+
fetchedCSV, err = crc.OperatorsV1alpha1().ClusterServiceVersions(operatorNamespace).UpdateStatus(fetchedCSV)
9981013
require.NoError(t, err)
9991014

10001015
_, err = fetchCSV(t, crc, csv.Name, func(csv *v1alpha1.ClusterServiceVersion) bool {
10011016
// Should create deployment
1002-
dep, err = c.GetDeployment(testNamespace, depName)
1017+
dep, err = c.GetDeployment(operatorNamespace, depName)
10031018
require.NoError(t, err)
10041019

10051020
// Should have a new ca hash annotation

0 commit comments

Comments
 (0)