-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·54 lines (50 loc) · 1.39 KB
/
entrypoint.sh
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
#!/bin/sh -l
sleep 10
DOWNLOAD_ID=$(cat /proc/sys/kernel/random/uuid)
DOWNLOAD_NAME=download-pv-job-$DOWNLOAD_ID
mkdir -p ~/.kube
echo $1 | base64 -d > ~/.kube/config
echo "Applied kubeConfig"
kubectl version
cat <<EOF | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: $DOWNLOAD_NAME
labels:
app: k8s-download
spec:
template:
spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: $2
restartPolicy: Never
containers:
- name: download-pv
image: alpine:latest
command: ['/bin/sh']
args:
['-c', 'sleep 140s']
volumeMounts:
- name: data
mountPath: /data
EOF
sleep 5
echo "SourcePath:/data/"$3
echo "OutputPath:"$PWD/$4
kubectl wait --for=condition=ready pod -l job-name=$DOWNLOAD_NAME --timeout=$5s
kubectl exec jobs/$DOWNLOAD_NAME -- ls /data/$3
kubectl exec jobs/$DOWNLOAD_NAME -- apk update
kubectl exec jobs/$DOWNLOAD_NAME -- apk add zip
kubectl exec jobs/$DOWNLOAD_NAME -- mv /data/$3 /output
kubectl exec jobs/$DOWNLOAD_NAME -- zip -r output.zip /output
kubectl exec jobs/$DOWNLOAD_NAME -- stat output.zip
pods=$(kubectl get pods --selector=job-name=$DOWNLOAD_NAME --output=jsonpath='{.items[*].metadata.name}')
kubectl cp $pods:output.zip $PWD/output.zip
unzip $PWD/output.zip -d $PWD/$4
rm output.zip
mv $PWD/$4/output/* $PWD/$4
ls
kubectl delete jobs/$DOWNLOAD_NAME