Skip to content

Commit

Permalink
Make is-installed script not exit on error (#2087)
Browse files Browse the repository at this point in the history
* add timeout option to is-installed script
* add info about the script
* do not immediately exit with code 1 on Error status
* add information about is-installed script to docs
* add default timeout to is-installed script on CI
* do not use echo and subshell to print output from kubectl
* move information about timeout below the logs from installer
* update codeowners
  • Loading branch information
kubadz committed Jan 8, 2019
1 parent 53c29eb commit 6ad8586
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -5,7 +5,7 @@
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.

# These are the default owners for the whole content of the `kyma` repository. The default owners are automatically added as reviewers when you open a pull request, unless different owners are specified in the file.
* @derberg @pbochynski @PK85 @a-thaler @lszymik
* @derberg @pbochynski @PK85 @a-thaler @lszymik @piotrmsc

/common/ @mszostok @aszecowka @piotrmiskiewicz @sjanota @Tomasz-Smelcerz-SAP @strekm @crabtree @akgalwas @janmedrek @Szymongib @sayanh @radufa @suleymanakbas91

Expand Down
2 changes: 1 addition & 1 deletion ci.Dockerfile
Expand Up @@ -59,7 +59,7 @@ RUN echo 'alias kc="kubectl"' >> ~/.bashrc
# minikube and docker start must be done on starting container to make it work
ENTRYPOINT /kyma/installation/scripts/docker-start.sh \
&& /kyma/installation/cmd/run.sh --vm-driver none \
&& /kyma/installation/scripts/is-installed.sh \
&& /kyma/installation/scripts/is-installed.sh --timeout 30m \
&& /kyma/installation/scripts/watch-pods.sh \
&& (($RUN_TESTS && /kyma/installation/scripts/testing.sh) || $IGNORE_TEST_FAIL) \
&& exec bash
4 changes: 4 additions & 0 deletions docs/kyma/docs/033-inst-local-installation-scripts.md
Expand Up @@ -76,3 +76,7 @@ The `installation/scripts/installer.sh` script creates the default RBAC role, in
The script applies the Installation custom resource and marks it with the `action=install` label, which triggers the Kyma installation.

>**NOTE:** The Kyma installation runs in the background. Execute the `./installation/scripts/is-installed.sh` script to follow the installation process.
## The is-installed.sh script

The `installation/scripts/is-installed.sh` script shows the status of Kyma installation in real time. The script checks the status of the Installation custom resource. When it detects that the status changed to `Installed`, the script exits. If you define a timeout period and the status doesn't change to `Installed` within that period, the script fetches the installer logs. If you don't set a timeout period, the script waits for the change of the status until you terminate it.
85 changes: 75 additions & 10 deletions installation/scripts/is-installed.sh
@@ -1,5 +1,47 @@
#!/bin/bash

#################################################################################
#
# Follow the process of Kyma installation
# Returns exit code 0 if Kyma is installed successfully
#
# Options:
# --verbose - reduce the delay between status checks; print the installation CR
# and status of all pods in every check
# --timeout - set the timeout after which the logs from installer will be printed
# and script will return exit code 1; the time accuracy depends on
# the delay between status checks; after the flag provide the time
# in the seconds (s/S), minutes (m/M) or hours (h/H) in the following
# format: <number_of_time_units><time_unit>
#
# Samples:
# bash is-installed.sh --timeout 25m
# bash is-installed.sh --verbose
#
#################################################################################

function parse_timeout {
TIME=$(echo "$TIMEOUT" | tr -dc '0-9')
UNIT=$(echo "$TIMEOUT" | tr -d '0-9' | tr -d ' ')

case "${UNIT}" in
"s"|"S") TIMEOUT=TIME ;;
"m"|"M") TIMEOUT=$(( TIME*60 )) ;;
"h"|"H") TIMEOUT=$(( TIME*3600 )) ;;
"")
echo "time unit not provided"
exit 1
;;
*)
echo "unknown time unit: ${UNIT}"
exit 1
;;
esac
}

TIMEOUT=""
TIMEOUT_SET=0
ITERATIONS_LEFT=0
VERBOSE=0
DELAY=10

Expand All @@ -14,6 +56,12 @@ do
DELAY=5
shift # past flag
;;
--timeout)
TIMEOUT_SET=1
TIMEOUT="$2"
shift # past flag
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
Expand All @@ -22,6 +70,11 @@ do
done
set -- "${POSITIONAL[@]}" # restore positional parameters

if [ "$TIMEOUT_SET" -ne 0 ]; then
parse_timeout
ITERATIONS_LEFT=$(( TIMEOUT/DELAY ))
fi

echo "Checking state of kyma installation...hold on"
while :
do
Expand All @@ -33,18 +86,30 @@ do
break
elif [ "$STATUS" = "Error" ]
then
echo "kyma installation error... ${DESC}"
echo "----------"
echo "$(kubectl logs -n kyma-installer $(kubectl get pods --all-namespaces -l name=kyma-installer --no-headers -o jsonpath='{.items[*].metadata.name}'))"
echo "----------"
exit 1
echo "kyma installation error, description: ${DESC}"
if [ "$TIMEOUT_SET" -eq 0 ]; then
echo "to fetch the logs from the installer execute: kubectl logs -n kyma-installer $(kubectl get pods --all-namespaces -l name=kyma-installer --no-headers -o jsonpath='{.items[*].metadata.name}')"
fi
if [ "$TIMEOUT_SET" -ne 0 ] && [ "$ITERATIONS_LEFT" -le 0 ]; then
echo "Fetching logs from the installer due to timeout:"
echo "----------"
kubectl logs -n kyma-installer $(kubectl get pods --all-namespaces -l name=kyma-installer --no-headers -o jsonpath='{.items[*].metadata.name}')
echo "----------"
echo "timeout reached on kyma installation error. Exiting"
exit 1
fi
else
echo "Status: ${STATUS}, description: ${DESC}"
if [ "${VERBOSE}" -eq 1 ]; then
echo "$(kubectl get installation/kyma-installation -o yaml)"
echo "----------"
echo "$(kubectl get po --all-namespaces)"
if [ "$TIMEOUT_SET" -ne 0 ] && [ "$ITERATIONS_LEFT" -le 0 ]; then
echo "timeout reached. Exiting"
exit 1
fi
sleep $DELAY
fi
if [ "${VERBOSE}" -eq 1 ]; then
kubectl get installation/kyma-installation -o yaml
echo "----------"
kubectl get po --all-namespaces
fi
sleep $DELAY
ITERATIONS_LEFT=$(( ITERATIONS_LEFT-1 ))
done
2 changes: 1 addition & 1 deletion prow/kyma-integration-on-debian/deploy-and-test-kyma.sh
Expand Up @@ -11,5 +11,5 @@ ROOT_DIR=${CURRENT_DIR}/../../

sudo ${CURRENT_DIR}/install-deps-debian.sh
sudo ${ROOT_DIR}/installation/cmd/run.sh --vm-driver "none"
sudo ${ROOT_DIR}/installation/scripts/is-installed.sh
sudo ${ROOT_DIR}/installation/scripts/is-installed.sh --timeout 30m
sudo ${ROOT_DIR}/installation/scripts/testing.sh

0 comments on commit 6ad8586

Please sign in to comment.