Skip to content

Commit

Permalink
[#894] tutorial tester
Browse files Browse the repository at this point in the history
Usage (to be executed at the root of the operator)

```
Usage of /tmp/go-build2452366115/b001/exe/tester:
  -dry-run
    	just list what would be executed without doing it
  -ignore-breakpoints
    	ignore the breakpoints
  -interactive
    	prompt to press enter between each chunk
  -list
    	just list the tutorials found
  -no-styling
    	disable spiners in cli
  -quiet
    	disable output
  -start-from string
    	start from a specific stage name
  -timeout int
    	the timeout in minutes for every executed command (default 10)
  -tutorial string
    	Run only a specific tutorial
  -tutorials-root string
    	where to find the tutorials (default "./docs/tutorials")
  -update-tutorials
    	update the chunk output section in the tutorials
  -verbose
    	print more logs
```

Checkout docs/tutorials/writing_tutorials.md for more details about how
to write executable tutorials.
  • Loading branch information
lavocatt authored and brusdev committed Sep 4, 2024
1 parent 91ea49a commit 6ae91ca
Show file tree
Hide file tree
Showing 7 changed files with 1,896 additions and 248 deletions.
299 changes: 230 additions & 69 deletions docs/tutorials/send_receive_ingress.md

Large diffs are not rendered by default.

366 changes: 254 additions & 112 deletions docs/tutorials/send_receive_ingress_pem.md

Large diffs are not rendered by default.

190 changes: 127 additions & 63 deletions docs/tutorials/send_receive_port_forwarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,99 @@ Before you start, you need to have access to a running Kubernetes cluster
environment. A [Minikube](https://minikube.sigs.k8s.io/docs/start/) instance
running on your laptop will do fine.

#### Start minikube with a parametrized dns domain name

```{"stage":"init", "id":"minikube_start"}
minikube start --profile tutorialtester
minikube profile tutorialtester
```
```shell tutorial_tester
* [tutorialtester] minikube v1.32.0 on Fedora 40
* Automatically selected the docker driver. Other choices: kvm2, qemu2, ssh
* Using Docker driver with root privileges
* Starting control plane node tutorialtester in cluster tutorialtester
* Pulling base image ...
* Creating docker container (CPUs=2, Memory=15900MB) ...
* Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
- Generating certificates and keys ...
- Booting up control plane ...
- Configuring RBAC rules ...
* Configuring bridge CNI (Container Networking Interface) ...
- Using image gcr.io/k8s-minikube/storage-provisioner:v5
* Verifying Kubernetes components...
* Enabled addons: storage-provisioner, default-storageclass
* Done! kubectl is now configured to use "tutorialtester" cluster and "default" namespace by default
* minikube profile was successfully set to tutorialtester
```

#### Enable nginx and ssl passthrough for minikube

```{"stage":"init"}
minikube addons enable ingress
minikube kubectl -- patch deployment -n ingress-nginx ingress-nginx-controller --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value":"--enable-ssl-passthrough"}]'
```
```shell tutorial_tester
* ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.
You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
- Using image registry.k8s.io/ingress-nginx/controller:v1.9.4
- Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0
- Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0
* Verifying ingress addon...
* The 'ingress' addon is enabled
deployment.apps/ingress-nginx-controller patched
```

#### Make sure the domain of your cluster is resolvable

If you are running your OpenShift cluster locally, you might not be able to
resolve the urls to IPs out of the blue. Follow [this guide]({{< ref
"/docs/help/hostname_resolution" >}} "set up dnsmasq") to configure your setup.

This tutorial will follow the simple /etc/hosts approach, but feel free to use
the most appropriate one for you.

### Deploy the operator

#### create the namespace

```console
$ kubectl create namespace send-receive-project
$ kubectl config set-context --current --namespace=send-receive-project
```{"stage":"init"}
kubectl create namespace send-receive-project
kubectl config set-context --current --namespace=send-receive-project
```
```shell tutorial_tester
namespace/send-receive-project created
Context "tutorialtester" modified.
```

Go to the root of the operator repo and install it:

```console
$ cd send-receive-project
$ ./deploy/install_opr.sh
```{"stage":"init", "rootdir":"$operator"}
./deploy/install_opr.sh
```
```shell tutorial_tester
Deploying operator to watch single namespace
Client Version: 4.15.0-0.okd-2024-01-27-070424
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Kubernetes Version: v1.28.3
customresourcedefinition.apiextensions.k8s.io/activemqartemises.broker.amq.io created
customresourcedefinition.apiextensions.k8s.io/activemqartemisaddresses.broker.amq.io created
customresourcedefinition.apiextensions.k8s.io/activemqartemisscaledowns.broker.amq.io created
customresourcedefinition.apiextensions.k8s.io/activemqartemissecurities.broker.amq.io created
serviceaccount/activemq-artemis-controller-manager created
role.rbac.authorization.k8s.io/activemq-artemis-operator-role created
rolebinding.rbac.authorization.k8s.io/activemq-artemis-operator-rolebinding created
role.rbac.authorization.k8s.io/activemq-artemis-leader-election-role created
rolebinding.rbac.authorization.k8s.io/activemq-artemis-leader-election-rolebinding created
deployment.apps/activemq-artemis-controller-manager created
```

Wait for the Operator to start (status: `running`).
```console
$ kubectl get pod --namespace send-receive-project

```bash {"stage":"init", "runtime":"bash", "label":"wait for the operator to be running"}
kubectl wait pod --all --for=condition=Ready --namespace=send-receive-project --timeout=600s
```
```shell tutorial_tester
pod/activemq-artemis-controller-manager-55b8c479df-2nxqd condition met
```

### Deploying the ActiveMQ Artemis Broker
Expand All @@ -48,105 +122,95 @@ For this tutorial we need to:
properties. Two queues are setup, one called `APP.JOBS` that is of type
`ANYCAST` and one called `APP.COMMANDS` that is of type `MULTICAST`.

```console
$ kubectl apply -f - <<EOF
```bash {"stage":"deploy", "HereTag":"EOF", "runtime":"bash", "label":"deploy the broker"}
kubectl apply -f - <<EOF
apiVersion: broker.amq.io/v1beta1
kind: ActiveMQArtemis
metadata:
name: default
name: send-receive
namespace: send-receive-project
spec:
acceptors:
- bindToAllInterfaces: true
name: acceptAll
name: acceptall
port: 62626
brokerProperties:
- addressConfigurations."APP.JOBS".routingTypes=ANYCAST
- addressConfigurations."APP.JOBS".queueConfigs."APP.JOBS".routingType=ANYCAST
- addressConfigurations."APP.COMMANDS".routingTypes=MULTICAST
EOF
```
```shell tutorial_tester
activemqartemis.broker.amq.io/send-receive created
```

Wait for the Broker to be ready:

```console
$ kubectl get ActivemqArtemis -o custom-columns="NAME:.metadata.name,READY:.status.conditions[?(@.type=='Ready')].status" -n send-receive-project
NAME READY
send-receive True
```{"stage":"deploy"}
kubectl wait ActiveMQArtemis send-receive --for=condition=Ready --namespace=send-receive-project --timeout=240s
```

### Forwarding ports

```console
$ kubectl port-forward default-ss-0 62626 -n send-receive-project
Forwarding from 127.0.0.1:62626 -> 62626
Forwarding from [::1]:62626 -> 62626
```shell tutorial_tester
activemqartemis.broker.amq.io/send-receive condition met
```


### Exchanging messages between a producer and a consumer

Download the [latest
release](https://activemq.apache.org/components/artemis/download/) of ActiveMQ
Artemis, decompress the tarball and locate the artemis executable.

#### ANYCAST
```bash {"stage":"test_setup", "rootdir":"$tmpdir.1", "runtime":"bash", "label":"download artemis"}
wget --quiet https://dlcdn.apache.org/activemq/activemq-artemis/2.36.0/apache-artemis-2.36.0-bin.tar.gz
tar -zxf apache-artemis-2.36.0-bin.tar.gz apache-artemis-2.36.0/
```

For this use case, run first the producer, then the consumer.
```bash {"stage":"test", "rootdir":"$tmpdir.1/apache-artemis-2.36.0/bin/", "parallel":true, "runtime":"bash", "label":"anycast: produce & consume 1000 messages"}
# First we need to start port forwarding
kubectl port-forward send-receive-ss-0 62626 -n send-receive-project &

```console
$ ./artemis producer --destination APP.JOBS --url tcp://localhost:62626
# Then produce and consume some messages
./artemis producer --destination APP.JOBS --url tcp://localhost:62626
./artemis consumer --destination APP.JOBS --url tcp://localhost:62626

# Finally we need to kill the port forwarding
pkill kubectl -9
```
```shell tutorial_tester
Forwarding from 127.0.0.1:62626 -> 62626
Forwarding from [::1]:62626 -> 62626
Connection brokerURL = tcp://localhost:62626
Handling connection for 62626
Handling connection for 62626
Producer ActiveMQQueue[APP.JOBS], thread=0 Started to calculate elapsed time ...

Producer ActiveMQQueue[APP.JOBS], thread=0 Produced: 1000 messages
Producer ActiveMQQueue[APP.JOBS], thread=0 Elapsed time in second : 8 s
Producer ActiveMQQueue[APP.JOBS], thread=0 Elapsed time in milli second : 8711 milli seconds
```

```console
$ ./artemis consumer --destination APP.JOBS --url tcp://localhost:62626

Producer ActiveMQQueue[APP.JOBS], thread=0 Elapsed time in milli second : 8766 milli seconds
Connection brokerURL = tcp://localhost:62626
Consumer:: filter = null
Handling connection for 62626
Handling connection for 62626
Consumer ActiveMQQueue[APP.JOBS], thread=0 wait until 1000 messages are consumed
Received 1000
Consumer ActiveMQQueue[APP.JOBS], thread=0 Consumed: 1000 messages
Consumer ActiveMQQueue[APP.JOBS], thread=0 Elapsed time in second : 0 s
Consumer ActiveMQQueue[APP.JOBS], thread=0 Elapsed time in milli second : 61 milli seconds
Consumer ActiveMQQueue[APP.JOBS], thread=0 Elapsed time in milli second : 68 milli seconds
Consumer ActiveMQQueue[APP.JOBS], thread=0 Consumed: 1000 messages
Consumer ActiveMQQueue[APP.JOBS], thread=0 Consumer thread finished
```
#### MULTICAST
### cleanup
For this use case, run first the consumer(s), then the producer.
More details there
https://activemq.apache.org/components/artemis/documentation/2.0.0/address-model.html.
To leave a pristine environment after executing this tutorial you can simply,
delete the minikube cluster.
In `n` other terminal(s) connect `n` consumer(s):

```console
$ ./artemis consumer --destination topic://APP.COMMANDS --url tcp://localhost:62626

Connection brokerURL = tcp://localhost:62626
Consumer:: filter = null
Consumer ActiveMQTopic[APP.COMMANDS], thread=0 wait until 1000 messages are consumed
Received 1000
Consumer ActiveMQTopic[APP.COMMANDS], thread=0 Consumed: 1000 messages
Consumer ActiveMQTopic[APP.COMMANDS], thread=0 Elapsed time in second : 14 s
Consumer ActiveMQTopic[APP.COMMANDS], thread=0 Elapsed time in milli second : 14934 milli seconds
Consumer ActiveMQTopic[APP.COMMANDS], thread=0 Consumed: 1000 messages
Consumer ActiveMQTopic[APP.COMMANDS], thread=0 Consumer thread finished
```{"stage":"teardown", "requires":"init/minikube_start"}
minikube delete --profile tutorialtester
```

Then connect the producer

```console
$ ./artemis producer --destination topic://APP.COMMANDS --url tcp://localhost:62626
Connection brokerURL = tcp://localhost:62626
Producer ActiveMQTopic[APP.COMMANDS], thread=0 Started to calculate elapsed time ...

Producer ActiveMQTopic[APP.COMMANDS], thread=0 Produced: 1000 messages
Producer ActiveMQTopic[APP.COMMANDS], thread=0 Elapsed time in second : 0 s
Producer ActiveMQTopic[APP.COMMANDS], thread=0 Elapsed time in milli second : 889 milli seconds
```shell tutorial_tester
* Deleting "tutorialtester" in docker ...
* Deleting container "tutorialtester" ...
* Removing /home/tlavocat/.minikube/machines/tutorialtester ...
* Removed all traces of the "tutorialtester" cluster.
```
Loading

0 comments on commit 6ae91ca

Please sign in to comment.