-
Notifications
You must be signed in to change notification settings - Fork 873
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: support notifications on rollout events using notifications-engine #1175
Merged
alexmt
merged 5 commits into
argoproj:master
from
alexmt:369-notifications-custom-triggers
Jun 18, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7d2e52a
feat: integrate notifications engine
alexmt c79c657
more notification templates; trigger names using convention
alexmt 0101af0
add notifitions documentation feature
alexmt 9f09617
more unit tests
alexmt 2d5949e
Apply reviewer notes
alexmt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# Notifications | ||
|
||
!!! important | ||
Available since v1.1 | ||
|
||
Argo Rollouts provides notifications powered by the [Notifications Engine](https://github.com/argoproj/notifications-engine). | ||
Controller administrators can leverage flexible systems of triggers and templates to configure notifications requested | ||
by the end users. The end-users can subscribe to the configured triggers by adding an annotation to the Rollout objects. | ||
|
||
## Configuration | ||
|
||
The trigger defines the condition when the notification should be sent as well as the notification content template. | ||
Default Argo Rollouts comes with a list of built-in triggers that cover the most important events of Argo Rollout live-cycle. | ||
Both triggers and templates are configured in the `argo-rollouts-notification-configmap` ConfigMap. In order to get | ||
started quickly, you can use pre-configured notification templates defined in [notifications-install.yaml](../../manifests/notifications-install.yaml). | ||
|
||
If you are leveraging Kustomize it is recommended to include [notifications-install.yaml](../../manifests/notifications-install.yaml) as a remote | ||
resource into your `kustomization.yaml` file: | ||
|
||
```yaml | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml | ||
- https://github.com/argoproj/argo-rollouts/releases/latest/download/notifications-install.yaml | ||
``` | ||
|
||
After including the `argo-rollouts-notification-configmap` ConfigMap the administrator needs to configure integration | ||
with the required notifications service such as Slack or MS Teams. An example below demonstrates Slack integration: | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: argo-rollouts-notification-configmap | ||
data: | ||
service.slack: | | ||
token: $slack-token | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: argo-rollouts-notification-secret | ||
stringData: | ||
slack-token: <my-slack-token> | ||
``` | ||
|
||
Learn more about supported services and configuration settings in services [documentation](../generated/notification-services/overview.md). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link is broken There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. link is referencing file is generated directory. So these files are not committed to git. |
||
|
||
## Subscriptions | ||
|
||
The end-users can start leveraging notifications using `notifications.argoproj.io/subscribe.<trigger>.<service>: <recipient>` annotation. | ||
For example, the following annotation subscribes two Slack channels to notifications about canary rollout step completion: | ||
|
||
```yaml | ||
--- | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Rollout | ||
metadata: | ||
name: rollout-canary | ||
annotations: | ||
notifications.argoproj.io/subscribe.on-rollout-step-completed.slack: my-channel1;my-channel2 | ||
|
||
``` | ||
|
||
Annotation key consists of following parts: | ||
|
||
* `on-rollout-step-completed` - trigger name | ||
* `slack` - notification service name | ||
* `my-channel1;my-channel2` - a semicolon separated list of recipients | ||
|
||
## Customization | ||
|
||
The Rollout administrator can customize the notifications by configuring notification templates and custom triggers | ||
in `argo-rollouts-notification-configmap` ConfigMap. | ||
|
||
### Templates | ||
|
||
The notification template is a stateless function that generates the notification content. The template is leveraging | ||
[html/template](https://golang.org/pkg/html/template/) golang package. It is meant to be reusable and can be referenced by multiple triggers. | ||
|
||
An example below demonstrates a sample template: | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: argo-rollouts-notification-configmap | ||
data: | ||
template.my-purple-template: | | ||
message: | | ||
Rollout {{.rollout.metadata.name}} has purple image | ||
slack: | ||
attachments: | | ||
[{ | ||
"title": "{{ .rollout.metadata.name}}", | ||
"color": "#800080" | ||
}] | ||
``` | ||
|
||
Each template has access to the following fields: | ||
|
||
- `rollout` holds the rollout object. | ||
- `recipient` holds the recipient name. | ||
|
||
The `message` field of the template definition allows creating a basic notification for any notification service. You can | ||
leverage notification service-specific fields to create complex notifications. For example using service-specific you can | ||
add blocks and attachments for Slack, subject for Email or URL path, and body for Webhook. See corresponding service | ||
[documentation](../generated/notification-services/overview.md) for more information. | ||
|
||
### Custom Triggers | ||
|
||
In addition to custom notification template administrator and configure custom triggers. Custom trigger defines the | ||
condition when the notification should be sent. The definition includes name, condition and notification templates reference. | ||
The condition is a predicate expression that returns true if the notification should be sent. The trigger condition | ||
evaluation is powered by [antonmedv/expr](https://github.com/antonmedv/expr). | ||
The condition language syntax is described at [Language-Definition.md](https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md). | ||
|
||
The trigger is configured in `argo-rollouts-notification-configmap` ConfigMap. For example the following trigger sends a notification | ||
when rollout pod spec uses `argoproj/rollouts-demo:purple` image: | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: argocd-notifications-cm | ||
data: | ||
trigger.on-purple: | | ||
- send: [my-purple-template] | ||
when: rollout.spec.template.spec.containers[0].image == 'argoproj/rollouts-demo:purple' | ||
``` | ||
|
||
Each condition might use several templates. Typically each template is responsible for generating a service-specific notification part. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: argo-rollouts-notification-configmap | ||
data: | ||
service.slack: | | ||
token: $slack-token | ||
## Custom Trigger | ||
trigger.on-purple: | | ||
- send: [my-purple-template] | ||
when: rollout.spec.template.spec.containers[0].image == 'argoproj/rollouts-demo:purple' | ||
template.my-purple-template: | | ||
message: | | ||
Rollout {{.rollout.metadata.name}} has purple image | ||
slack: | ||
attachments: | | ||
[{ | ||
"title": "{{ .rollout.metadata.name}}", | ||
"color": "#800080" | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- ../../manifests/notifications | ||
|
||
patchesStrategicMerge: | ||
- configmap.yaml |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add a note:
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.
done
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.
has v1.1 been released yet? i see that the release tags only go up to v1.0.2