Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 7172ef0

Browse files
committed
- Implemented kubernetes cluster readiness check via polling during project initialization
1 parent 80c16d4 commit 7172ef0

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

init_project.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ if [[ $(isMinikubeRunning) -eq 0 ]]; then
227227
status "Starting minikube"
228228
#echo "$(python -c 'import os,sys;print(os.path.realpath("."));')/ -alldirs -mapall="$(id -u)":"$(id -g)" $(minikube ip)" | sudo tee -a /etc/exports && sudo nfsd restart
229229
minikube start --cpus=2 --memory=4096
230+
# minikube start --cache-images --cpus=2 --memory=4096
230231
# hanged in some cases todo
231232
# minikube start --cpus=2 --memory=4096 2> >(logError) | {
232233
# while IFS= read -r line
@@ -239,15 +240,16 @@ if [[ $(isMinikubeRunning) -eq 0 ]]; then
239240
fi
240241
status "Configuring kubernetes cluster on the minikube"
241242
# TODO: Optimize. Helm tiller must be initialized and started before environment configuration can begin
242-
helm init && sleep 10
243+
helm init
244+
waitForKubernetesPodToRun 'tiller-deploy'
245+
243246
# TODO: change k-rebuild-environment to comply with formatting requirements
244247
if [[ "${disable_nfs}" == 1 ]]; then
245248
bash "${vagrant_dir}/scripts/host/k_rebuild_environment.sh" -d
246249
else
247250
bash "${vagrant_dir}/scripts/host/k_rebuild_environment.sh"
248251
fi
249252

250-
251253
minikube_ip="$(minikube service magento2-monolith --url | grep -oE '[0-9][^:]+' | head -1)"
252254
status "Saving minikube IP to etc/config.yaml (${minikube_ip})"
253255
sed -i.back "s|ip_address: \".*\"|ip_address: \"${minikube_ip}\"|g" "${config_path}"

k-restart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD
77
source "${vagrant_dir}/scripts/functions.sh"
88
resetNestingLevel
99

10-
if [[ $(isMinikubeRunning) -eq 1 ]]; then
10+
if [[ $(isMinikubeRunning) -eq 1 || $(isMinikubeSaved) -eq 1 ]]; then
1111
minikube stop 2> >(logError)
1212
fi
1313

1414
minikube start --cpus=2 --memory=4096 2> >(logError)
15+
#minikube start --cache-images --cpus=2 --memory=4096 2> >(logError)
1516

1617
info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)"

scripts/functions.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,41 @@ function isMinikubeStopped() {
227227
fi
228228
}
229229

230+
function isMinikubeSaved() {
231+
minikube_status="$(minikube status | grep minikube: 2> >(log))"
232+
if [[ ${minikube_status} == "minikube: Saved" ]]; then
233+
echo 1
234+
fi
235+
}
236+
230237
# TODO: Add suspended
231238

232239
function isMinikubeInitialized() {
233-
if [[ $(isMinikubeRunning) -eq 1 || $(isMinikubeStopped) -eq 1 ]]; then
240+
if [[ $(isMinikubeRunning) -eq 1 || $(isMinikubeStopped) -eq 1 || $(isMinikubeSaved) -eq 1 ]]; then
234241
echo 1
235242
fi
236243
}
244+
245+
function waitForKubernetesPodToRun()
246+
{
247+
set +e
248+
249+
if [[ -n "${1}" ]]; then
250+
pod_id="${1}"
251+
else
252+
error "Argument missing for 'waitForKubernetesPodToRun'"
253+
set -e
254+
exit 1
255+
fi
256+
257+
COUNTER=0
258+
pod_status=$(kubectl get pods --all-namespaces | grep -hE "${pod_id}-[a-z0-9\-]+" | grep -o 'Running')
259+
260+
while [[ $pod_status != 'Running' && $COUNTER -lt 240 ]] ; do
261+
sleep 3
262+
let COUNTER+=3
263+
status "Waiting for pod (${pod_id}) to run"
264+
pod_status=$(kubectl get pods --all-namespaces | grep -hE "${pod_id}-[a-z0-9\-]+" | grep -o 'Running')
265+
done
266+
set -e
267+
}

scripts/guest/m-reinstall

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ if [[ ${magento_home_page_content} =~ ${pattern} ]]; then
134134

135135
bash "${VAGRANT_ROOT}/scripts/guest/warm_up_cache"
136136

137-
status "Generating XSD references for PHP Storm"
138-
php "${MAGENTO_ROOT}/bin/magento" dev:urn-catalog:generate "${vagrant_dir}/.idea/misc.xml"
139-
sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "${vagrant_dir}/.idea/misc.xml"
137+
status "Generating XSD references for PHP Storm in the background"
138+
php "${MAGENTO_ROOT}/bin/magento" dev:urn-catalog:generate "${vagrant_dir}/.idea/misc.xml" && sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "${vagrant_dir}/.idea/misc.xml" &
140139

141140
decrementNestingLevel
142141
success "Magento reinstalled successfully"

scripts/host/k_rebuild_environment.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ cd "${vagrant_dir}/etc/helm" && helm install \
3535
--set global.checkout.volumeHostPath="${vagrant_dir}" .
3636

3737
# TODO: Waiting for containers to initialize before proceeding
38-
sleep 7
39-
40-
41-
## Bypass Helm
42-
#cd "${vagrant_dir}" && python local_deploy.py --all --ingress \
43-
# && kubectl patch deployment magento2-monolith -p \
44-
# "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
38+
waitForKubernetesPodToRun 'magento2-monolith'
39+
waitForKubernetesPodToRun 'magento2-mysql'
40+
waitForKubernetesPodToRun 'magento2-redis-master'
4541

4642
exit 0

0 commit comments

Comments
 (0)