Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function deploy fails to delete scheduled function without Cloud Scheduler job #4795

Open
taeold opened this issue Jul 28, 2022 · 8 comments · May be fixed by #7787
Open

Function deploy fails to delete scheduled function without Cloud Scheduler job #4795

taeold opened this issue Jul 28, 2022 · 8 comments · May be fixed by #7787

Comments

@taeold
Copy link
Contributor

taeold commented Jul 28, 2022

[REQUIRED] Environment info

firebase-tools: 11.4.0

Platform: macOS

[REQUIRED] Test case

import * as functions from "firebase-functions";

export const v1scheduled = functions.pubsub.schedule("every 30 minutes").onRun(() => {});

[REQUIRED] Steps to reproduce

  1. Deploy a scheduled function
  2. Delete the Cloud Scheduler job associated w/ the scheduled function
  3. Try deleting the function via firebase functions:delete <fn>

[REQUIRED] Expected behavior

Delete the pubsub topic and the function

[REQUIRED] Actual behavior

Command fails:

HTTP 404: Job not found

You have to go manually delete the function in Cloud console. This is annoying, especially if you are running something like firebase deploy --force to clean up old functions as it marks the entire deployment as failed.

@pelly-ryu
Copy link

any update about this?
I experienced this today

@fernandocalsa
Copy link

any update on this? I'm having same problem when trying to remove old functions

@zaqqaz
Copy link

zaqqaz commented Aug 15, 2023

same issue

@crossan007
Copy link

crossan007 commented Oct 4, 2024

I'm seeing this issue as well.

I'm using the atlassian/firebase-deploy:5.1.0 (https://bitbucket.org/atlassian/firebase-deploy/src/master/) BitBucket pipeline to deploy both functions and hosting.

The first time I tried running this pipeline after removing a function from source control, I realized the Google Cloud IAM Service Account associated with the KEY_FILE Pipeline variable was missing the cloudscheduler.jobs.delete permission. I saw this error: HTTP Error: 403, The principal (user or service account) lacks IAM permission "cloudscheduler.jobs.delete" for the resource

I added that permission and re-ran the pipeline.

The second pipeline execution failed with HTTP Error: 403, Cloud Pub/Sub API has not been used in project .... After this pipeline execution failure, the affected functions in Cloud Console appeared to be "partially deleted" - the trigger column no longer listed the CRON schedule:
Before:
image
After:
image

All subsequent pipeline execution attempts now fail with HTTP Error: 404, Job not found.

@crossan007
Copy link

crossan007 commented Oct 4, 2024

In troubleshooting this, I realized my service account role was missing a few permissions:

  • pubsub.topics.delete
  • cloudscheduler.jobs.delete
  • cloudscheduler.jobs.get
  • cloudscheduler.jobs.get

Also, the service account I'm using for deployment belongs to a different organization than the project being deployed, so I had to enable the Cloud Pub/Sub API on the organization to which the service account belongs in order to make the API call to delete the topic.

@crossan007
Copy link

Whilst awaiting merge request approval and a proper release, I was able to patch this into my deployment pipeline so I can "delete" Cloud Functions in the pipeline:

patch /usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js .build/firebase-fabricator.patch

where the contents of .build/firebase-fabricator.patch is:

--- original-fabricator.js	2024-10-04 13:26:09.743553600 -0400
+++ fabricator.js	2024-10-04 17:29:32.601762600 -0400
@@ -160,7 +160,24 @@
         await this.setTrigger(update.endpoint);
     }
     async deleteEndpoint(endpoint) {
-        await this.deleteTrigger(endpoint);
+        try {
+            await this.deleteTrigger(endpoint);
+        }
+        catch (err) {
+            if (err instanceof reporter.DeploymentError &&
+                err.op == "delete schedule" &&
+                err.original.message == "HTTP Error: 404, Job not found.") {
+                logger_1.logger.warn(`Trigger for ${endpoint.id} not found. Continuing to delete function.`);
+            }
+            else if (err instanceof reporter.DeploymentError &&
+                err.op == "delete topic" &&
+                err.message.startsWith("Failed to delete topic function")) {
+                logger_1.logger.warn(`Failed to delete topic function for ${endpoint.id}. Ensure the account has 'pubsub.topics.delete' permission.  You may need to manually delete the topic.  Continuing to delete function.`);
+            }
+            else {
+                throw err;
+            }
+        }
         if (endpoint.platform === "gcfv1") {
             await this.deleteV1Function(endpoint);
         }

@crossan007
Copy link

@mathu97 how does #7781 resolve this? That PR seems to only modify files to src/emulator/apphosting

@mathu97
Copy link
Contributor

mathu97 commented Oct 7, 2024

@mathu97 how does #7781 resolve this? That PR seems to only modify files to src/emulator/apphosting

that PR was linked by accident! Re-openning this issue.

@mathu97 mathu97 reopened this Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants