Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
refactor: Replace template.body, template.title fields with `temp…
Browse files Browse the repository at this point in the history
…late.message` and `template.email.subject` fields (#151)
  • Loading branch information
Alexander Matyushentsev authored Jan 13, 2021
1 parent dc9984c commit 5586bb3
Show file tree
Hide file tree
Showing 35 changed files with 731 additions and 334 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Built-in triggers/templates replaced with triggers/templates "catalog" (#56)
* `config.yaml` and `notifiers.yaml` configs split into multiple ConfigMap keys (#76)
* `trigger.enabled` field is replaced with `defaultTriggers` setting
* Replace `template.body`, `template.title` fields with `template.message` and `template.email.subject` fields

## v0.7.0 (2020-05-10)

Expand Down
58 changes: 45 additions & 13 deletions catalog/install.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
apiVersion: v1
data:
template.app-deployed: |
body: |
email:
subject: New version of an application {{.app.metadata.name}} is up and running.
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} is now running new version of deployments manifests.
slack:
attachments: |
Expand Down Expand Up @@ -36,9 +38,10 @@ data:
{{end}}
]
}]
title: New version of an application {{.app.metadata.name}} is up and running.
template.app-health-degraded: |
body: |
email:
subject: Application {{.app.metadata.name}} has degraded.
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} Application {{.app.metadata.name}} has degraded.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
slack:
Expand Down Expand Up @@ -69,16 +72,44 @@ data:
{{end}}
]
}]
title: Application {{.app.metadata.name}} has degraded.
template.app-sync-failed: |
body: |
email:
subject: Failed to sync application {{.app.metadata.name}}.
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} The sync operation of application {{.app.metadata.name}} has failed at {{.app.status.operationState.finishedAt}} with the following error: {{.app.status.operationState.message}}
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
slack:
attachments: "[{\n \"title\": \"{{ .app.metadata.name}}\",\n \"title_link\":\"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}\",\n \"color\": \"#E96D76\",\n \"fields\": [\n {\n \"title\": \"Sync Status\",\n \"value\": \"{{.app.status.sync.status}}\",\n \"short\": true\n },\n {\n \"title\": \"Repository\",\n \"value\": \"{{.app.spec.source.repoURL}}\",\n \"short\": true\n }\n {{range $index, $c := .app.status.conditions}}\n {{if not $index}},{{end}}\n {{if $index}},{{end}}\n {\n \"title\": \"{{$c.type}}\",\n \"value\": \"{{$c.message}}\",\n \"short\": true\n }\n {{end}}\n ]\n}] "
title: Failed to sync application {{.app.metadata.name}}.
attachments: |-
[{
"title": "{{ .app.metadata.name}}",
"title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
"color": "#E96D76",
"fields": [
{
"title": "Sync Status",
"value": "{{.app.status.sync.status}}",
"short": true
},
{
"title": "Repository",
"value": "{{.app.spec.source.repoURL}}",
"short": true
}
{{range $index, $c := .app.status.conditions}}
{{if not $index}},{{end}}
{{if $index}},{{end}}
{
"title": "{{$c.type}}",
"value": "{{$c.message}}",
"short": true
}
{{end}}
]
}]
template.app-sync-running: |
body: |
email:
subject: Start syncing application {{.app.metadata.name}}.
message: |
The sync operation of application {{.app.metadata.name}} has started at {{.app.status.operationState.startedAt}}.
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
slack:
Expand Down Expand Up @@ -109,9 +140,10 @@ data:
{{end}}
]
}]
title: Start syncing application {{.app.metadata.name}}.
template.app-sync-status-unknown: |
body: |
email:
subject: Application {{.app.metadata.name}} sync status is 'Unknown'
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} Application {{.app.metadata.name}} sync is 'Unknown'.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
{{if ne .serviceType "slack"}}
Expand Down Expand Up @@ -147,14 +179,14 @@ data:
{{end}}
]
}]
title: Application {{.app.metadata.name}} sync status is 'Unknown'
template.app-sync-succeeded: |
body: |
email:
subject: Application {{.app.metadata.name}} has been successfully synced.
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} has been successfully synced at {{.app.status.operationState.finishedAt}}.
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
slack:
attachments: "[{\n \"title\": \"{{ .app.metadata.name}}\",\n \"title_link\":\"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}\",\n \"color\": \"#18be52\",\n \"fields\": [\n {\n \"title\": \"Sync Status\",\n \"value\": \"{{.app.status.sync.status}}\",\n \"short\": true\n },\n {\n \"title\": \"Repository\",\n \"value\": \"{{.app.spec.source.repoURL}}\",\n \"short\": true\n }\n {{range $index, $c := .app.status.conditions}}\n {{if not $index}},{{end}}\n {{if $index}},{{end}}\n {\n \"title\": \"{{$c.type}}\",\n \"value\": \"{{$c.message}}\",\n \"short\": true\n }\n {{end}}\n ]\n}] "
title: Application {{.app.metadata.name}} has been successfully synced.
trigger.on-deployed: |
- description: Application is synced and healthy. Triggered once per commit.
oncePer: app.status.sync.revision
Expand Down
5 changes: 3 additions & 2 deletions catalog/templates/app-deployed.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
title: "New version of an application {{.app.metadata.name}} is up and running."
body: |
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} is now running new version of deployments manifests.
email:
subject: New version of an application {{.app.metadata.name}} is up and running.
slack:
attachments: |
[{
Expand Down
5 changes: 3 additions & 2 deletions catalog/templates/app-health-degraded.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
title: "Application {{.app.metadata.name}} has degraded."
body: |
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} Application {{.app.metadata.name}} has degraded.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
email:
subject: Application {{.app.metadata.name}} has degraded.
slack:
attachments: |
[{
Expand Down
7 changes: 4 additions & 3 deletions catalog/templates/app-sync-failed.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
title: "Failed to sync application {{.app.metadata.name}}."
body: |
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} The sync operation of application {{.app.metadata.name}} has failed at {{.app.status.operationState.finishedAt}} with the following error: {{.app.status.operationState.message}}
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
email:
subject: Failed to sync application {{.app.metadata.name}}.
slack:
attachments: |
[{
Expand Down Expand Up @@ -29,4 +30,4 @@ slack:
}
{{end}}
]
}]
}]
5 changes: 3 additions & 2 deletions catalog/templates/app-sync-running.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
title: "Start syncing application {{.app.metadata.name}}."
body: |
message: |
The sync operation of application {{.app.metadata.name}} has started at {{.app.status.operationState.startedAt}}.
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
email:
subject: "Start syncing application {{.app.metadata.name}}."
slack:
attachments: |
[{
Expand Down
5 changes: 3 additions & 2 deletions catalog/templates/app-sync-status-unknown.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
title: "Application {{.app.metadata.name}} sync status is 'Unknown'"
body: |
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} Application {{.app.metadata.name}} sync is 'Unknown'.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
{{if ne .serviceType "slack"}}
{{range $c := .app.status.conditions}}
* {{$c.message}}
{{end}}
{{end}}
email:
subject: Application {{.app.metadata.name}} sync status is 'Unknown'
slack:
attachments: |
[{
Expand Down
5 changes: 3 additions & 2 deletions catalog/templates/app-sync-succeeded.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
title: "Application {{.app.metadata.name}} has been successfully synced."
body: |
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} has been successfully synced at {{.app.status.operationState.finishedAt}}.
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
email:
subject: Application {{.app.metadata.name}} has been successfully synced.
slack:
attachments: |
[{
Expand Down
12 changes: 8 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import (
"os"
"path/filepath"

"github.com/spf13/cobra"

"github.com/argoproj-labs/argocd-notifications/cmd/tools"
"github.com/spf13/cobra"
)

func main() {
binaryName := filepath.Base(os.Args[0])
if val := os.Getenv("ARGOCD_NOTIFICATIONS_BINARY"); val != "" {
binaryName = val
}
var command *cobra.Command
if filepath.Base(os.Args[0]) == "argocd-notifications-backend" || os.Getenv("ARGOCD_NOTIFICATIONS_BACKEND") == "true" {
switch binaryName {
case "argocd-notifications-backend":
command = &cobra.Command{
Use: "argocd-notifications-backend",
Run: func(c *cobra.Command, args []string) {
Expand All @@ -21,7 +25,7 @@ func main() {
}
command.AddCommand(newControllerCommand())
command.AddCommand(newBotCommand())
} else {
default:
command = tools.NewToolsCommand()
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/tools/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestTemplateNotifyConsole(t *testing.T) {
cmData := map[string]string{
"trigger.my-trigger": `[{when: "app.metadata.name == 'guestbook'", send: [my-template]}]`,
"template.my-template": `
title: hello {{.app.metadata.name}}`,
message: hello {{.app.metadata.name}}`,
}
var stdout bytes.Buffer
var stderr bytes.Buffer
Expand All @@ -32,8 +32,8 @@ title: hello {{.app.metadata.name}}`,

func TestTemplateGet(t *testing.T) {
cmData := map[string]string{
"template.my-template1": `{title: hello}`,
"template.my-template2": `{title: hello}`,
"template.my-template1": `{message: hello}`,
"template.my-template2": `{message: hello}`,
}

var stdout bytes.Buffer
Expand Down
4 changes: 2 additions & 2 deletions cmd/tools/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestTriggerRun(t *testing.T) {
- when: app.metadata.name == 'guestbook'
send: [my-template]`,
"template.my-template": `
title: hello {{.app.metadata.name}}`,
message: hello {{.app.metadata.name}}`,
}

var stdout bytes.Buffer
Expand All @@ -95,7 +95,7 @@ func TestTriggerGet(t *testing.T) {
- when: 'false'
send: [my-template]`,
"template.my-template": `
title: hello {{.app.metadata.name}}`,
message: hello {{.app.metadata.name}}`,
}

var stdout bytes.Buffer
Expand Down
8 changes: 4 additions & 4 deletions docs/argocd-notifications-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ data:
# Templates are used to generate the notification template message
template.my-custom-template: |
title: Hello {{.app.metadata.name}}
body: |
message: |
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
# Templates might have notification service specific fields. E.g. slack message might include annotations
template.my-custom-template-slack-template: |
title: Application {{.app.metadata.name}} sync status is {{.app.status.sync.status}}
body: |
message: |
Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
email:
subject: Application {{.app.metadata.name}} sync status is {{.app.status.sync.status}}
slack:
attachments: |
[{
Expand Down
Loading

0 comments on commit 5586bb3

Please sign in to comment.