-
Notifications
You must be signed in to change notification settings - Fork 6
/
run_backpack.sh
executable file
·99 lines (86 loc) · 2.74 KB
/
run_backpack.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
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
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
###
# Default settings
###
CLEANUP=true
PRIVILEGED=false
NAMESPACE=backpack
UUID=`uuidgen`
LABEL_NAME=""
LABEL_VALUE=""
ES_SSL=False
IMAGE="quay.io/cloud-bulldozer/backpack:latest"
while getopts s:n:xa:t:c:u:l:v:i:h flag
do
case "${flag}" in
s) ES_SERVER=${OPTARG};;
n) NAMESPACE=${OPTARG};;
x) PRIVILEGED=true;;
c) CLEANUP=${OPTARG};;
u) UUID=${OPTARG};;
l) LABEL_NAME=${OPTARG};;
v) LABEL_VALUE=${OPTARG};;
i) IMAGE=${OPTARG};;
a) ES_SSL=${OPTARG};;
h) echo "Usage: run_backpack.sh [-s ELASTICSEARCH_SERVER] [-c true|false] [-n NAMESPACE] [-x] [-u UUID] [-l LABEL_NAME] [-v LABEL_VALUE] [-i IMAGE] [-a True|False]" ; exit ;;
?) echo "Usage: run_backpack.sh [-s ELASTICSEARCH_SERVER] [-c true|false] [-n NAMESPACE] [-x] [-u UUID] [-l LABEL_NAME] [-v LABEL_VALUE] [-i IMAGE] [-a True|False]" ; exit 1 ;;
esac
done
echo "Running Backpack with the following options"
echo "ES Server: "$ES_SERVER
echo "SSL Enabled: "$ES_SSL
echo "Namespace: "$NAMESPACE
echo "Privileged: "$PRIVILEGED
echo "Cleanup: "$CLEANUP
echo "UUID: "$UUID
cp backpack_daemonset.yml backpack_$UUID.yml
sed -i "s/{UUID}/$UUID/g" backpack_$UUID.yml
sed -i "s/{NAMESPACE}/$NAMESPACE/g" backpack_$UUID.yml
sed -i "s?{ELASTICSEARCH_SERVER}?-s $ES_SERVER?g" backpack_$UUID.yml
sed -i "s/{PRIV}/$PRIVILEGED/g" backpack_$UUID.yml
sed -i "s?{IMAGE}?$IMAGE?g" backpack_$UUID.yml
sed -i "s?{ES_SSL}?$ES_SSL?g" backpack_$UUID.yml
kubectl create namespace $NAMESPACE
if [[ $PRIVILEGED == "true" ]]
then
sed -i "s/{ACCOUNT}/backpack-view/g" backpack_$UUID.yml
cp backpack_role.yaml backpack_role_$UUID.yaml
sed -i "s/{NAMESPACE}/$NAMESPACE/g" backpack_role_$UUID.yaml
kubectl apply -f backpack_role_$UUID.yaml
if [[ `command -v oc` ]]
then
if [[ `oc get securitycontextconstraints.security.openshift.io` ]]
then
oc adm policy -n $NAMESPACE add-scc-to-user privileged -z backpack-view
fi
fi
else
sed -i "s/{ACCOUNT}/default/g" backpack_$UUID.yml
fi
if [[ $LABEL_NAME != "" && $LABEL_VALUE != "" ]]
then
cat <<EOT >> backpack_$UUID.yml
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: $LABEL_NAME
operator: In
values:
- $LABEL_VALUE
EOT
fi
kubectl apply -f backpack_$UUID.yml
while [[ `kubectl -n $NAMESPACE get pods -l=name=backpack-$UUID -o jsonpath='{range .items[*]}{.status.containerStatuses[*].ready}{"\n"}{end}' | grep false` ]]
do
sleep 15
done
if [[ $CLEANUP == "true" ]]
then
if [[ $ACCOUNT == "true" ]]
then
kubectl delete -f backpack_role_$UUID.yaml
fi
kubectl delete -f backpack_$UUID.yml
fi