diff --git a/kubernetes/samples/scripts/common/utility.sh b/kubernetes/samples/scripts/common/utility.sh index 979207be224..1144a31fc30 100644 --- a/kubernetes/samples/scripts/common/utility.sh +++ b/kubernetes/samples/scripts/common/utility.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2018, 2021, Oracle and/or its affiliates. +# Copyright (c) 2018, 2022, Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. # @@ -926,3 +926,26 @@ function checkService(){ done echo "Service [$svc] found" } + +# Get pod name when pod available in a given namespace +function getPodName(){ + + local max=$((SECONDS + 120)) + + local pod=$1 + local ns=$2 + + local pname="" + while [ $SECONDS -le $max ] ; do + pname=`kubectl get po -n ${ns} | grep -w ${pod} | awk '{print $1}'` + [ -z "${pname}" ] || break + sleep 1 + done + + if [ -z "${pname}" ] ; then + echo "[ERROR] Could not find Pod [$pod] after $max seconds"; + exit 1 + fi + + echo "${pname}" +} \ No newline at end of file diff --git a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh index 069edb06a24..9acc7953b1a 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2018, 2021, Oracle and/or its affiliates. +# Copyright (c) 2018, 2022, Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. # # Description @@ -212,9 +212,9 @@ function createDomainHome { # domain resource is created by exec'ing into the pod to look for the presence of domainCreate.yaml file. if [ "$useWdt" = true ]; then - POD_NAME=`kubectl get pods -n ${namespace} | grep ${JOB_NAME} | awk ' { print $1; } '` + POD_NAME=$(getPodName "${JOB_NAME}" "${namespace}") echo "Waiting for results to be available from $POD_NAME" - kubectl wait --timeout=600s --for=condition=ContainersReady pod $POD_NAME + kubectl wait --timeout=600s --for=condition=ContainersReady pod $POD_NAME -n ${namespace} #echo "Fetching results" sleep 30 max=30