4

Followed the docs and did the setup as needed, whenever trying to deploy a function, the debug error says

Cannot create trigger projects/***********/locations/us-central1/triggers/******-967155: 
Invalid resource state for \"\": Permission denied while using the Eventarc Service Agent. If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent. Otherwise, verify that it has Eventarc Service Agent role."

Could not create Cloud Run service onrelationadded. spec.template.spec.containers.resources.limits.cpu: Invalid value specified for cpu. For the specified value, maxScale may not exceed 10.\nConsider running your workload in a region with greater capacity, decreasing your requested cpu-per-instance, or requesting an increase in quota for this region if you are seeing sustained usage near this limit

Coming from the V1 I never saw this error before, after looking a lil bit I found its related to IAM & ADMIN . checked the service default manager permission and tried to enable permission as Functions Editor/Admin but still without success

enter image description here

Command : firebase deploy --only functions

Response:


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> tsc

✔  functions: Finished running predeploy script.
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged /User/ ******/******/**** (125.52 KB) for uploading
i  functions: ensuring required API run.googleapis.com is enabled...
i  functions: ensuring required API eventarc.googleapis.com is enabled...
i  functions: ensuring required API pubsub.googleapis.com is enabled...
i  functions: ensuring required API storage.googleapis.com is enabled...
✔  functions: required API pubsub.googleapis.com is enabled
✔  functions: required API eventarc.googleapis.com is enabled
✔  functions: required API storage.googleapis.com is enabled
✔  functions: required API run.googleapis.com is enabled
i  functions: generating the service identity for pubsub.googleapis.com...
i  functions: generating the service identity for eventarc.googleapis.com...
✔  functions: functions folder uploaded successfully
i  functions: creating Node.js 18 (2nd Gen) function onRelationAdded(us-central1)...
⚠  functions: Your current project quotas don't allow for the current max instances setting of 100. Either reduce this function's maximum instances, or request a quota increase on the underlying Cloud Run service at https://cloud.google.com/run/quotas.
⚠  functions: You can adjust the max instances value in your function's runtime options:
        setGlobalOptions({maxInstances: 10})
Failed to create function projects/****/locations/us-central1/functions/Added/user

Functions deploy had errors with the following functions:
        AddedUser(us-central1)
i  functions: cleaning up build files...

Error: There was an error deploying functions ```
David.C
  • 257
  • 3
  • 17
  • Edit your post and include the command that you are running. Since you might have an authorization problem include details on how you authorized the command. Run the command `gcloud auth list`. Look up that principal in IAM and include the roles assigned to that principal. You also have the error `Invalid value specified for cpu`. Do you have an available quota in the region you are deploying? https://cloud.google.com/run/docs/configuring/cpu#setting – John Hanley Jun 08 '23 at 17:39
  • I had a project with 200 functions+ in the same ``region`` the default is ``us-central1`` , never had a quota problem, I edited and included more logs @JohnHanley – David.C Jun 08 '23 at 18:14
  • Your update did not provide the details I asked for. Your update confirms that you have a quota problem. `Your current project quotas don't allow for the current max instances setting of 100. Either reduce this function's maximum instances ...` – John Hanley Jun 08 '23 at 18:55
  • I tried to run the gcloud command and I got: ``zsh: command not found: `` – David.C Jun 08 '23 at 19:33
  • Have you seen answers like this one: https://stackoverflow.com/a/64887504/8016720 – John Hanley Jun 08 '23 at 19:51

2 Answers2

10

To explicitly reduce the default number of instances for all functions in V2, need to use the setGlobalOptions function from the firebase-functions/v2 package.

import { setGlobalOptions } from "firebase-functions/v2";

// Set the maximum instances to 10 for all functions
setGlobalOptions({ maxInstances: 10 });

Use below code if you are not using ES module

const {setGlobalOptions} = require("firebase-functions/v2");
setGlobalOptions({maxInstances: 10});
Priyesh
  • 1,266
  • 5
  • 17
David.C
  • 257
  • 3
  • 17
  • You can also import this directly from 'firebase-functions/v2/options'. I only mention this because, per the docs, "The v2 subpackage is modular, and we recommend only importing the specific module that you need." – Gorgant Jul 02 '23 at 11:00
3

If this is your first deployment of v2, then it's likely all you need to do is wait. In my case, it took approximately 30 minutes for Cloud Run to create a new service.

To double-check if this is your case, go to https://console.cloud.google.com/functions, open your function, and check if it shows the "Creating Cloud Run Service" status.

Logs even say: since this is your first time using functions v2, we need a little bit longer to finish setting everything up, please retry the deployment in a few minutes.

But I didn't expect "a few minutes" to last half of an hour. Someone on Reddit mentioned it that it can take anywhere between 0.5 to 1h from their experience

Stanislau Buzunko
  • 1,630
  • 1
  • 15
  • 27