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: add slack notification onExit TDE-842 #162

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions workflows/util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ graph TD;
create-thumbnails-->publish-thumbnails;
```

Note: `#alert-argo-workflows` Slack channel is notified once the workflow is completed.

### [aws-list](https://github.com/linz/argo-tasks/blob/master/src/commands/list/list.ts)

Recursively loops through the provided source path and lists all the files within this location. Some listing parameters are currently hard-coded due to the current bespoke purpose of this workflow:
Expand Down
79 changes: 79 additions & 0 deletions workflows/util/create-thumbnails.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
nodeSelector:
karpenter.sh/capacity-type: "spot"
entrypoint: main
onExit: exit-handler
arguments:
parameters:
# FIXME: Should use camelCase or underscore?
Expand Down Expand Up @@ -117,6 +118,12 @@ spec:
artifacts:
- name: files
path: /tmp/file_list.json
outputs:
parameters:
- name: count
globalName: count
valueFrom:
path: /tmp/thumbnails/count
container:
image: "019359803926.dkr.ecr.ap-southeast-2.amazonaws.com/eks:topo-imagery-{{=sprig.trim(workflow.parameters['version-topo-imagery'])}}"
resources:
Expand Down Expand Up @@ -151,6 +158,78 @@ spec:
valueFrom:
path: "/tmp/location"

- name: exit-handler
steps:
- - name: notify
template: notify-slack
when: "{{workflow.status}} == Succeeded"

- name: notify-slack
inputs:
parameters:
- name: count
value: "{{workflow.outputs.parameters.count}}"
script:
image: "019359803926.dkr.ecr.ap-southeast-2.amazonaws.com/eks:argo-tasks-{{=sprig.trim(workflow.parameters['version-argo-tasks'])}}"
env:
- name: PARAMS
value: "{{workflow.parameters}}"
- name: WEBHOOK
valueFrom:
secretKeyRef:
name: slack-linz-webhook # name of the secret that stores linz Slack webhook
key: url # the Slack Webhook URL is stored as `url`
command: [node]
source: |
const slackWebhook = process.env.WEBHOOK
const params = JSON.parse(process.env.PARAMS);

var paramFields = []
params.forEach((param) => paramFields.push({type: "mrkdwn", text: "*" + param.name + ":*\n " + param.value}));

const payload = {
icon_url: "https://cncf-branding.netlify.app/img/projects/argo/icon/color/argo-icon-color.png",
username: "Argo Workflows [bot]",
channel: "#alert-argo-workflows",
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: ":frame_with_picture: Thumbnails Created",
emoji: true
}
},
{
type: "section",
text: {
type: "mrkdwn",
text: "{{inputs.parameters.count}} files have been generated."
}
},
{
type: "section",
fields: paramFields
},
],
};

fetch(slackWebhook, {
method: "POST",
body: JSON.stringify(payload),
headers: {
"Content-Type": "application/json; charset=utf-8",
"Content-Length": JSON.stringify(payload).length,
Accept: "application/json",
},
})
.then((res) => {
console.log(res);
})
.catch((error) => {
console.log(error);
});

volumes:
- name: ephemeral
emptyDir: {}