mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
feat: add health check after harbor installed (#2833)
feat: add health check after harbor installed feat: add health check after harbor installed feat: add health check after harbor installed Signed-off-by: xuesongzuo@yunify.com <xuesongzuo@yunify.com>
This commit is contained in:
parent
9c4c4304ff
commit
0e28c2a2dd
|
|
@ -49,6 +49,31 @@
|
|||
- name: Harbor | Start and enable Harbor service
|
||||
command: systemctl daemon-reload && systemctl start harbor.service && systemctl enable harbor.service
|
||||
|
||||
- name : Harbor | Check harbor api health
|
||||
command: |
|
||||
HARBOR_URL="https://{{ .image_registry.auth.registry }}"
|
||||
MAX_WAIT_SECONDS=300
|
||||
CHECK_INTERVAL=2
|
||||
MAX_RETRIES=$((MAX_WAIT_SECONDS / CHECK_INTERVAL))
|
||||
for ((i=1; i<=MAX_RETRIES; i++)); do
|
||||
# Check health endpoint
|
||||
response=$(curl -k -s -w "%{http_code}" -o /tmp/harbor_health_response.json "$HARBOR_URL/api/v2.0/health")
|
||||
http_code=${response: -3}
|
||||
# Check if healthy
|
||||
if [ "$http_code" -eq 200 ] && grep -q "\"status\":\"healthy\"" /tmp/harbor_health_response.json 2>/dev/null; then
|
||||
rm -f /tmp/harbor_health_response.json
|
||||
exit 0
|
||||
fi
|
||||
# Wait before next check if not max retries reached
|
||||
if [ $i -lt $MAX_RETRIES ]; then
|
||||
sleep $CHECK_INTERVAL
|
||||
fi
|
||||
done
|
||||
# Timeout reached
|
||||
rm -f /tmp/harbor_health_response.json
|
||||
echo "ERROR: Harbor service did not became health within 5 minutes!"
|
||||
exit 1
|
||||
|
||||
- name: Harbor | Configure HA and synchronize Harbor images
|
||||
when:
|
||||
- .image_registry.ha_vip | empty | not
|
||||
|
|
@ -95,10 +120,28 @@
|
|||
systemctl restart harbor.service
|
||||
- name: Harbor | Wait for Harbor service to become ready
|
||||
command: |
|
||||
if ! timeout 300 bash -c 'while ! nc -zv localhost 443; do sleep 2; done'; then
|
||||
echo "ERROR: Harbor did not start within 5 minutes!"
|
||||
exit 1
|
||||
fi
|
||||
HARBOR_URL="https://{{ .image_registry.auth.registry }}"
|
||||
MAX_WAIT_SECONDS=300
|
||||
CHECK_INTERVAL=2
|
||||
MAX_RETRIES=$((MAX_WAIT_SECONDS / CHECK_INTERVAL))
|
||||
for ((i=1; i<=MAX_RETRIES; i++)); do
|
||||
# Check health endpoint
|
||||
response=$(curl -k -s -w "%{http_code}" -o /tmp/harbor_health_response.json "$HARBOR_URL/api/v2.0/health")
|
||||
http_code=${response: -3}
|
||||
# Check if healthy
|
||||
if [ "$http_code" -eq 200 ] && grep -q "\"status\":\"healthy\"" /tmp/harbor_health_response.json 2>/dev/null; then
|
||||
rm -f /tmp/harbor_health_response.json
|
||||
exit 0
|
||||
fi
|
||||
# Wait before next check if not max retries reached
|
||||
if [ $i -lt $MAX_RETRIES ]; then
|
||||
sleep $CHECK_INTERVAL
|
||||
fi
|
||||
done
|
||||
# Timeout reached
|
||||
rm -f /tmp/harbor_health_response.json
|
||||
echo "ERROR: Harbor service did not became health within 5 minutes!"
|
||||
exit 1
|
||||
- name: Harbor | Synchronize harbor-replications script to remote host
|
||||
template:
|
||||
src: harbor-replications.sh
|
||||
|
|
|
|||
Loading…
Reference in New Issue