Skip to content

Commit c721c63

Browse files
AlexNPavellilic
andauthored
doc/dev,hack/tests: update docs and fix go test configuration (#1629)
* doc/dev,hack/tests: update docs and fix go test configuration * doc/dev: Include metrics e2e steps in docs * .travis.yml: remove unused -v make arg * Apply suggestions from code review Co-Authored-By: Haseeb Tariq <[email protected]> Co-authored-by: Lili Cosic <[email protected]>
1 parent 65b687b commit c721c63

File tree

5 files changed

+56
-33
lines changed

5 files changed

+56
-33
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
# Build and test go
7272
- <<: *test
7373
name: Go on OpenShift
74-
script: make test/ci-go ARGS="-v"
74+
script: make test/ci-go
7575

7676
# Build and test ansible
7777
- <<: *test

doc/dev/testing/running-the-tests.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,15 @@ and the operator images will be built and stored in you local docker registry.
100100

101101
The `make test/e2e/go` command accepts an `ARGS` variable containing flags that will be passed to `go test`:
102102

103-
- `-image` string - Sets the operator test image tag to be built and used in testing. Defaults to "quay.io/example/memcached-operator:v0.0.1"
103+
- `-image-name` string - Sets the operator test image tag to be built and used in testing. Defaults to "quay.io/example/memcached-operator:v0.0.1"
104104
- `-local-repo` string - Sets the path to the local SDK repo being tested. Defaults to the path of the SDK repo containing e2e tests. This is useful for testing customized e2e code.
105105

106106
An example of using `ARGS` is in the note below.
107107

108108
**NOTE**: Some of these tests, specifically the ansible (`test/e2e/ansible` and `test/ci-ansible`), helm
109-
(`test/e2e/helm` and `test/ci-helm`), and CI Go (`test/e2e/ci-go`) tests, only work when the cluster shares the local docker
109+
(`test/e2e/helm` and `test/ci-helm`), and Go (`test/e2e/go` and `test/e2e/ci-go`) tests, only work when the cluster shares the local docker
110110
registry, as is the case with `oc cluster up` and `minikube` after running `eval $(minikube docker-env)`.
111111

112-
The E2E go test (`test/e2e/go`) can be run on a remote cluster by specifying an image name using a repo that you are logged into and
113-
have permission to push to as such:
114-
115-
```sh
116-
$ make test/e2e/go ARGS="-image=quay.io/example/memcached:e2e-test"
117-
```
118-
119112
All other tests will run correctly on a remote cluster if `$HOME/.kube/config` points to the remote cluster and your
120113
`KUBECONFIG` env var is either empty or is set to the path of a kubeconfig for the remote cluster.
121114

@@ -127,9 +120,8 @@ during the go tests can cause these cleanups to fail (the ansible and helm E2E t
127120
always clean up correctly). For example, if a segfault occurs or a user kills the
128121
testing process, the cleanup functions for the go tests will not run. To manually clean up a test:
129122

130-
1. Delete the CRD (`kubectl delete -f $HOME/projects/example.com/memcached-operator/deploy/crds/cache_v1alpha1_memcached_crd.yaml`).
131-
2. Delete the created project in `$HOME/projects/example.com/memcached-operator`
132-
3. Delete the namespaces that the tests run in, which also deletes any resources created within the namespaces. The namespaces start with `memcached-memcached-group` or `main` and are appended with a unix timestamp (seconds since Jan 1 1970). The kubectl command can be used to delete namespaces: `kubectl delete namespace $NAMESPACE`.
123+
1. Delete the CRD (`kubectl delete crd memcacheds.cache.example.com`).
124+
2. Delete the namespaces that the tests run in, which also deletes any resources created within the namespaces. The namespaces start with `memcached-memcached-group` or `main` and are appended with a unix timestamp (seconds since Jan 1 1970). The kubectl command can be used to delete namespaces: `kubectl delete namespace $NAMESPACE`.
133125

134126
[travis]: ./travis-build.md
135127
[quay]: https://quay.io

doc/dev/testing/travis-build.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,32 @@ The Go, Ansible, and Helm tests then differ in what tests they run.
4444
7. Run `scorecard` subcommand and check that expected score matches actual score.
4545
8. Run `scorecard` subcommand with json output enabled and verify the output.
4646
4. Run [go e2e tests][go-e2e].
47-
1. Use `operator-sdk` to create and configure a new `memcached-operator` project and install the memcached CRD in the cluster.
48-
2. Run cluster test (namespace is auto-generated and deleted by test framework).
49-
1. Build `memcached-operator` image with `--enable-tests` flag enabled (used in the in-cluster test later).
50-
2. Deploy operator and resources to the cluster.
51-
3. Run the leader election test.
52-
1. Verify that operator deployment is ready.
53-
2. Verify that leader configmap specifies 1 leader and that the memcached operator has 2 pods (configuration for this is done in step 4.1).
54-
3. Delete current leader and wait for memcached-operator deployment to become ready again.
55-
4. Verify that leader configmap specifies 1 leader and that the memcached-operator has 2 pods.
56-
5. Verify that the name of the new leader is different from the name of the old leader.
57-
4. Run the memcached scale test.
58-
1. Create memcached CR specifying a desired cluster size of 3 and wait until memcached cluster is of size 3.
59-
2. Increase desired cluster size to 4 and wait until memcached cluster is of size 4.
60-
3. Run local test.
61-
1. Create new namespace for the test.
62-
2. Start operator using `up local` subcommand.
63-
3. Run memcached scale test (described in step 4.2.4)
64-
4. Delete the test namespace.
47+
1. Scaffold a project using `hack/tests/scaffolding/e2e-go-scaffold.sh`
48+
2. Build `memcached-operator` image to be used in tests
49+
3. Run scaffolded project e2e tests using `operator-sdk up local`
50+
1. Run cluster test (namespace is auto-generated and deleted by test framework).
51+
1. Deploy operator and required resources to the cluster.
52+
2. Run the leader election test.
53+
1. Verify that operator deployment is ready.
54+
2. Verify that leader configmap specifies 1 leader and that the memcached operator has 2 pods (configuration for this is done in step 4.1).
55+
3. Delete current leader and wait for memcached-operator deployment to become ready again.
56+
4. Verify that leader configmap specifies 1 leader and that the memcached-operator has 2 pods.
57+
5. Verify that the name of the new leader is different from the name of the old leader.
58+
3. Run the memcached scale test.
59+
1. Create memcached CR specifying a desired cluster size of 3 and wait until memcached cluster is of size 3.
60+
2. Increase desired cluster size to 4 and wait until memcached cluster is of size 4.
61+
4. Run the memcached metrics test.
62+
1. Make sure the metrics Service was created.
63+
2. Get metrics via proxy pod and make sure they are present.
64+
3. Perform linting of the existing metrics.
65+
5. Run the memcached custom resource metrics test.
66+
1. Make sure the metrics Service was created.
67+
2. Get metrics via proxy pod and make sure they are present.
68+
3. Perform linting of the existing metrics.
69+
4. Perform checks on each custom resource generated metric and makes sure the name, type, value, labels and metric are correct.
70+
2. Run local test (namespace is auto-generated and deleted by test framework).
71+
1. Start operator using `up local` subcommand.
72+
2. Run memcached scale test (described in step 4.3.1.3)
6573
4. Run [TLS library tests][tls-tests].
6674
1. This test runs multiple simple tests of the operator-sdk's TLS library. The tests run in parallel and each tests runs in its own namespace.
6775

hack/tests/e2e-go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ operator-sdk build $IMAGE_NAME
99
operator-sdk test local ./test/e2e
1010
popd
1111

12-
go test ./test/e2e/... -root=. -globalMan=testdata/empty.yaml $1
12+
go test ./test/e2e/... -root=. -globalMan=testdata/empty.yaml

hack/tests/scaffolding/e2e-go-scaffold.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,31 @@ trap_add 'rm -f $ROOTDIR/go.mod' EXIT
1010
BASEPROJECTDIR="$(mktemp -d)"
1111
IMAGE_NAME="quay.io/example/memcached-operator:v0.0.1"
1212

13+
# change IMAGE_NAME in case it is redefined by a flag
14+
# parse "--image-name value" format
15+
ORIG_ARGS=("$@")
16+
while [[ $# -gt 0 ]]
17+
do
18+
key="$1"
19+
case $key in
20+
-image-name|--image-name) # "--image-name value" format
21+
IMAGE_NAME="$2"
22+
shift
23+
;;
24+
-image-name=*|--image-name=*) # "--image-name=value" format
25+
IMAGE_NAME="${key#*=}"
26+
shift
27+
;;
28+
*) # different arg/flag
29+
shift
30+
;;
31+
esac
32+
done
33+
34+
set -- "${ORIG_ARGS[@]}"
35+
1336
go build -o $BASEPROJECTDIR/scaffold-memcached $ROOTDIR/hack/tests/scaffolding/scaffold-memcached.go
1437

1538
pushd "$BASEPROJECTDIR"
16-
./scaffold-memcached --local-repo $ROOTDIR --image-name=$IMAGE_NAME --local-image
39+
./scaffold-memcached --local-repo $ROOTDIR --image-name=$IMAGE_NAME --local-image $@
1740
popd

0 commit comments

Comments
 (0)