This is a simple demo. You need a Kubernetes cluster, I use kind.
kind create cluster --image=kindest/node:v1.23.3
Install Argo Events
kubectl create namespace argo-events
kubectl apply \
-f https://raw.githubusercontent.com/argoproj/argo-events/stable/manifests/install.yaml
kubectl -n argo-events apply \
-f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/eventbus/native.yaml
Event source are enteties that publish some sort of event. This is a simple webhook. Different options can be found here
apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
name: webhook
spec:
service:
ports:
- port: 12000
targetPort: 12000
webhook:
hello-world:
port: "12000"
endpoint: /hello-world
method: POST
Create this event source:
kubectl apply -f manifests/event-source.yaml -n argo-events
List your event sources
kubectl get eventsources -n argo-events
List the event source objects pods/service
kubectl get pods -n argo-events
kubectl get svc -n argo-events
Port fowrad to test hook
kubectl port-forward svc/webhook-eventsource-svc -n argo-events 12000:12000
Test with curl
curl -X POST -H "Content-Type: application/json" \
-d '{"message":"My first webhook"}' \
http://127.0.0.1:12000/hello-world
Sensors detects one or many events (so you can control dependencies) and triggers a Trigger to do some sort of task.
In this inistance, we'll just create a pod. Other trigger tempaltes
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: webhook
spec:
template:
serviceAccountName: argo-events-sa
dependencies:
- name: payload
eventSourceName: webhook
eventName: hello-world
triggers:
- template:
name: payload
k8s:
group: ""
version: v1
resource: pods
operation: create
source:
resource:
apiVersion: v1
kind: Pod
metadata:
generateName: payload-
labels:
app: payload
spec:
containers:
- name: hello
image: alpine
command: ["echo"]
args: ["Payload received: ", "", "\n"]
restartPolicy: Never
parameters:
- src:
dependencyName: payload
dataKey: body.message
dest: spec.containers.0.args.1
Here we can take the payload and use it as an argument!
Create the sensor with the trigger template
kubectl -n argo-events apply -f manifests/sensor.yaml
Now curl your event source
curl -X POST \
-H "Content-Type: application/json" \
-d '{"message":"This is my payload"}' \
http://127.0.0.1:12000/hello-world
Check that it created a pod
kubectl -n argo-events get pods
Look at the logs for your message
kubectl -n argo-events logs -l app=payload
Clean up pods to try again
kubectl -n argo-events delete pods -l app=payload
To clean up, just kill the cluster
kind delete clusters --all