github.com/argoproj/argo-events@v1.9.1/docs/tutorials/06-trigger-conditions.md (about) 1 # Trigger Conditions 2 3 In the previous sections, you have been dealing with just a single dependency. 4 But, in many cases, you want to wait for multiple events to occur and then 5 trigger a resource which means you need a mechanism to determine which triggers 6 to execute based on set of different event dependencies. This mechanism is 7 supported through `conditions`. 8 9 **Note**: Whenever you define multiple dependencies in a sensor, the sensor 10 applies a `AND` operation, meaning, it will wait for all dependencies to resolve 11 before it executes triggers. `conditions` can modify that behavior. 12 13 ## Prerequisite 14 15 Minio server must be set up in the `argo-events` namespace with a bucket called 16 `test` and it should be available at `minio-service.argo-events:9000`. 17 18 ## Conditions 19 20 Consider a scenario where you have a `Webhook` and `Minio` event-source, and you 21 want to trigger an Argo workflow if the sensor receives an event from the 22 `Webhook` event-source, but, another workflow if it receives an event from the 23 `Minio` event-source. 24 25 1. Create the webhook event-source and event-source. The event-source listens 26 to HTTP requests on port `12000`. 27 28 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/tutorials/06-trigger-conditions/webhook-event-source.yaml 29 30 2. Create the minio event-source. The event-source listens to events of type 31 `PUT` and `DELETE` for objects in bucket `test`. 32 33 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/tutorials/06-trigger-conditions/minio-event-source.yaml 34 35 Make sure there are no errors in any of the event-sources. 36 37 3. Let's create the sensor. If you take a closer look at the trigger templates, 38 you will notice that it contains a field named `conditions`, which is a 39 boolean expression contains dependency names. So, as soon as the expression 40 is resolved as true, the corresponding trigger will be executed. 41 42 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/tutorials/06-trigger-conditions/sensor-01.yaml 43 44 4. Send a HTTP request to Webhook event-source. 45 46 curl -d '{"message":"this is my first webhook"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example 47 48 5. You will notice an Argo workflow with name `group-1-xxxx` is created with 49 following output, 50 51 __________________________ 52 < this is my first webhook > 53 -------------------------- 54 \ 55 \ 56 \ 57 ## . 58 ## ## ## == 59 ## ## ## ## === 60 /""""""""""""""""___/ === 61 ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ 62 \______ o __/ 63 \ \ __/ 64 \____\______/ 65 66 6. Now, lets generate a Minio event so that we can run `group-2-xxxx` workflow. 67 Drop a file onto `test` bucket. The workflow that will get created will 68 print the name of the bucket as follows, 69 70 ______ 71 < test > 72 ------ 73 \ 74 \ 75 \ 76 ## . 77 ## ## ## == 78 ## ## ## ## === 79 /""""""""""""""""___/ === 80 ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ 81 \______ o __/ 82 \ \ __/ 83 \____\______/ 84 85 5. Great!! You have now learned how to use `conditions`. Lets update the sensor 86 with a trigger that waits for both dependencies to resolve. This is the 87 normal sensor behavior if `conditions` is not defined. 88 89 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/tutorials/06-trigger-conditions/sensor-02.yaml 90 91 Send a HTTP request and perform a file drop on Minio bucket as done above. 92 You should get the following output. 93 94 _______________________________ 95 < this is my first webhook test > 96 ------------------------------- 97 \ 98 \ 99 \ 100 ## . 101 ## ## ## == 102 ## ## ## ## === 103 /""""""""""""""""___/ === 104 ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ 105 \______ o __/ 106 \ \ __/ 107 \____\______/