forked from lintol/helm-ckan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathk8s-paster
More file actions
executable file
·65 lines (52 loc) · 1.31 KB
/
k8s-paster
File metadata and controls
executable file
·65 lines (52 loc) · 1.31 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
65
#!/bin/sh
if [ "$1" = "" ]
then
echo "Must have chart name as first paster argument"
exit 1
fi
if [ "$2" = "" ]
then
echo "Must have values file as second paster argument"
exit 1
fi
RELEASE=$1
VALUES=$2
shift
shift
if [ "$*" = "" ]
then
echo "Must have paster commands (use /etc/ckan/production.ini for config)"
exit 1
fi
JOBNAME=$RELEASE-paster-job-$(date '+%s')
PASTERCOMMAND=$@
kubectl delete job --selector="job=ckan-paster-job" --ignore-not-found
helm template -n srv-ckan . --values $VALUES --set "jobName=$JOBNAME,runningJob=1,pasterCommand=$PASTERCOMMAND" -x templates/job.yaml | kubectl create -f -
getJob() {
kubectl get jobs $JOBNAME --output=jsonpath="{range .items[*]}{.metadata.name}{end}"
}
getPrePod () {
kubectl get pods --selector="job-name=$JOBNAME" --field-selector="status.phase=Pending" --output=jsonpath="{range .items[*]}{.metadata.name}{end}"
}
getPod () {
kubectl get pods --selector="job-name=$JOBNAME" --field-selector="status.phase=Running" --output=jsonpath="{range .items[*]}{.metadata.name}{end}"
}
cleanup () {
POD="$(getPod $JOBNAME)"
if [ "$POD" != "" ]
then
kubectl delete job $JOBNAME
fi
exit 2
}
sleep 1
while [ "$(getPrePod $JOBNAME)" != "" ]
do
echo "[waiting...]"
sleep 0.5
done
trap "cleanup" 2
if [ "$(getPod $JOBNAME)" != "" ]
then
kubectl logs -f $(getPod $JOBNAME)
fi