-
Notifications
You must be signed in to change notification settings - Fork 746
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
feat(sensor): email trigger #2793
Conversation
…goproj#2781) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
- EmailTrigger use EmailService to send email - Execute asserts receiver email is provided - Execute asserts receiver emails are valid emails - Execute asserts Body cannot be empty - Execute asserts Subject cannot be empty Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
- Change Port from int to int32 - Fix typo portobuf to protobuf - Change protobuf type for port from bytes to varint - Fix typo protobuff to protobuf Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
…ontrollers/sensor/validate.go Signed-off-by: gokulav137 <[email protected]>
…address Change is made as notification.emailService doesnot support multiple to email addresses Signed-off-by: gokulav137 <[email protected]>
username and password together Signed-off-by: gokulav137 <[email protected]>
- Add optional comment to EmailTrigger type - Move validation for To,From,Subject and Body from controller validation to trigger execution validation Signed-off-by: gokulav137 <[email protected]>
EmailTrigger Port default value specified as 0 Signed-off-by: gokulav137 <[email protected]>
- Username can't be empty - Host can't be empty - Port should be between 0-65535 Signed-off-by: gokulav137 <[email protected]>
- Test EmailTrigger.FetchResource - Test EmailTrigger.ApplyResource - Test EmailTrigger.Execute Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
4e85cd9
to
bd49ef9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for submitting the PR!
pkg/apis/sensor/v1alpha1/types.go
Outdated
Port int32 `json:"port,omitempty" protobuf:"varint,5,opt,name=port"` | ||
// To refers to the email address to which email is send. | ||
// +optional | ||
To string `json:"to,omitempty" protobuf:"bytes,6,opt,name=to"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is making it []string
better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it [] string
would better. But argoproj/notifications-engine doesn't support multiple to emails.
This line passes only one to address down.
https://github.com/argoproj/notifications-engine/blob/master/pkg/services/email.go#L84C43-L84C43
sensors/triggers/email/email.go
Outdated
} | ||
destination := notifications.Destination{ | ||
Service: "email", | ||
Recipient: emailTrigger.To, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to send to multiple recipients?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking along the lines that the user can create a mail group at their end and use that.
But if we need to support this out of the box, I think we have to either:
- Modify the notifications-engine to support multiple to emails
maybe something like
to := String.Split(dest.Recipient, ",")
email := smtp.New(smtp.Options{
........
........
}).WithSubject(subject).WithBody(body).To(to[0], to[1:]...)
in https://github.com/argoproj/notifications-engine/blob/master/pkg/services/email.go#L77-L84
This shouldn't break any existing functionality
OR
- Send multiple email notifications with each of the to addresses. But this isn't ideal.
OR
- we have to implement a different email service
@whynowy , Would be great to get your opinion on this. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check how the following is implemented?
https://github.com/argoproj/notifications-engine/blob/master/README.md?plain=1#L73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding was that it was sending out multiple emails out with different recipients as mentioned in the second option. As this matches with pattern in other applications like slack where a recipient will be a channel or user.
Hence the suggestion of adding support for comma separated emails for recipients to the email notification service at notification-engine.
But I will take another look at it. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cloned the notifications-engine repo and ran it locally.
Its sending the emails separately. So an email will be sent out for each recipient:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: another
annotations:
notifications.argoproj.io/subscriptions: |
- trigger: [on-cert-ready]
destinations:
- service: email
recipients: [[email protected], [email protected]]
spec:
secretName: something
issuerRef:
name: letsencrypt-staging
emailAddresses:
- [email protected]
I tried adding the comma separated change it worked.
to := String.Split(dest.Recipient, ",")
email := smtp.New(smtp.Options{
........
........
}).WithSubject(subject).WithBody(body).To(to[0], to[1:]...)
It send an email with multiple to addresses:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: another
annotations:
notifications.argoproj.io/subscriptions: |
- trigger: [on-cert-ready]
destinations:
- service: email
recipients: ["[email protected],[email protected]", [email protected]]
spec:
secretName: something
issuerRef:
name: letsencrypt-staging
emailAddresses:
- [email protected]
Here one email would be sent with only [email protected] as recipient and another with both.
@whynowy what do you think. Should I go with this approach and raise a pull request there. Looks like it will add to notification-engines functionality too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest:
- Make the
To
a[]string
; - Do for loop here to send notifications;
- If there's a follow up in notification-engine to support multiple recipients, we update it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, sounds like a good plan. Will do the same. Thanks.
Please also add a doc in https://github.com/argoproj/argo-events/tree/master/docs/sensors/triggers. Thanks! |
- Modified EmailTrigger.To from string to []string - Refactored email sending logic to send an email each to all the addresses in To Signed-off-by: gokulav137 <[email protected]>
…omplexity Removed parameterization to reduce complexity in example Signed-off-by: gokulav137 <[email protected]>
- Modify types comment for Username and SMTPPassword to be optional - Remove Username and SMTPPassword requirement check - Refactor SMTPPassword retrieval from secrets to only when SMTPPassword is not nil Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
- Add dynamic to email use case and commented satic to email use case Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
Signed-off-by: gokulav137 <[email protected]>
var errs error | ||
validEmail := regexp.MustCompile(`^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$`) | ||
for _, addr := range emailTrigger.To { | ||
if !validEmail.MatchString(addr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we move it to validate.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand validate.go does the pre validations when a sensor is created.
To support dynamic recipient address the validation was moved here. So that validation for to addresses will take place during execution.
Please correct me if I am wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gokulav137 - you are right, missed that!
Signed-off-by: gokulav137 <[email protected]> Signed-off-by: jmillage <[email protected]>
Adding email triggers support using existing email notification service
Resolves #1817
Also added Example and unit tests for email trigger
First time contributor here. Please let me know incase any issues/ changes in design
Email Trigger specification:
EmailTrigger
(Appears on: TriggerTemplate)
EmailTrigger refers to the specification of the email notification trigger.
parameters
\[\]TriggerParameter
Parameters is the list of key-value extracted from event’s payload that are applied to the trigger resource.
username
string
Username refers to the username used to connect to the smtp server.
smtpPassword
Kubernetes core/v1.SecretKeySelector
SMTPPassword refers to the Kubernetes secret that holds the smtp password used to connect to smtp server.
host
string
Host refers to the smtp host url to which email is send.
port
int32
Port refers to the smtp server port to which email is send. Defaults to 0.
to
\[\]string
To refers to the email addresses to which the emails are send.
from
string
From refers to the address from which the email is send from.
subject
string
Subject refers to the subject line for the email send.
body
string
Body refers to the body/content of the email send.
Example:
Checklist: