deploy-cloud-functions icon indicating copy to clipboard operation
deploy-cloud-functions copied to clipboard

ALREADY_EXISTS error while trying to update function with dash instead of underscore in name

Open vitorelourenco opened this issue 1 year ago • 7 comments

TL;DR

The error seems to be realated to how gcp treats function names. The correct function name was foo_bar but in the name field for the action, I had written foo-bar instead.

Expected behavior

An error message saying 'Failed to update' or a successful update.

Observed behavior

Error showing an attempt to create a cloud function with the "same name".

Action YAML

name: ...
on:
  push:
    branches:
      - main
    paths:
      - ...
  workflow_dispatch:
jobs:
  deploy-job:
    environment: ...

    permissions:
      id-token: write
      contents: read

    runs-on: ubuntu-latest

    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - id: 'auth'
        name: 'Authenticate to Google Cloud'
        uses: 'google-github-actions/auth@v2'
        with:
          workload_identity_provider: ...
          service_account: ...

      - id: 'deploy'
        uses: 'google-github-actions/deploy-cloud-functions@v3'
        with:
          name: ...
          runtime: 'nodejs20'
          entry_point: ...
          environment: 'GEN_2'
          region: ...
          source_dir: ...

      - name: Report Status
        if: always()
        uses: ravsamhq/notify-slack-action@v2
        with:
          status: ${{ job.status }}
          notify_when: 'failure'
        env:
          ...

Log output

Run google-github-actions/deploy-cloud-functions@v3
Created zip file from --REDACTED--
Creating new Cloud Functions deployment
Error: google-github-actions/deploy-cloud-functions failed with: failed to POST --REDACTED--: (409) {
  "error": {
    "code": 409,
    "message": "Could not create Cloud Run service --REDACTED--. A Cloud Run service with this name already exists. Please redeploy the function with a different name.",
    "status": "ALREADY_EXISTS"
  }
}

Additional information

No response

vitorelourenco avatar Nov 19 '24 14:11 vitorelourenco

Does a Cloud Run service with that name already exist? You can check in the Google Cloud Console.

sethvargo avatar Nov 19 '24 14:11 sethvargo

Does a Cloud Run service with that name already exist? You can check in the Google Cloud Console.

It does but it is the same service, it's a cloud function gen 2. In the clound functions console it's named as foo_bar (underscore) and in the cloud run console it's named as foo-bar (dash)

vitorelourenco avatar Nov 19 '24 18:11 vitorelourenco

Does this happen every time? Or did you rename the function and then it started happening?

sethvargo avatar Nov 19 '24 20:11 sethvargo

I've only started using github actions for it today, before that I would zip and redeploy via console. I do remember fiddling around with that function, back when I was moving it from GEN 1 to GEN 2. I may have changed it's name back then but I'm not sure if it was my doing or google's, since the function still displays with an underscore in the cloud functions console. It's also a pretty set-and-done function so it hasnt seen any new deployments for several months. I don't have other examples of this in our repo but that happens every time for this function. I was thinking this could be a problem related to the underlying tool instead of the action but the error I get is different when I use gcloud with the same arugments.

cloud run name: foo-bar cloud function name: foo_bar

gcloud functions deploy --entry-point ... --gen2 --region us-east1 --source ... --runtime nodejs20 foo-bar
ERROR: (gcloud.functions.deploy) One of arguments [--trigger-topic, --trigger-bucket, --trigger-http, --trigger-event, --trigger-event-filters] is required: You must specify a trigger when deploying a new function.


gcloud functions deploy --entry-point ... --gen2 --region us-east1 --source ... --runtime nodejs20 foo_bar
Preparing function...done.                                                                                                                                                                                                
X Updating function (may take a while)...  
<more stuff>

vitorelourenco avatar Nov 19 '24 20:11 vitorelourenco

Are you able to put together a reproduction case from scratch? I'm having trouble reproducing this, so I must be missing a step.

sethvargo avatar Nov 20 '24 00:11 sethvargo

I'll see if I can reproduce it over the weekend

vitorelourenco avatar Nov 20 '24 00:11 vitorelourenco

It's been a while and I was never able to reproduce it. Insted, I was able to deploy it using this action but then a completely different error happened when the cloud scheduler tried to execute it:

"@type":"type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished", "debugInfo":"URL_UNREACHABLE-UNREACHABLE_5xx. Original HTTP response code number = 504", "jobName":"--REDACTED--", "status":"DEADLINE_EXCEEDED", "targetType":"HTTP", "url":"--REDACTED--"}

I believe there were edge cases that were hard to treat/predict and irrelevant if the user can just make a new cloud function that won't have the same legacy history of being a cloud function v1, then a v2, then a cloud run function and having name changes that include dashes and underscores...

Feel free to close this issue, as it seems only I have gone through it and it might not even be a real issue anymore.

vitorelourenco avatar Feb 05 '25 10:02 vitorelourenco