#!/bin/bash
#***************************************************************#
# ScriptName: uk8s_check_apiserver.sh
# Author: xhy
# Create Date: 2025-03-29 10:20
# Modify Author: xhy
# Modify Date: 2025-03-29 12:25
# Version: v1
#***************************************************************#

max_retries=5
err=0
apiserver_healthz_url="https://localhost:6443/healthz"

for _ in $(seq 1 $max_retries); do
    http_code=$(curl -s -o /dev/null -w "%{http_code}" "$apiserver_healthz_url")

    if [[ "$http_code" == "200" ]]; then
        echo "apiserver normal!"
        exit 0
    else
        err=$((err + 1))
        sleep 3
    fi
done

echo -e "\n\n\033[31m[ERROR] >>> apiserver error: failed $max_retries retries...\033[0m"
exit 1
