Skip to content

Commit

Permalink
fix: roberta self-test was not base64-decoding slack secrets
Browse files Browse the repository at this point in the history
Also not the correct channel field in the payload.
This PR adds some helpers, resume.sh and suspend.sh, on the periodic task.
  • Loading branch information
starpit committed Aug 30, 2022
1 parent 2c42713 commit 3f3fad0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
16 changes: 6 additions & 10 deletions deploy/self-test/roberta/1gpu/once.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,28 @@ spec:
serviceAccountName: codeflare-self-test-serviceaccount
containers:
- name: self-test
image: ghcr.io/project-codeflare/codeflare-self-test:0.11.0
image: ghcr.io/project-codeflare/codeflare-self-test:0.11.1
env:
# - name: GUIDEBOOK_RUN_ARGS
# value: "-V"
- name: VARIANTS
value: roberta-1gpu
- name: SLACK_TEAMID
- name: SLACK_URL
valueFrom:
secretKeyRef:
name: codeflare-self-test-slack
key: TEAMID
- name: SLACK_CHANNELID
key: URL
- name: SLACK_CHANNEL
valueFrom:
secretKeyRef:
name: codeflare-self-test-slack
key: CHANNELID
- name: SLACK_TOKEN
valueFrom:
secretKeyRef:
name: codeflare-self-test-slack
key: TOKEN
key: CHANNEL
- name: SLACK_USERNAME
valueFrom:
secretKeyRef:
name: codeflare-self-test-slack
key: USERNAME
optional: true
- name: ML_CODEFLARE_ROBERTA_GITHUB_USER
valueFrom:
secretKeyRef:
Expand Down
11 changes: 6 additions & 5 deletions deploy/self-test/roberta/1gpu/periodic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ spec:
serviceAccountName: codeflare-self-test-serviceaccount
containers:
- name: self-test
image: ghcr.io/project-codeflare/codeflare-self-test:0.11.0
image: ghcr.io/project-codeflare/codeflare-self-test:0.11.1
env:
# - name: GUIDEBOOK_RUN_ARGS
# value: "-V"
- name: VARIANTS
value: roberta-1gpu
- name: SLACK_TEAMID
- name: SLACK_URL
valueFrom:
secretKeyRef:
name: codeflare-self-test-slack
key: TEAMID
- name: SLACK_CHANNELID
key: URL
- name: SLACK_CHANNEL
valueFrom:
secretKeyRef:
name: codeflare-self-test-slack
key: CHANNELID
key: CHANNEL
- name: SLACK_TOKEN
valueFrom:
secretKeyRef:
Expand All @@ -79,6 +79,7 @@ spec:
secretKeyRef:
name: codeflare-self-test-slack
key: USERNAME
optional: true
- name: ML_CODEFLARE_ROBERTA_GITHUB_USER
valueFrom:
secretKeyRef:
Expand Down
5 changes: 5 additions & 0 deletions deploy/self-test/roberta/1gpu/resume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Resumes the `periodic` cronjob.
#

kubectl patch cronjobs codeflare-self-test-roberta-1gpu-periodic -p '{"spec" : {"suspend" : false }}'
6 changes: 6 additions & 0 deletions deploy/self-test/roberta/1gpu/suspend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Suspends the `periodic` cronjob. This is useful if you want to sneak
# in a `once` run for debugging.
#

kubectl patch cronjobs codeflare-self-test-roberta-1gpu-periodic -p '{"spec" : {"suspend" : true }}'
20 changes: 13 additions & 7 deletions deploy/self-test/self-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ echo "Using these variants: $variants"
function cleanup {
STATUS=$?

TEAMID=$SLACK_TEAMID
CHANNELID=$SLACK_CHANNELID
TOKEN=$SLACK_TOKEN
USERNAME=${SLACK_USERNAME-"Self-test Bot"}

if [ -n "$TEAMID" ] && [ -n "$CHANNELID" ] && [ -n "$TOKEN" ]; then
if [ -n "$SLACK_URL" ] && [ -n "$SLACK_CHANNEL" ]; then
if [ "$STATUS" = "0" ]; then
ICON=":green_heart:"
TEXT="$(date)\nSuccessful run\nVariants: $variants"
Expand All @@ -35,10 +30,21 @@ function cleanup {
# TODO, add tee'd logs of failing run
fi

URL=$(echo $SLACK_URL | base64 -d)
CHANNEL=$(echo $SLACK_CHANNEL | base64 -d)

if [ -n "$SLACK_USERNAME" ]; then
USERNAME=$(echo $SLACK_USERNAME | base64 -d)
else
USERNAME="Self-test Bot"
fi

echo "Posting to slack status=$STATUS to $URL"
curl -X POST \
--data-urlencode "payload={\"channel\": \"#$CHANNEL\", \"username\": \"$USERNAME\", \"text\": \"$TEXT\", \"icon_emoji\": \"$ICON\"}" \
https://hooks.slack.com/services/$TEAMID/$CHANNELID/$TOKEN
$URL
else
echo "Skipping post to slack url?=${#SLACK_URL} channel?=${#SLACK_CHANNEL}"
fi
}

Expand Down
6 changes: 3 additions & 3 deletions docs/self-test/roberta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export SLACK_TOKEN=mytoken

```shell
kubectl create secret generic codeflare-self-test-slack \
--from-literal=TEAMID=$(echo -n SLACK_TEAMID | base64) \
--from-literal=CHANNELID=$(echo -n SLACK_CHANNELID | base64) \
--from-literal=TOKEN=$(echo -n SLACK_TOKEN | base64)
--from-literal=TEAMID=$(echo -n $SLACK_TEAMID | base64) \
--from-literal=CHANNELID=$(echo -n $SLACK_CHANNELID | base64) \
--from-literal=TOKEN=$(echo -n $SLACK_TOKEN | base64)
```

### Deploy the automation
Expand Down

0 comments on commit 3f3fad0

Please sign in to comment.