fix deploy karmada-apiserver error by loadBalancer

Signed-off-by: Poor12 <shentiecheng@huawei.com>
This commit is contained in:
Poor12 2022-11-22 14:51:22 +08:00
parent 00403af749
commit 1dc4c83e16
2 changed files with 5 additions and 3 deletions

View File

@ -200,7 +200,7 @@ if [ "${HOST_CLUSTER_TYPE}" = "remote" ]; then
KARMADA_APISERVER_IP=$(kubectl --context="${HOST_CLUSTER_NAME}" get pod -l app=karmada-apiserver -n "${KARMADA_SYSTEM_NAMESPACE}" -o=jsonpath='{.items[0].status.podIP}')
;;
LoadBalancer)
if util::wait_service_external_ip "karmada-apiserver" "karmada-apiserver" "${KARMADA_SYSTEM_NAMESPACE}"; then
if util::wait_service_external_ip "${HOST_CLUSTER_NAME}" "karmada-apiserver" "${KARMADA_SYSTEM_NAMESPACE}"; then
echo "Get service external IP: ${SERVICE_EXTERNAL_IP}, wait to check network connectivity"
KARMADA_APISERVER_IP=$(util::get_load_balancer_ip) || KARMADA_APISERVER_IP=''
else

View File

@ -521,13 +521,15 @@ function util::wait_service_external_ip() {
local tmp
for tmp in {1..30}; do
set +e
## if .status.loadBalancer does not have `ingress` field, return "".
## if .status.loadBalancer has `ingress` field but one of `ingress` field does not have `hostname` or `ip` field, return "<no value>".
external_host=$(kubectl --context="$context_name" get service "${service_name}" -n "${namespace}" --template="{{range .status.loadBalancer.ingress}}{{.hostname}} {{end}}" | xargs)
external_ip=$(kubectl --context="$context_name" get service "${service_name}" -n "${namespace}" --template="{{range .status.loadBalancer.ingress}}{{.ip}} {{end}}" | xargs)
set -e
if [[ ! -z "$external_host" ]]; then # Compatibility with hostname, such as AWS
if [[ ! -z "$external_host" && "$external_host" != "<no value>" ]]; then # Compatibility with hostname, such as AWS
external_ip=$external_host
fi
if [[ -z "$external_ip" ]]; then
if [[ -z "$external_ip" || "$external_ip" = "<no value>" ]]; then
echo "wait the external ip of ${service_name} ready..."
sleep 6
continue