github.com/argoproj/argo-cd/v2@v2.10.5/test/remote/README.md (about) 1 # End-to-end tests against a real cluster 2 3 Using the tools in this directory, you can run the End-to-End test suite against 4 a real Argo CD workload, that is deployed to a K8s cluster, instead of running 5 it against a locally running Argo CD. 6 7 Since e2e tests are destructive, do **not** run it against an installation that 8 you depend on. 9 10 ## Preparations 11 12 ### Install the Argo CD you want to test 13 14 It is recommended to install in the `argocd-e2e` namespace: 15 16 ```shell 17 kubectl create ns argocd-e2e 18 kubectl -n argocd-e2e apply -f <your Argo CD installation manifests> 19 ``` 20 21 If you're going to install Argo CD using either Argo CD Operator or OpenShift GitOps Operator, you can use this manifest to install the Argo CD instance into your namespace: 22 23 ```yaml 24 apiVersion: argoproj.io/v1alpha1 25 kind: ArgoCD 26 metadata: 27 name: argocd-test 28 namespace: argocd-e2e 29 spec: 30 server: 31 route: 32 enabled: true 33 ``` 34 35 ### Give the Argo CD the appropriate RBAC permissions 36 37 ```shell 38 # If you installed to a different namespace, set accordingly 39 export NAMESPACE=argocd-e2e 40 # If you installed Argo CD via Operator, set accordingly 41 # export ARGOCD_E2E_NAME_PREFIX=argocd-cluster 42 ./test/remote/generate-permissions.sh | kubectl apply -f - 43 ``` 44 45 ### Build the repository container image 46 47 You will need to build & publish a container image that will hold the required 48 testing repositories. 49 50 This container image will be named `argocd-e2e-cluster`, so you will need to 51 setup a corresponding repository for it in your registry as well. 52 53 To build it, run the following. Note that kustomize is required: 54 55 ```shell 56 cd test/remote 57 export IMAGE_NAMESPACE=quay.io/{YOUR USERNAME HERE} 58 # builds & tags the image 59 make image 60 # pushes the image to your repository 61 make image-push 62 # build the manifests & store them at temp location 63 make manifests > /tmp/e2e-repositories.yaml 64 ``` 65 66 If you do not have kustomize installed, you need to manually edit the manifests 67 at `test/remote/manifests/e2e_repositories.yaml` to point to the correct image. 68 69 If you get `make: realpath: Command not found`, install coreutils. 70 71 ### Deploy the test container and additional permissions 72 73 **Note:** The test container requires to be run in privileged mode for now, due 74 to some processes running as root (this may change some day...). 75 76 On OpenShift, you will likely need to allow privileged operations: 77 78 ```shell 79 oc -n argocd-e2e adm policy add-scc-to-user privileged -z default 80 ``` 81 82 Then, apply the manifests for the E2E repositories workload: 83 84 ```shell 85 kubectl -n argocd-e2e apply -f /tmp/e2e-repositories.yaml 86 ``` 87 88 Verify that the deployment was successful: 89 90 ```shell 91 kubectl -n argocd-e2e rollout status deployment argocd-e2e-cluster 92 ``` 93 94 ## Start the tests 95 96 ### Port-forward the repository 97 98 In another shell, port forward the repository to your local machine: 99 100 ```shell 101 kubectl -n argocd-e2e port-forward service/argocd-e2e-server 9081:9081 102 ``` 103 104 ### On local cluster (e.g. K3s, microk8s, minishift) 105 106 Set the server endpoint of the Argo CD API. If you are running on the same host 107 as the cluster, or the cluster IPs are routed to your host, you can use the 108 following: 109 110 ```shell 111 export ARGOCD_SERVER=$(kubectl -n argocd-e2e get svc argocd-server -o jsonpath='{.spec.clusterIP}') 112 ``` 113 114 Set the admin password to use: 115 116 ```shell 117 export ARGOCD_E2E_ADMIN_PASSWORD=$(kubectl -n argocd-e2e get secrets argocd-initial-admin-secret -o jsonpath='{.data.password}'|base64 -d) 118 ``` 119 120 Run the tests 121 122 ```shell 123 ./test/remote/run-e2e-remote.sh make test-local 124 ``` 125 126 ### On remote non-OpenShift cluster 127 128 In another shell, do a port-forward to the API server's service: 129 130 ```shell 131 kubectl -n argocd-e2e port-forward svc/argocd-server 4443:443 132 ``` 133 134 Set Argo CD Server port: 135 136 ```shell 137 export ARGOCD_SERVER=127.0.0.1:4443 138 ``` 139 140 Set the admin password to use: 141 142 ```shell 143 export ARGOCD_E2E_ADMIN_PASSWORD=$(kubectl -n argocd-e2e get secrets argocd-initial-admin-secret -o jsonpath='{.data.password}'|base64 -d) 144 ``` 145 146 Run the tests 147 148 ```shell 149 ./test/remote/run-e2e-remote.sh make test-local 150 ``` 151 152 ### On remote OpenShift cluster 153 154 You should first scale down Argo CD Operator, since it will revert changes made 155 during the tests instantly: 156 157 ```shell 158 oc -n openshift-operators scale deployment --replicas=0 argocd-operator 159 ``` 160 161 Set the endpoint by using the route created by the operator: 162 163 ```shell 164 export ARGOCD_SERVER=$(oc -n argocd-e2e get routes argocd-test-server -o jsonpath='{.spec.host}') 165 ``` 166 167 Set the admin password, created by the operator: 168 169 ```shell 170 export ARGOCD_E2E_ADMIN_PASSWORD=$(oc -n argocd-e2e get secrets argocd-test-cluster -o jsonpath='{.data.admin\.password}' | base64 -d) 171 ``` 172 173 Set the name of the Argo CD instance as installed by the operator (below example assumes operand name of `argocd-test`): 174 175 ```shell 176 export ARGOCD_E2E_NAME_PREFIX=argocd-test 177 ``` 178 179 Run the tests with currently known failing tests disabled: 180 181 ```shell 182 ./test/remote/run-e2e-remote.sh make test-local ARGOCD_E2E_SKIP_OPENSHIFT=true 183 ``` 184 185 ## Running single or multiple tests isolated 186 187 This should be run in the same shell where you set `ARGOCD_SERVER` and `ARGOCD_E2E_ADMIN_PASSWORD` variables 188 189 1. Run the `go test` command through the wrapper, e.g. to run a test named `MyTestName`: 190 191 ``` 192 $ ./test/remote/run-e2e-remote.sh go test -v github.com/argoproj/argo-cd/test/e2e -run ^MyTestName$^ 193 ``` 194 195 196 ## Further configuration 197 198 Some environment variables can control the behavior of the tests: 199 200 * `ARGOCD_SERVER` - the remote endpoint of the Argo CD API server to use for tests 201 * `ARGOCD_E2E_ADMIN_PASSWORD` - the admin user's password to use 202 * `ARGOCD_E2E_TEST_TIMEOUT` - timeout for the complete test suite, specified as duration (e.g. `2h` or `1h30m`) 203 * `ARGOCD_E2E_DEFAULT_TIMEOUT` - timeout in seconds for each context operation (e.g. sync). Default `30`. 204 * `ARGOCD_E2E_NAMESPACE` - the namespace where Argo CD is running in for the tests 205 * `ARGOCD_E2E_NAME_PREFIX` - if your Argo CD installation has a name prefix (e.g. installed by the Operator), specify it here 206 207 Furthermore, you can skip various classes of tests by setting the following to true: 208 209 ```shell 210 # If you disabled GPG feature, set to true to skip related tests 211 export ARGOCD_E2E_SKIP_GPG=${ARGOCD_E2E_SKIP_GPG:-false} 212 # Some tests do not work OOTB with OpenShift 213 export ARGOCD_E2E_SKIP_OPENSHIFT=${ARGOCD_E2E_SKIP_OPENSHIFT:-false} 214 # Skip all Helm tests 215 export ARGOCD_E2E_SKIP_HELM=${ARGOCD_E2E_SKIP_HELM:-false} 216 ``` 217 218 ## Recording tests that ran successfully and restart at point of fail 219 220 Sometimes, due to a hiccup or timeout on the remote cluster, a test may fail to run without specific reason. This can be time consuming when tests 221 are being run again, since every test will be executed again. You can record the tests that were run & successful and pick up where it failed. 222 For this purpose, set the `ARGOCD_E2E_RECORD` variable to point to a file where tests will be recorded: 223 224 ``` 225 $ ./test/remote/run-e2e-remote.sh make test-e2e-local ARGOCD_E2E_RECORD=/tmp/mytests 226 ``` 227 228 If the tests fail, just re-run above command. All tests that have been previously run will be skipped, and testing will continue with the next test. 229 230 ## Tear down 231 232 1. Remove argocd-e2e namespace 233 234 ``` 235 $ kubectl delete ns argocd-e2e 236 ``` 237 238 239 ## Troubleshooting 240 241 * On message: 242 243 ``` 244 time="2021-03-23T09:52:53Z" level=fatal msg="`git push origin master -f` failed exit status 128: fatal: unable to access 'http://127.0.0.1:9081/argo-e2e/testdata.git/': Empty reply from server" 245 ``` 246 247 Your port-forward is probably not setup correctly or broke (e.g. due to pod restart) 248 249 * Make sure `argocd-e2e-cluster` pod is running. If you get a CrashLoopBackoff, ensure that you enabled elevated privileges as shown above 250 251 * Sometimes, you may run into a timeout especially if the cluster is very busy. In this case, you have to restart the tests. See test recording above.