From d5260cf8fca54fdf8a108804afac37f1dba8e15d Mon Sep 17 00:00:00 2001 From: Tudor Date: Tue, 24 Mar 2026 15:10:09 +0000 Subject: [PATCH] fix(kestra-init): use correct flows API endpoint and handle upsert - POST /api/v1/flows with Content-Type: application/x-yaml (not the ZIP-based /import endpoint) - On 409 (already exists), fall back to PUT /api/v1/flows/{ns}/{id} so redeployment updates existing flows rather than failing - Print HTTP response body on error for easier debugging Co-Authored-By: Claude Sonnet 4.6 --- integrator/docker/kestra-init.sh | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/integrator/docker/kestra-init.sh b/integrator/docker/kestra-init.sh index 624a2ec..fd821d2 100644 --- a/integrator/docker/kestra-init.sh +++ b/integrator/docker/kestra-init.sh @@ -6,12 +6,36 @@ KESTRA_URL="${KESTRA_URL:-http://kestra:8080}" echo "Importing flows into Kestra at ${KESTRA_URL}..." for f in /flows/*.yml; do - echo " -> $(basename "$f")" - curl -sf -X POST "${KESTRA_URL}/api/v1/flows/import" \ - -H "Content-Type: multipart/form-data" \ - -F "fileUpload=@${f}" \ - || { echo "Failed to import $(basename "$f")"; exit 1; } - echo "" + name="$(basename "$f")" + echo " -> $name" + + http_code=$(curl -s -o /tmp/kestra_resp -w "%{http_code}" \ + -X POST "${KESTRA_URL}/api/v1/flows" \ + -H "Content-Type: application/x-yaml" \ + --data-binary "@${f}") + + if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then + echo " created" + elif [ "$http_code" = "409" ]; then + # Flow already exists — update it via PUT /api/v1/flows/{namespace}/{id} + ns=$(grep '^namespace:' "$f" | awk '{print $2}') + id=$(grep '^id:' "$f" | awk '{print $2}') + http_code2=$(curl -s -o /tmp/kestra_resp -w "%{http_code}" \ + -X PUT "${KESTRA_URL}/api/v1/flows/${ns}/${id}" \ + -H "Content-Type: application/x-yaml" \ + --data-binary "@${f}") + if [ "$http_code2" = "200" ] || [ "$http_code2" = "201" ]; then + echo " updated" + else + echo " ERROR updating $name: HTTP $http_code2" + cat /tmp/kestra_resp; echo + exit 1 + fi + else + echo " ERROR importing $name: HTTP $http_code" + cat /tmp/kestra_resp; echo + exit 1 + fi done echo "All flows imported."