From d32575fff2d3117ce57738f40f11610c6ba38bcb Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 5 Jul 2026 10:56:38 +0000 Subject: [PATCH] fix: resolve Gitea service API for PaC apply --- ...platform-infra-pipelines-as-code-remote.sh | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/src/platform-infra-pipelines-as-code-remote.sh b/scripts/src/platform-infra-pipelines-as-code-remote.sh index 0f76e120..f66b964c 100644 --- a/scripts/src/platform-infra-pipelines-as-code-remote.sh +++ b/scripts/src/platform-infra-pipelines-as-code-remote.sh @@ -28,7 +28,29 @@ duration_seconds() { } api_url() { - printf '%s/api/v1/%s' "$UNIDESK_PAC_GITEA_BASE_URL" "$1" + prepare_gitea_api_base + printf '%s/api/v1/%s' "$UNIDESK_PAC_GITEA_API_BASE_URL" "$1" +} + +prepare_gitea_api_base() { + if [ -n "${UNIDESK_PAC_GITEA_API_BASE_URL:-}" ]; then + return + fi + base="$UNIDESK_PAC_GITEA_BASE_URL" + hostport=$(printf '%s' "$base" | sed -n 's#^http://\([^/]*\).*$#\1#p') + if printf '%s' "$hostport" | grep -q '\.svc\.cluster\.local'; then + host=${hostport%%:*} + port=${hostport##*:} + if [ "$port" = "$hostport" ]; then port=80; fi + service=${host%%.*} + rest=${host#*.} + namespace=${rest%%.*} + cluster_ip=$(kubectl -n "$namespace" get svc "$service" -o jsonpath='{.spec.clusterIP}') + UNIDESK_PAC_GITEA_API_BASE_URL="http://$cluster_ip:$port" + else + UNIDESK_PAC_GITEA_API_BASE_URL="$base" + fi + export UNIDESK_PAC_GITEA_API_BASE_URL } gitea_api() {