{"record":{"id":"38de4b8cc50fd306","repo":"GoogleContainerTools/skaffold","slug":"statuscode-deploy-cloud-run-delete-service-err","errorCode":"StatusCode_DEPLOY_CLOUD_RUN_DELETE_SERVICE_ERR","errorMessage":"unable to delete Cloud Run Service","messagePattern":"unable to delete Cloud Run Service","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/cloudrun/deploy.go","lineNumber":555,"sourceCode":"\t\tprojectID = service.Metadata.Namespace\n\tdefault:\n\t\t// no project specified, we don't know what to delete.\n\t\treturn sErrors.NewError(fmt.Errorf(\"unable to determine Google Cloud Project\"), &proto.ActionableErr{\n\t\t\tMessage: \"No Google Cloud Project found in Cloud Run manifest or Skaffold Manifest.\",\n\t\t\tErrCode: proto.StatusCode_DEPLOY_READ_MANIFEST_ERR,\n\t\t})\n\t}\n\tparent := fmt.Sprintf(\"projects/%s/locations/%s\", projectID, d.Region)\n\tsName := fmt.Sprintf(\"%s/services/%s\", parent, service.Metadata.Name)\n\tif dryRun {\n\t\toutput.Yellow.Fprintln(out, sName)\n\t\treturn nil\n\t}\n\n\tdelCall := crclient.Projects.Locations.Services.Delete(sName)\n\t_, err := delCall.Do()\n\tif err != nil {\n\t\treturn sErrors.NewError(fmt.Errorf(\"unable to delete Cloud Run Service\"), &proto.ActionableErr{\n\t\t\tMessage: err.Error(),\n\t\t\tErrCode: proto.StatusCode_DEPLOY_CLOUD_RUN_DELETE_SERVICE_ERR,\n\t\t})\n\t}\n\treturn nil\n}\n\nfunc (d *Deployer) deleteRunJob(crclient *run.APIService, out io.Writer, dryRun bool, manifest []byte) error {\n\tjob := &run.Job{}\n\tif err := k8syaml.Unmarshal(manifest, job); err != nil {\n\t\treturn sErrors.NewError(fmt.Errorf(\"unable to unmarshal Cloud Run Job config: %w\", err), &proto.ActionableErr{\n\t\t\tMessage: err.Error(),\n\t\t\tErrCode: proto.StatusCode_DEPLOY_READ_MANIFEST_ERR,\n\t\t})\n\t}\n\tvar projectID string\n\tswitch {\n\tcase d.Project != \"\":","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/cloudrun/deploy.go#L537-L573","documentation":"Thrown by deleteRunService when the Cloud Run API Delete call (crclient.Projects.Locations.Services.Delete(sName).Do()) returns an error. The project/region/service resource name were resolved fine, but the API refused or failed the deletion. The underlying API error text is surfaced in the actionable error Message.","triggerScenarios":"cleanupRun -> deleteRunService calls Projects.Locations.Services.Delete on projects/<proj>/locations/<region>/services/<name> and the API returns a non-2xx response or transport error.","commonSituations":"Service already deleted (404) or never existed; wrong region configured; missing run.services.delete IAM permission or expired credentials; API not enabled; transient network failures; service has a delete-blocking state (e.g. deletion already in progress).","solutions":["Read the embedded err.Error() in the actionable error: if 404, the service is already gone and cleanup can be re-run/ignored","Verify gcloud auth and IAM: the identity needs roles/run.admin (run.services.delete)","Confirm deploy.cloudrun.region matches the region the service was deployed to","Retry on transient (5xx/network) failures after checking service state"],"exampleFix":"// before: deleting in wrong region\ndeploy:\n  cloudrun:\n    region: us-central1\n// after: match the region used at deploy time\ndeploy:\n  cloudrun:\n    region: us-east1","handlingStrategy":"try-catch","validationCode":"// pre-check before delete\ncall := crclient.Projects.Locations.Services.Get(sName)\nif _, err := call.Do(); err != nil {\n\tif gErr, ok := err.(*googleapi.Error); ok && gErr.Code == 404 {\n\t\treturn nil // already deleted, skip\n\t}\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"if _, err := delCall.Do(); err != nil {\n\tif gErr, ok := err.(*googleapi.Error); ok {\n\t\tswitch gErr.Code {\n\t\tcase 404:\n\t\t\treturn nil // idempotent delete\n\t\tcase 403:\n\t\t\treturn fmt.Errorf(\"IAM: needs run.services.delete: %w\", err)\n\t\tcase 429, 500, 503:\n\t\t\treturn retryWithBackoff(delCall)\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["Make cleanup idempotent: treat 404 as success","Grant the CI identity roles/run.admin (run.services.delete permission)","Keep region configured identically for deploy and cleanup","Check the service's status before deleting (deletion already in progress returns an error)"],"tags":["gcp","cloud-run","api","deletion"],"backgroundTag":"cloud-run-api-delete-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}