Browse code

Update test cases and docs to use `openshift ex router`

Router is now no longer optional

Clayton Coleman authored on 2015/02/20 12:03:26
Showing 5 changed files
... ...
@@ -32,12 +32,10 @@ Once it is pulled it will start and be visible in the `docker ps` list of contai
32 32
     [vagrant@openshiftdev origin]$ sudo /data/src/github.com/openshift/origin/_output/local/bin/linux/amd64/openshift start &
33 33
 
34 34
     If running in https mode, ensure osc can authenticate to the master
35
-    [vagrant@openshiftdev origin]$ export KUBECONFIG=/data/src/github.com/openshift/origin/openshift.local.certificates/admin/.kubeconfig
35
+    [vagrant@openshiftdev origin]$ export KUBECONFIG=/data/src/github.com/openshift/origin/openshift.local.certificates/openshift-client/.kubeconfig
36 36
     [vagrant@openshiftdev origin]$ sudo chmod a+r "$KUBECONFIG"
37
-
38
-    If running in https mode, ensure install-router.sh can authenticate to the master
39 37
     [vagrant@openshiftdev origin]$ sudo chmod a+r openshift.local.certificates/openshift-client/key.key
40
-    [vagrant@openshiftdev origin]$ CERT_DIR=openshift.local.certificates/openshift-client hack/install-router.sh {router_id} {master_url}
38
+    [vagrant@openshiftdev origin]$ openshift ex router --create --credentials="${KUBECONFIG}"
41 39
     [vagrant@openshiftdev origin]$ osc get pods
42 40
 
43 41
 #### Clustered vagrant environment
... ...
@@ -46,7 +44,7 @@ Once it is pulled it will start and be visible in the `docker ps` list of contai
46 46
     $ export OPENSHIFT_DEV_CLUSTER=true
47 47
     $ vagrant up
48 48
     $ vagrant ssh master
49
-    [vagrant@openshift-master ~]$ hack/install-router.sh {router_id} {master_url}
49
+    [vagrant@openshift-master ~]$ openshift ex router --create --credentials="${KUBECONFIG}"
50 50
 
51 51
 
52 52
 
... ...
@@ -58,12 +56,14 @@ In order to run the router in a deployed environment the following conditions mu
58 58
 * The machine may or may not be registered with the master.  Optimally it will not serve pods while also serving as the router
59 59
 * The machine must not have services running on it that bind to host port 80 since this is what the router uses for traffic
60 60
 
61
-To install the router pod you use the `hack/install-router.sh` script, passing it the router id, master url, and, optionally,
62
-the OpenShift executable.  If the executable is not passed the script will try to find it via the `PATH`.  If the
63
-script is still unable to find the OpenShift executable then it will simply create the `/tmp/router.json` file and stop.
64
-It is then up to the user to issue the `osc create` command manually.
61
+To install the router pod you use the `openshift ex router` command line, passing the flags `--create` and `--credentials=<kubeconfig_file>`.
62
+The credentials flag controls the identity that the router will use to talk to the master (and the address of the master) so in most
63
+environments you can use the `${CERTS_DIR}/openshift-client/.kubeconfig` file. Once you run this command you can check the configuration
64
+of the router by running `osc get dc router` to check the deployment status.
65
+
66
+`openshift ex router` offers other options for deploying routers - run `openshift help ex router` for more details.
65 67
 
66
-### Manually   
68
+### Manually
67 69
 
68 70
 To run the router manually (outside of a pod) you should first build the images with instructions found below.  Then you
69 71
 can run the router anywhere that it can access both the pods and the master.  The router exposes port 80 so the host 
... ...
@@ -93,10 +93,10 @@ the present working directory is the same directory as this README.
93 93
     need to accept the server certificates and present its own client
94 94
     certificate. These are generated as part of the `openshift start`
95 95
     command in whatever the current directory is at the time. You will
96
-    need to point osc and curl at the appropriate .kubeconfig in order 
97
-    to connect to OpenShift. Assuming you are running as a user other 
98
-    than root, you will also need to make the .kubeconfig readable by 
99
-    that user. (Note: this is just for example purposes; in a real 
96
+    need to point osc and curl at the appropriate .kubeconfig in order
97
+    to connect to OpenShift. Assuming you are running as a user other
98
+    than root, you will also need to make the .kubeconfig readable by
99
+    that user. (Note: this is just for example purposes; in a real
100 100
     installation, users would generate their own keys and not have access
101 101
     to the system keys.)
102 102
 
... ...
@@ -285,7 +285,7 @@ Congratulations, you've successfully deployed and updated an application on Open
285 285
 
286 286
 Advanced
287 287
 ---------
288
-OpenShift also provides features that live outside the deployment life cycle like routing.  
288
+OpenShift also provides features that live outside the deployment life cycle like routing.
289 289
 
290 290
 1.  Your sample app has been created with a secure route which can be viewed by performing a `GET` on the route api object.
291 291
 
... ...
@@ -295,53 +295,47 @@ OpenShift also provides features that live outside the deployment life cycle lik
295 295
 
296 296
 
297 297
 2.  To use the route you must first install a router.  OpenShift provides an HAProxy router implementation that we'll use.
298
-To install the router you must know the ip address of the host the router will be deployed on (used later) and the api 
298
+To install the router you must know the ip address of the host the router will be deployed on (used later) and the api
299 299
 url the master is listening on.  The api url can be found in the logs, your ip address can be determined with `ip a`.  Replace
300 300
 the ip address shown below with the correct one for your environment.
301 301
 
302
-            # Optional: pre-pull the router image.  This will be pulled automatically when the pod is created but will 
303
-            # take some time.  Your pod will stay in Pending state while the pull is completed 
302
+            # Optional: pre-pull the router image.  This will be pulled automatically when the pod is created but will
303
+            # take some time.  Your pod will stay in Pending state while the pull is completed
304 304
             $ docker pull openshift/origin-haproxy-router
305
-            
306
-            $ pushd ../..
307
-            $ sudo chmod +r ./openshift.local.certificates/openshift-client/key.key
308
-            $ CERT_DIR=openshift.local.certificates/openshift-client hack/install-router.sh router https://10.0.2.15:8443
309
-              Creating router file and starting pod...
310
-              router
311
-            $ popd
305
+
306
+            $ openshift ex router --create --credentials="${KUBECONFIG}"
307
+              router # the service
308
+              router # the deployment config
312 309
 
313 310
 
314 311
 3.  Wait for the router to start.
315 312
 
316 313
 
317
-            $ osc get pods
318
-            POD                       IP                  CONTAINER(S)                   IMAGE(S)                          HOST                           LABELS                                                                                                             STATUS
319
-            docker-registry-1-fnd84   172.17.0.3          registry-container             openshift/docker-registry         openshiftdev.local/127.0.0.1   deployment=docker-registry-1,deploymentconfig=docker-registry,name=registrypod,template=docker-registry-template   Running
320
-            router                    172.17.0.10         origin-haproxy-router-router   openshift/origin-haproxy-router   openshiftdev.local/127.0.0.1   <none>                                                                                                             Running
314
+            $ osc describe dc router
315
+            # watch for the number of deployed pods to go to 1
321 316
 
322 317
 
323 318
 4.  *Optional:* View the logs of the router.
324
- 
325 319
 
326
-            $ osc log router
320
+            $ osc log router-1-<podrandom-suffix>
327 321
 
328 322
 
329 323
 5.  Curl the url, substituting the ip address shown for the correct value in your environment.
330 324
 
331
-            $ curl -s -k --resolve www.example.com:443:10.0.2.15 https://www.example.com 
332
-                ... removed for readability ... 
325
+            $ curl -s -k --resolve www.example.com:443:10.0.2.15 https://www.example.com
326
+                ... removed for readability ...
333 327
                 <title>Hello from OpenShift v3!</title>
334 328
                 ... removed for readability ...
335
-            
329
+
336 330
 7. *Optional*: View the certificate being used for the secure route.
337
-            
331
+
338 332
             $ openssl s_client -servername www.example.com -connect 10.0.2.15:443
339 333
             ... removed for readability ...
340 334
             subject=/CN=www.example.com/ST=SC/C=US/emailAddress=example@example.com/O=Example/OU=Example
341 335
             issuer=/C=US/ST=SC/L=Default City/O=Default Company Ltd/OU=Test CA/CN=www.exampleca.com/emailAddress=example@example.com
342 336
             ... removed for readability ...
343 337
             ^C
344
-            
338
+
345 339
 
346 340
 
347 341
 Additional Operations
348 342
deleted file mode 100755
... ...
@@ -1,87 +0,0 @@
1
-#!/bin/bash
2
-set -e
3
-
4
-# ID to be used as the k8s id and also appended to the container name. Defaults to router1
5
-ROUTER_ID="${1}"
6
-# Full address to connect to the master.
7
-MASTER_URL="${2}"
8
-# openshift executable - optional, will try to find it on the path if not specified
9
-OPENSHIFT="${3}"
10
-
11
-OS_ROOT=$(dirname "${BASH_SOURCE}")/..
12
-
13
-if [[ "${ROUTER_ID}" == "" ]]; then
14
-	echo "No router id provided, cannot create router..."
15
-	exit
16
-fi
17
-
18
-if [[ "${MASTER_URL}" == "" ]]; then
19
-	echo "No master url provided, cannot create router..."
20
-	exit
21
-fi
22
-if [[ "${MASTER_URL}" != "http"* ]]; then
23
-	echo "Master url must include protocol, e.g. https://localhost:8443"
24
-	exit
25
-fi
26
-
27
-if [[ "${OPENSHIFT}" == "" ]]; then
28
-    if [[ "$(which osc)" != "" ]]; then
29
-        OPENSHIFT=$(which osc)
30
-    fi
31
-fi
32
-
33
-OPENSHIFT_INSECURE="${OPENSHIFT_INSECURE:-false}"
34
-CERT_DIR="${CERT_DIR:-}"
35
-OPENSHIFT_CA_DATA="${OPENSHIFT_CA_DATA:-}"
36
-OPENSHIFT_CERT_DATA="${OPENSHIFT_CERT_DATA:-}"
37
-OPENSHIFT_KEY_DATA="${OPENSHIFT_KEY_DATA:-}"
38
-
39
-if [[ "${MASTER_URL}" == "https"* ]]; then
40
-	# Read client cert data in to send to containerized components
41
-	if [ -n "${CERT_DIR}" ]; then
42
-		OPENSHIFT_CA_DATA="$(cat "${CERT_DIR}/root.crt")"
43
-		OPENSHIFT_CERT_DATA="$(cat "${CERT_DIR}/cert.crt")"
44
-		OPENSHIFT_KEY_DATA="$(cat "${CERT_DIR}/key.key")"
45
-	fi
46
-
47
-	# I don't know how to do this inline with bash and it's logically a separate step we want to remove anyway
48
-	# TODO: remove this once services can provide root cert data to pods
49
-	# Escape cert data for json
50
-	OPENSHIFT_CA_DATA="${OPENSHIFT_CA_DATA//$'\n'/\\\\n}"
51
-	OPENSHIFT_CERT_DATA="${OPENSHIFT_CERT_DATA//$'\n'/\\\\n}"
52
-	OPENSHIFT_KEY_DATA="${OPENSHIFT_KEY_DATA//$'\n'/\\\\n}"
53
-
54
-
55
-	if [[ "$OPENSHIFT_CA_DATA" == "" ]]; then
56
-		echo "Running against an HTTPS master (${MASTER_URL}) without a trusted certificate bundle."
57
-		echo "Set \$CERT_DIR to the directory containing the root certificate bundle (root.crt), client certificate (cert.crt), and the client key (key.key) to start securely next time."
58
-		echo "Starting insecurely..."
59
-		OPENSHIFT_INSECURE=true
60
-	fi
61
-
62
-else
63
-	OPENSHIFT_INSECURE=""
64
-	OPENSHIFT_CA_DATA=""
65
-	OPENSHIFT_CERT_DATA=""
66
-	OPENSHIFT_KEY_DATA=""
67
-fi
68
-
69
-# update the template file
70
-echo "Creating router file and starting pod..."
71
-cp "${OS_ROOT}/images/router/haproxy/pod.json" /tmp/router.json
72
-sed -i "s|ROUTER_ID|${ROUTER_ID}|g" /tmp/router.json
73
-sed -i "s|\${OPENSHIFT_MASTER}|${MASTER_URL}|"       /tmp/router.json
74
-sed -i "s|\${OPENSHIFT_INSECURE}|${OPENSHIFT_INSECURE}|"   /tmp/router.json
75
-sed -i "s|\${OPENSHIFT_CA_DATA}|${OPENSHIFT_CA_DATA}|"     /tmp/router.json
76
-sed -i "s|\${OPENSHIFT_CERT_DATA}|${OPENSHIFT_CERT_DATA}|"     /tmp/router.json
77
-sed -i "s|\${OPENSHIFT_KEY_DATA}|${OPENSHIFT_KEY_DATA}|"     /tmp/router.json
78
-# TODO: provide security context to client inside router pod
79
-
80
-# create the pod if we can find openshift
81
-if [ "${OPENSHIFT}" == "" ]; then
82
-    echo "Unable to find openshift binary"
83
-    echo "/tmp/router.json has been created.  In order to start the router please run:"
84
-    echo "osc create -f /tmp/router.json"
85
-else
86
-    "${OPENSHIFT}" --server="${MASTER_URL}" create -f /tmp/router.json
87
-fi
... ...
@@ -234,16 +234,13 @@ echo "start-build: ok"
234 234
 osc describe build ${started} | grep openshift/ruby-20-centos$
235 235
 
236 236
 osc cancel-build "${started}" --dump-logs --restart
237
-echo "cancel-build: ok"
238
-
239 237
 # a build for which there is an upstream tag in the corresponding imagerepo, so
240 238
 # the build should use that specific tag of the image instead of the image field
241 239
 # as defined in the buildconfig
242 240
 started=$(osc start-build ruby-sample-build-validtag)
243 241
 osc describe build ${started} | grep openshift/ruby-20-centos:success$
244 242
 osc cancel-build "${started}" --dump-logs --restart
245
-
246
-osc get minions,pods
243
+echo "cancel-build: ok"
247 244
 
248 245
 openshift ex policy add-group cluster-admin system:unauthenticated
249 246
 openshift ex policy remove-group cluster-admin system:unauthenticated
... ...
@@ -259,4 +256,12 @@ openshift ex new-project ui-test-project --admin="anypassword:createuser"
259 259
 openshift ex policy add-user admin anypassword:adduser -n ui-test-project
260 260
 osc describe policybinding master -n ui-test-project | grep createuser
261 261
 osc describe policybinding master -n ui-test-project | grep adduser
262
-echo "UI project commands: ok"
262
+echo "ui-project-commands: ok"
263
+
264
+[ ! "$(openshift ex router | grep 'does not exist')"]
265
+[ "$(openshift ex router -o yaml --credentials="${KUBECONFIG}" | grep 'openshift/origin-haproxy-')" ]
266
+openshift ex router --create --credentials="${KUBECONFIG}"
267
+[ "$(openshift ex router | grep 'service exists')" ]
268
+echo "ex router: ok"
269
+
270
+osc get minions,pods
... ...
@@ -209,8 +209,12 @@ openshift ex new-project test --description="This is an example project to demon
209 209
 echo "The console should be available at ${API_SCHEME}://${PUBLIC_MASTER_HOST}:$(($API_PORT + 1)).	You may need to visit ${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT} first to accept the certificate."
210 210
 echo "Log in as 'e2e-user' to see the 'test' project."
211 211
 
212
+# install the router
213
+echo "[INFO] Installing the router"
214
+openshift ex router --create --credentials="${KUBECONFIG}" --images="${USE_IMAGES}"
212 215
 
213 216
 # install the registry
217
+echo "[INFO] Installing the registry"
214 218
 CERT_DIR="${CERT_DIR}/openshift-client" hack/install-registry.sh
215 219
 
216 220
 echo "[INFO] Waiting for Docker registry pod to start"
... ...
@@ -262,16 +266,8 @@ wait_for_app "test"
262 262
 #wait_for_build "custom"
263 263
 #wait_for_app "custom"
264 264
 
265
-if [[ "$ROUTER_TESTS_ENABLED" == "true" ]]; then
266
-	echo "[INFO] Installing router with master url of ${API_SCHEME}://${CONTAINER_ACCESSIBLE_API_HOST}:${API_PORT} and starting pod..."
267
-	echo "[INFO] To disable router testing set ROUTER_TESTS_ENABLED=false..."
268
-	CERT_DIR="${CERT_DIR}/openshift-client" "${OS_ROOT}/hack/install-router.sh" "router1" "${API_SCHEME}://${CONTAINER_ACCESSIBLE_API_HOST}:${API_PORT}"
269
-	wait_for_command "osc get pods | grep router1 | grep -i Running" $((5*TIME_MIN))
270
-
271
-	echo "[INFO] Validating routed app response..."
272
-	validate_response "-s -k --resolve www.example.com:443:${CONTAINER_ACCESSIBLE_API_HOST} https://www.example.com" "Hello from OpenShift" 0.2 50
273
-else
274
-	echo "[INFO] Validating app response..."
275
-	validate_response "http://${FRONTEND_IP}:5432" "Hello from OpenShift"
276
-fi
265
+# ensure the router is started
266
+wait_for_command "osc get pods | grep router-1 | grep -i Running" $((5*TIME_MIN))
277 267
 
268
+echo "[INFO] Validating routed app response..."
269
+validate_response "-s -k --resolve www.example.com:443:${CONTAINER_ACCESSIBLE_API_HOST} https://www.example.com" "Hello from OpenShift" 0.2 50