3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2023 Nordix Foundation.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
22 # @author Waqas Ikram (waqas.ikram@est.tech)
25 SUCCESSFUL_TEXT="Successfully created kind cluster"
26 FAILURE_TEXT="Failed creating kind cluster"
27 SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
28 SCRIPT_NAME=$(basename $0)
32 date +"%Y-%m-%d %H:%M:%S"
36 if [ -z "$TIME_OUT_DEFAULT_VALUE_SEC" ]; then
37 echo "$SCRIPT_NAME $(current_timestamp): ERROR: Undefined value for TIME_OUT_DEFAULT_VALUE_SEC attribute"
41 CONTAINER_NAME=$(docker ps -aqf "name=kind-cluster" --format "{{.Names}}")
42 if [ -z "$CONTAINER_NAME" ]; then
43 echo "$SCRIPT_NAME $(current_timestamp): Unable to find kind-cluster docker container id "
47 START_TIME_IN_SECONDS=`date +%s`
48 TIME_OUT_END_TIME_IN_SECONDS=$(($START_TIME_IN_SECONDS+$TIME_OUT_DEFAULT_VALUE_SEC));
51 echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME script Start Time `date -d @$START_TIME_IN_SECONDS`"
52 echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME will time out at `date -d @$TIME_OUT_END_TIME_IN_SECONDS`"
54 while [ `date +%s` -lt "$TIME_OUT_END_TIME_IN_SECONDS" ]; do
55 echo "$(current_timestamp): Waiting for $CONTAINER_NAME to finish ..."
57 result=$(docker logs "$CONTAINER_NAME" 2>&1 | grep -E "$SUCCESSFUL_TEXT|$FAILURE_TEXT")
58 if [ ! -z "$result" ]; then
59 echo "$SCRIPT_NAME $(current_timestamp): Found result: $result"
62 echo "$(current_timestamp): Sleeping for ${SLEEP_TIME} seconds"
66 if [ -z "$result" ] || echo "$result" | grep -E "$FAILURE_TEXT"; then
67 echo "$SCRIPT_NAME $(current_timestamp): ERROR: failed to create kind-cluster... "
68 echo "-------------- $CONTAINER_NAME logs -------------"
69 docker logs "$CONTAINER_NAME"
70 echo "------------------------------------------------------------"
74 echo "$SCRIPT_NAME $(current_timestamp): Finished successfully '$result'..."