0

I am trying to move a test function from Gen1 to Gen2. I deleted it through the console, and used the following command (through Github actions) to deploy. I get the error at the bottom, which doesn't make sense since I'm not specifying any memory size.

Has anyone experienced this?

        gcloud -q functions deploy hello_world \
          --gen2 \
          --runtime python310 \
          --trigger-http \
          --allow-unauthenticated \
          --region us-central1 \
          --source functions/src \
          --service-account=${{ secrets.GCP_SA_EMAIL }}
ERROR: (gcloud.functions.deploy) ResponseError: status=[400], code=[OK],
message=[Could not create Cloud Run service hello-world.

spec.template.spec.containers.resources.limits.memory: Invalid value
specified for memory. For the specified value, maxScale may not exceed 83.
RopeySim
  • 423
  • 4
  • 11
  • Does the function have exactly the same name as the gen1 had? Maybe it takes some time to purge it. If the name is identical, can you try if you get the same error with a different name? – yedpodtrzitko May 17 '23 at 07:40
  • I created a new function, test, and deployed it as above (just changed the name to test and created the function in main.py. Same result unfortunately. – RopeySim May 17 '23 at 07:50
  • Do you have default parameter in your gcloud config? To see them, perform a `gcloud config list`. Paste the result with redacted sensitive data – guillaume blaquiere May 17 '23 at 07:51
  • 1
    Consider adding `--memory=512MiB` and `--max-instances=30` or lower than `83` which could solve the issue. – Rohit Kharche May 17 '23 at 10:11
  • That did it. I had to adjust permissions, but the memory and instance flags fixed it. Thank you, you should put it as an answer. I don't get why it's necessary, I've seen examples where it isn't provided and it uses the default. – RopeySim May 18 '23 at 22:47

1 Answers1

3

The error message :

spec.template.spec.containers.resources.limits.memory: Invalid value
specified for memory. For the specified value, maxScale may not exceed 83.

means the existing gen 1 cloud function may have a maxScale set to more than 83. While migrating to gen2 default memory might have been taken by default as 256 MB as per documentation and max scale is greater than 83 which might be giving above error.

Hence I have set the --max-instances=30 to balance max-instances according to memory. But you can also modify this value as per requirement by --max-instances .

The same applies to the --memory flag.

The updated command will be :

gcloud -q functions deploy hello_world \
          --gen2 \
          --runtime python310 \
          --memory=512MiB \
          --max-instances=30 \
          --trigger-http \
          --allow-unauthenticated \
          --region us-central1 \
          --source functions/src \
          --service-account=${{ secrets.GCP_SA_EMAIL }}

Reference : gcloud functions deploy

Rohit Kharche
  • 2,541
  • 1
  • 2
  • 13
  • 1
    Once again thank you so much for your help. I migrated all the functions and it works great. Gen2 is very nice. – RopeySim May 19 '23 at 12:09