fix: resolve Gitea service API for PaC apply
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user