-
Notifications
You must be signed in to change notification settings - Fork 33
/
setup_gke_filestore.sh
executable file
·227 lines (205 loc) · 6.38 KB
/
setup_gke_filestore.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
GCLOUD_PROJECT=
GCLOUD_ZONE=
CLUSTER_NAME=
NAMESPACE=default
BACKUP_VALUES="${SCRIPT_DIR}/backup_values.yaml"
SOLR_BACKUP_NFS_GB=1024
RELEASE=
function print_usage() {
ERROR_MSG="$2"
if [ "$ERROR_MSG" != "" ]; then
echo -e "\nERROR: $ERROR_MSG\n"
fi
echo -e " -c Name of the GKE cluster (required)\n"
echo -e " -p GCP Project ID (required)\n"
echo -e " -r Helm release name for installing Fusion 5; defaults to the namespace, see -n option\n"
echo -e " -n Kubernetes namespace to install Fusion 5 into, defaults to 'default'\n"
echo -e " --zone GCP Zone to create filestore in \n"
echo -e " --backup-values-file The name of the values file to write backup values to"
echo -e " --solr-backup-fs-gb Size (in gigabytes) of the GCP Fileshare for solr backups, defaults to ${SOLR_BACKUP_NFS_GB}\n"
}
if [ $# -gt 0 ]; then
while true; do
case "$1" in
-c)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -c parameter!"
exit 1
fi
CLUSTER_NAME="$2"
shift 2
;;
-n)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -n parameter!"
exit 1
fi
NAMESPACE="$2"
shift 2
;;
-p)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -p parameter!"
exit 1
fi
GCLOUD_PROJECT="$2"
shift 2
;;
-r)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -r parameter!"
exit 1
fi
RELEASE="$2"
shift 2
;;
--zone)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --zone!"
exit 1
fi
GCLOUD_ZONE=$2
shift 2
;;
--solr-backup-fs-gb)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --solr-backup-fs-gb parameter!"
exit 1
fi
SOLR_BACKUP_NFS_GB=$2
shift 2
;;
--backup-values-file)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --backup-values-file parameter!"
exit 1
fi
BACKUP_VALUES=$2
shift 2
;;
-z)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -z parameter!"
exit 1
fi
GCLOUD_ZONE="$2"
shift 2
;;
-help|-usage|--help|--usage)
print_usage "$SCRIPT_CMD"
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
if [ -z "${GCLOUD_ZONE}" ]; then
print_usage "$SCRIPT_CMD" "--zone parameter must be specified"
exit 1
fi
if [ -z "${NAMESPACE}" ]; then
print_usage "$SCRIPT_CMD" "-n parameter must be specified"
exit 1
fi
if [ -z "${RELEASE}" ]; then
RELEASE="${NAMESPACE}"
fi
if [ -z "${CLUSTER_NAME}" ]; then
print_usage "$SCRIPT_CMD" "-c parameter must be specified"
exit 1
fi
if [ -z "${GCLOUD_PROJECT}" ]; then
print_usage "$SCRIPT_CMD" "-p parameter must be specified"
exit 1
fi
NFS_NAME="${CLUSTER_NAME}-${NAMESPACE}-${RELEASE}"
NFS_NAME="${NFS_NAME//_/-}"
if [ -z "${GCLOUD_ZONE}" ]; then
echo "--zone parameter must be specified"
exit 1
fi
if ! gcloud --project "${GCLOUD_PROJECT}" filestore instances list --filter="${NFS_NAME}" | grep "${NFS_NAME}" > /dev/null 2>&1; then
echo -e "\n Creating GCP filestore instance with name: '${NFS_NAME}' in zone: '${GCLOUD_ZONE}'"
gcloud --project "${GCLOUD_PROJECT}" filestore instances create "${NFS_NAME}" \
--tier=STANDARD \
--file-share=name="solrbackups,capacity=${SOLR_BACKUP_NFS_GB}GB" \
--zone="${GCLOUD_ZONE}" \
--network=name="default"
fi
NFS_IP="$(gcloud filestore instances describe "${NFS_NAME}" \
--project="${GCLOUD_PROJECT}" \
--zone="${GCLOUD_ZONE}" \
--format="value(networks.ipAddresses[0])")"
# need to create the namespace if it doesn't exist yet
if ! kubectl get namespace "${NAMESPACE}" > /dev/null 2>&1; then
if [ "${UPGRADE}" != "1" ]; then
kubectl create namespace "${NAMESPACE}"
kubectl label namespace "${NAMESPACE}" "owner=${OWNER_LABEL}"
echo -e "\nCreated namespace ${NAMESPACE} with owner label ${OWNER_LABEL}\n"
fi
fi
cat <<EOF | kubectl -n "${NAMESPACE}" apply -f -
apiVersion: v1
kind: PersistentVolume
metadata:
name: ${NAMESPACE}-solr-backups
annotations:
pv.beta.kubernetes.io/gid: "8983"
spec:
capacity:
storage: ${SOLR_BACKUP_NFS_GB}G
accessModes:
- ReadWriteMany
nfs:
path: /solrbackups
server: ${NFS_IP}
EOF
cat <<EOF | kubectl -n "${NAMESPACE}" apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "fusion-solr-backup-claim"
spec:
volumeName: ${NAMESPACE}-solr-backups
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: ${SOLR_BACKUP_NFS_GB}G
EOF
tee "${BACKUP_VALUES}" << END
solr-backup-runner:
enabled: true
sharedPersistentVolumeName: "fusion-solr-backup-claim"
solr:
additionalInitContainers:
- name: chown-backup-directory
securityContext:
runAsUser: 0
image: busybox:latest
command: ['/bin/sh', '-c', "owner=\$(stat -c '%u' /mnt/solr-backups); if [ ! \"\${owner}\" = \"8983\" ]; then chown -R 8983:8983 /mnt/solr-backups; fi "]
volumeMounts:
- mountPath: /mnt/solr-backups
name: solr-backups
additionalVolumes:
- name: solr-backups
persistentVolumeClaim:
claimName: fusion-solr-backup-claim
additionalVolumeMounts:
- name: solr-backups
mountPath: "/mnt/solr-backups"
END