forked from chipster/chipster-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp-shell.bash
87 lines (72 loc) · 2.48 KB
/
comp-shell.bash
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
79
80
81
82
83
84
85
86
87
#!/bin/bash
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ $# -gt 2 ]; then
echo "Open shell in container image"
echo "Usage: $0 [--local-image] [IMAGE]"
exit 0
fi
image_repo="docker-registry.rahti.csc.fi/chipster-images-release/"
image_pull_policy="IfNotPresent"
if [[ $1 == "--local-image" ]]; then
image_pull_policy="Never"
shift
fi
image=${1:-comp-20-04-r-deps}
name="comp-shell"
if ! kubectl get pod | grep $name | grep Running > /dev/null 2>&1; then
deployment=$(cat << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: $name
spec:
replicas: 1
selector:
matchLabels:
app: $name
template:
metadata:
labels:
app: $name
spec:
containers:
- name: $name
volumeMounts: []
volumes: []
EOF
)
echo "image: ${image_repo}${image}"
patch=".spec.template.spec.containers[0].image = \"${image_repo}${image}\" |
.spec.template.spec.containers[0].imagePullPolicy = \"${image_pull_policy}\""
TOOLS_BIN_NAME=$(cat ~/values.yaml | yq e - -o json | jq .toolsBin.version -r)
TOOLS_BIN_HOST_MOUNT_PATH=$(cat ~/values.yaml | yq e - -o json | jq .toolsBin.hostPath -r)
TOOLS_BIN_PATH="/opt/chipster/tools"
if [[ $TOOLS_BIN_NAME != "null" ]]; then
patch="$patch |
.spec.template.spec.containers[0].volumeMounts += [{\"name\": \"tools-bin\", \"readOnly\": false, \"mountPath\": \"$TOOLS_BIN_PATH\"}]"
if [[ $TOOLS_BIN_HOST_MOUNT_PATH != "null" ]]; then
echo "mount tools-bin from hostPath $TOOLS_BIN_HOST_MOUNT_PATH/$TOOLS_BIN_NAME to $TOOLS_BIN_PATH"
patch="$patch |
.spec.template.spec.volumes += [{\"name\": \"tools-bin\", \"hostPath\": { \"path\": \"$TOOLS_BIN_HOST_MOUNT_PATH/$TOOLS_BIN_NAME\", \"type\": \"Directory\"}}]"
else
echo "mount tools-bin from PVC $TOOLS_BIN_NAME to $TOOLS_BIN_PATH"
patch="$patch |
.spec.template.spec.volumes += [{\"name\": \"tools-bin\", \"persistentVolumeClaim\": { \"claimName\": \"tools-bin-$TOOLS_BIN_NAME\"}}]"
fi
else
echo "do not mount tools-bin"
fi
json=$(echo "$deployment" | yq e - -o=json | jq "$patch")
echo "$json" | kubectl apply -f -
echo "waiting pod to start"
for i in $(seq 30); do
if kubectl get pod 2> /dev/null | grep $name | grep Running > /dev/null; then
echo ""
break
fi
printf "."
sleep 1
done
fi
echo "comp shell, press Ctrl+D to exit"
kubectl exec -it $(kubectl get pod | grep $name | grep Running | cut -d " " -f 1) -- bash
kubectl delete deployment $name