-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathaction.yml
78 lines (68 loc) · 2.88 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Submit & Delete K8s Job
description: Submit and delete a K8s job after its execution
inputs:
job-name:
description: The job name
required: true
job-config-file:
description: Path to the Kubernetes job YAML
required: true
runs:
using: "composite"
steps:
- name: Submit and Delete Kubernetes job
uses: ./.github/actions/with-post-step
with:
main: |
echo "Submit K8s job ${{ inputs.job-config-file }}"
kubectl apply -f "${{ inputs.job-config-file }}"
# Wait for job to be craeted
kubectl wait --for=create job/${{ inputs.job-name }} --timeout=60s
# Wait for job to be unsuspended
kubectl wait --for=jsonpath='{.spec.suspend}=false' job/${{ inputs.job-name }} --timeout=7200s
# Wait for pods to be running
kubectl wait --for=condition=Ready \
--selector=batch.kubernetes.io/job-name=${{ inputs.job-name }} \
--timeout=600s pod
# Stream logs
kubectl logs --all-containers=true --all-pods=true --follow job/${{ inputs.job-name }}
# Detect job parallelism
parallelism=$(kubectl get job/"${{ inputs.job-name }}" -o jsonpath='{.spec.parallelism}')
# if parallelism is not set, use default value of 1
if [ -z "${parallelism}" ]; then
echo "No parallelism specified, defaulting to 1"
parallelism=1
fi
# Check whether the job succeeded or failed
while IFS=: read -r failures successes; do
failures="${status[0]:-0}"
successes="${status[1]:-0}"
total=$((failures + successes))
if [ $total -lt $parallelism ]; then
# neither "failed" nor "succeeded", so wait
sleep 1
elif [ $total -eq $parallelism ]; then
# we have total=parallelism => either X successes or X failures
# In any case, the job is done
break
else
# Log here
echo "Unexpected number of completed pods ${total} with parallelism ${parallelism}"
exit 255
fi
done <<EOF
$(kubectl get job/"${{ inputs.job-name }}" -o 'jsonpath={.status.failed}:{.status.succeeded}')
EOF
# If job indicates a failure try to print out the info
if [ $failures -gt 0 ]; then
echo "Job ${{ inputs.job-name }} has $failures failures"
# this is for batch jobs only
pods=$(kubectl get pods --selector=batch.kubernetes.io/job-name=${{ inputs.job-name }} -o name)
if [ -n "${pods}" ]; then
kubectl describe ${pods}
fi
exit 1
fi
post: |
echo "Deleting K8s job: ${{ inputs.job-name }}"
kubectl delete -f "${{ inputs.job-config-file }}"