-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdoc-process-status-task.yaml
More file actions
65 lines (52 loc) · 2.03 KB
/
doc-process-status-task.yaml
File metadata and controls
65 lines (52 loc) · 2.03 KB
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
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: doc-process-status
spec:
params:
- name: KFP_RUN_ID
description: Run ID of the Data Science Pipeline
type: string
steps:
- name: doc-process-status
image: quay.io/openshift/origin-cli:4.14
script: |
#!/bin/bash
LABEL="pipeline/runid=$(params.KFP_RUN_ID)"
LOG_FILE="/tekton/results/pod-logs.txt"
echo "Waiting for the system-container-impl pod with label $LABEL to start running...🥱"
while true; do
POD_NAME=$(oc get pods -l $LABEL -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | grep "system-container-impl")
if [[ -n "$POD_NAME" ]]; then
POD_STATUS=$(oc get pod "$POD_NAME" -o jsonpath='{.status.phase}' )
if [[ "$POD_STATUS" == "Running" ]]; then
echo "Pod $POD_NAME is now Running. Starting log streaming...💪"
break
fi
fi
echo "Waiting for the pod to start...🥱"
sleep 5
done
# Start `oc logs -f` in the background and redirect output to stdout
oc logs -f "$POD_NAME" | grep --line-buffered -A2 PROCESSING 2>&1 &
# Wait until the pod reaches Succeeded (or Failed)
while true; do
POD_STATUS=$(oc get pod "$POD_NAME" -o jsonpath='{.status.phase}' )
if [[ "$POD_STATUS" != "Running" ]]; then
echo "🙅♀️ Pod $POD_NAME is not running anymore. Stopping log streaming..."
break
fi
sleep 5
done
# Show the last 10 log lines
echo "🤓 Fetching the last 1 minute logs before exit:"
oc logs "$POD_NAME" --since=1m
# Exit based on final pod status
if [[ "$POD_STATUS" == "Succeeded" ]]; then
echo "💚 Pod completed successfully. Exiting with success."
exit 0
else
echo "💔 Pod failed. Exiting with failure."
exit 1
fi