-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.sh
executable file
·102 lines (91 loc) · 3.04 KB
/
init.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
100
101
102
#!/bin/bash
if ! minikube status | grep "cluster: Running"; then
echo "[$(date)][INFO] Starting minikube"
minikube start
else
echo "[$(date)][INFO] Minikube running."
fi
echo "[$(date)][INFO] Checking for container image presence."
eval "$(minikube docker-env)"
if [ "$(docker images sshd-gateway -q)" == "" ]; then
echo "[$(date)][INFO] Building sshd-gateway container."
docker build -t sshd-gateway -f ./Dockerfile.sshd .
else
echo "[$(date)][INFO] sshd-gateway image found."
fi
if [ "$(docker images centos-sudo -q)" == "" ]; then
echo "[$(date)][INFO] Building centos-sudo container."
docker build -t centos-sudo -f ./Dockerfile.sudo .
else
echo "[$(date)][INFO] Centos-sudo image found."
fi
if [ "$(docker images ubuntu-ip -q)" == "" ]; then
echo "[$(date)][INFO] Building ubuntu-ip container."
docker build -t ubuntu-ip -f ./Dockerfile.iputil .
else
echo "[$(date)][INFO] ubuntu-ip image found."
fi
eval "$(minikube docker-env -u)"
echo "[$(date)][INFO] Labeling namespace"
kubectl label ns default --overwrite=true session=true
echo "[$(date)][INFO] Creating/Updating configs and secrets..."
config_items=(
config-idm
config-sshd
script-session-gateway
script-session-host
template-session-host
)
config_types=(
config
config
script
script
template
)
config_length=${#config_items[@]}
for (( i=0; i<${config_length}; i++ )); do
if ! kubectl get cm "${config_items[$i]}" > /dev/null 2>&1; then
kubectl create cm "${config_items[$i]}" --from-file="${config_items[$i]}/"
else
kubectl create --dry-run cm "${config_items[$i]}" -o yaml \
--from-file="${config_items[$i]}/" | kubectl replace -f -
fi
kubectl label cm "${config_items[$i]}" type="${config_types[$i]}"
done
secret_items=(
config-idm-shadow
config-sshd-host-keys
)
secret_types=(
config
config
)
secret_length=${#secret_items[@]}
for (( i=0; i<${secret_length}; i++ )); do
if ! kubectl get secret "${secret_items[$i]}" > /dev/null 2>&1; then
kubectl create secret generic "${secret_items[$i]}" --from-file="secret-${secret_items[$i]}/"
else
kubectl create secret generic "${secret_items[$i]}" --dry-run -o yaml \
--from-file="secret-${secret_items[$i]}/" | kubectl replace -f -
fi
kubectl label secret "${secret_items[$i]}" type="${secret_types[$i]}"
done
echo "[$(date)][INFO] Creating User Home NFS Server"
kubectl apply -f nfs-provisioner/
while [ "$(kubectl get deploy nfs-provisioner --no-headers=true | awk '{print $5}')" != "1" ]; do
echo "[$(date)][INFO] Waiting for NFS Server to become ready."
sleep 5
done
echo "[$(date)][INFO] Creating/Updating Users.."
kubectl apply -f users/
echo "[$(date)][INFO] Creating Home PVC"
kubectl apply -f pvc-home.yaml
echo "[$(date)][INFO] Preparing User Home"
kubectl apply -f job-create-user-home.yaml
while [ "$(kubectl get job create-user-home --no-headers=true | awk '{print $3}')" != "1" ]; do
echo "[$(date)][INFO] Waiting for user home directories to be created."
sleep 5
done
echo "[$(date)][INFO] Deploying session-gateway"
kubectl apply -f session-gateway/