Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sensor): email trigger #2793

Merged
merged 29 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
136dbe2
chore(deps): bump github.com/antonmedv/expr from 1.14.3 to 1.15.0 (#2…
dependabot[bot] Sep 2, 2023
eb38cea
Add EmailTrigger Type
gokulav137 Sep 7, 2023
0bdf464
Add EmailTrigger which impliments Trigger interface
gokulav137 Sep 7, 2023
c785f15
Add EmailTrigger to GetTrigger
gokulav137 Sep 7, 2023
e440c25
Fix Protobuf Errors
gokulav137 Sep 7, 2023
147bd97
Make codegen
gokulav137 Sep 7, 2023
296311b
Fix type error - Cast emaiTrigger.Port int32 to int
gokulav137 Sep 7, 2023
afaf548
Move email trigger validation from sensor/trigger/email/email.go to c…
gokulav137 Sep 7, 2023
cb1aa75
Modify To email address from list of string to string with one email …
gokulav137 Sep 9, 2023
5ff643c
Refactor EmailTrigger type - Reorder for readability, bring smtp
gokulav137 Sep 9, 2023
3a8ca4d
Modify EmailTrigger To,From,Subject and Body to be optional
gokulav137 Sep 9, 2023
1be6e5d
Add optional and default comment to Port for EmailTrigger type
gokulav137 Sep 9, 2023
a3ac2ba
Add EmailTrigger Username, Host, Port validation to Sensor Validation
gokulav137 Sep 9, 2023
266e96b
Add unit tests for email package - sensors/triggers/email
gokulav137 Sep 9, 2023
5c5a6c1
Add Example for EmailTrigger
gokulav137 Sep 9, 2023
ea3ec14
Add formatting for EmailTrigger in types - add full stop
gokulav137 Sep 9, 2023
fee3853
Run make codegen
gokulav137 Sep 9, 2023
f722bcf
Refactor tests to not use variable defined outside Run
gokulav137 Sep 9, 2023
c5bc890
Fix linting errors
gokulav137 Sep 9, 2023
bd49ef9
Run make codegen - after downgrading pandoc to 2.17.1
gokulav137 Sep 9, 2023
a153daf
Merge branch 'master' into feature-sensor-email-trigger
gokulav137 Sep 9, 2023
31d9056
Modify EmailTrigger to support multiple to email addresses
gokulav137 Sep 16, 2023
bbb1f45
Modified EmailTriger example to use list for To and reduced example c…
gokulav137 Sep 16, 2023
115668e
Add support for smtp servers without authentication
gokulav137 Sep 16, 2023
9620178
Run Make codegen
gokulav137 Sep 16, 2023
dbfc55c
Modify example for documentation
gokulav137 Sep 16, 2023
37a460f
Fix typo in example DataTemplate -> dataTemplate
gokulav137 Sep 16, 2023
2858e03
Add Doc for Email Trigger
gokulav137 Sep 16, 2023
33b73ec
Merge branch 'master' into feature-sensor-email-trigger
gokulav137 Sep 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3460,8 +3460,11 @@
"type": "string"
},
"to": {
"description": "To refers to the email address to which email is send.",
"type": "string"
"description": "To refers to the email addresses to which the emails are send.",
"items": {
"type": "string"
},
"type": "array"
},
"username": {
"description": "Username refers to the username used to connect to the smtp server.",
Expand Down
7 changes: 5 additions & 2 deletions api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions api/sensor.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions api/sensor.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions controllers/sensor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,6 @@ func validateEmailTrigger(trigger *v1alpha1.EmailTrigger) error {
if trigger == nil {
return fmt.Errorf("trigger can't be nil")
}
if trigger.SMTPPassword == nil {
return fmt.Errorf("smtp password can't be empty")
}
if trigger.Username == "" {
return fmt.Errorf("username can't be empty")
}
if trigger.Host == "" {
return fmt.Errorf("host can't be empty")
}
Expand Down
104 changes: 104 additions & 0 deletions docs/sensors/triggers/email-trigger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Email Trigger

The Email trigger is used to send a custom email to a desired set of email addresses using an SMTP server. The intended use is for notifications for a build pipeline, but can be used for any notification scenario.

## Prerequisite

1. Deploy the eventbus in the namespace.

2. Have an SMTP server setup.

3. Create a kubernetes secret with the SMTP password in your cluster.

kubectl create secret generic smtp-secret --from-literal=password=$SMTP_PASSWORD

**Note**: If your SMTP server doesnot require authentication this step can be skipped.

4. Create a webhook event-source.

kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml

5. Set up port-forwarding to expose the http server. We will
use port-forwarding here.

kubectl port-forward -n argo-events <event-source-pod-name> 12000:12000

## Email Trigger

Lets say we want to send an email to a dynamic recepient using a custom email body template.

The custom email body template we are going to use is the following:
```
Hi <name>,
Hello There

Thanks,
Obi
```
where the name has to be substituted with the receiver name from the event.

1. Create a sensor with Email trigger.

kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/email-trigger.yaml

**Note**: Please update ```email.port```, ```email.host``` and ```email.username``` to that of your SMTP server.
If your SMTP server doesnot require authentication, the ```email.username``` and ```email.smtpPassword``` should be ommitted.

2. Send a http request to the event-source-pod to fire the Email trigger.

curl -d '{"name":"Luke", "to":"[email protected]"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example

**Note**: You can modify the value for key ```"to"``` to send the email to your address.

2. Alternatively you can skip providing the ```"to"``` in the payload to send an email to static email address provided in the trigger.

curl -d '{"name":"Luke"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example

**Note**: You have to remove the parameterization for ```email.to.0``` and add ```email.to``` like so:
```yaml
email:
...
to:
- [email protected]
- [email protected]
...
```

## Parameterization

We can parameterize the to, from, subject and body of the email trigger for dynamic capabilities.

The email trigger parameters have the following structure,

- parameters:
- src:
dependencyName: test-dep
dataKey: body.to
dest: email.to.0
- src:
dependencyName: test-dep
dataKey: body.to
dest: email.to.-1
- src:
dependencyName: test-dep
dataKey: body.from
dest: email.from
- src:
dependencyName: test-dep
dataKey: body.subject
dest: email.subject
- src:
dependencyName: test-dep
dataKey: body.emailBody
dest: email.body


- ```email.to.index``` can be used to overwite an email address already specified in the trigger at the provided index. (where index is an integer)
- ```email.to.-1``` can be used to append a new email address to the addresses to which an email will be sent.
- ```email.from``` can be used to specify the from address of the email sent.
- ```email.body``` can be used to specify the body of the email which will be sent.
- ```email.subject``` can be used to specify the subject of the email which will be sent.

To understand more on parameterization, take a look at [this tutorial](https://argoproj.github.io/argo-events/tutorials/02-parameterization/).

The complete specification of Email trigger is available [here](https://github.com/argoproj/argo-events/blob/master/api/sensor.md#emailtrigger).
7 changes: 5 additions & 2 deletions examples/sensors/email-trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ spec:
- src:
dependencyName: test-dep
dataKey: body.to
dest: email.to
dest: email.to.-1
- src:
dependencyName: test-dep
DataTemplate: "Hi {{.Input.body.name}},\n\n\tHello There.\n\nThanks,\nObi"
dataTemplate: "Hi {{.Input.body.name}},\n\n\tHello There.\n\nThanks,\nObi"
dest: email.body
template:
name: email-trigger
Expand All @@ -24,6 +24,9 @@ spec:
smtpPassword:
key: password
name: smtp-secret
# to:
# - [email protected]
# - [email protected]
host: smtp.example.net
port: 587
from: [email protected]
Expand Down
Loading