0

我正在尝试从放置在不同项目中的 Cloud Source Repository 部署 Cloud Function ,但出现以下错误:(Failed to retrieve function source code请参阅下面的完整原型)。

Project-A 包含下面列出的云功能和服务帐户。Project-B 包含源存储库。

我已成功在 Project-B 上部署了该功能。

我尝试为以下服务帐户赋予Source Repository Administrator云源存储库中的角色,但这没有帮助。

  • {project_A_number}@cloudservices.gserviceaccount.com
  • {project_A_number}-compute@developer.gserviceaccount.com
  • {project_A_number}@cloudbuild.gserviceaccount.com
  • 项目-A@appspot.gserviceaccount.com

我还尝试在 Project-A 上禁用 Cloud Functions API 并再次将其重新打开。

我不确定出了什么问题 - 如果有人知道在哪里进一步查看,我将不胜感激 - 在此先感谢!


部署在监控中创建了两个条目 - 一个 NOTICE 后跟一个 ERROR:

  • 错误日志:
{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "status": {
      "code": 5,
      "message": "Failed to retrieve function source code"
    },
    "authenticationInfo": {
      "principalEmail": "***@***.**"
    },
    "serviceName": "cloudfunctions.googleapis.com",
    "methodName": "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
    "resourceName": "projects/Project-A/locations/europe-west1/functions/pubsub-to-gcs"
  },
  "insertId": "-vmfbt4cd54",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "function_name": "pubsub-to-gcs",
      "region": "europe-west1",
      "project_id": "Project-A"
    }
  },
  "timestamp": "2021-10-20T12:21:45.352043Z",
  "severity": "ERROR",
  "logName": "projects/Project-A/logs/cloudaudit.googleapis.com%2Factivity",
  "operation": {
    "id": "operations/cm9ldHotbGlmZS1kYXRhLXRlc3QvZXVyb3BlLXdlc3QxL3B1YnN1Yi10by1nY3MvVEhFbUQtLTZITWM",
    "producer": "cloudfunctions.googleapis.com",
    "last": true
  },
  "receiveTimestamp": "2021-10-20T12:21:45.781856467Z"
}
  • NOTICE 日志(在错误之前记录):
{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalEmail": "***@****.**"
    },
    "requestMetadata": {
      "callerIp": "35.205.252.75",
      "callerSuppliedUserAgent": "google-cloud-sdk gcloud/360.0.0 command/gcloud.functions.deploy invocation-id/917d697431e84b91bfa2bd9f9cc4f302 environment/devshell environment-version/None interactive/True from-script/False python/3.7.3 term/screen (Linux 5.4.144+),gzip(gfe),gzip(gfe)",
      "requestAttributes": {
        "time": "2021-10-20T12:21:44.909430Z",
        "auth": {}
      },
      "destinationAttributes": {}
    },
    "serviceName": "cloudfunctions.googleapis.com",
    "methodName": "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
    "authorizationInfo": [
      {
        "resource": "projects/Project-A/locations/europe-west1/functions/pubsub-to-gcs",
        "permission": "cloudfunctions.functions.update",
        "granted": true,
        "resourceAttributes": {}
      }
    ],
    "resourceName": "projects/Project-A/locations/europe-west1/functions/pubsub-to-gcs",
    "request": {
      "@type": "type.googleapis.com/google.cloud.functions.v1.UpdateFunctionRequest",
      "function": {
        "timeout": "60s",
        "status": "UNKNOWN",
        "serviceAccountEmail": "Project-A@appspot.gserviceaccount.com",
        "availableMemoryMb": 256,
        "name": "projects/Project-A/locations/europe-west1/functions/pubsub-to-gcs",
        "runtime": "python39",
        "labels": {
          "deployment-tool": "cli-gcloud"
        },
        "entryPoint": "pubsub-to-gcs",
        "updateTime": "2021-10-20T12:21:40.149Z",
        "sourceRepository": {
          "url": "https://source.developers.google.com/projects/Project-B/repos/my-repo/moveable-aliases/master/paths/my-folder"
        },
        "httpsTrigger": {},
        "ingressSettings": "ALLOW_ALL",
        "versionId": "1"
      },
      "updateMask": "eventTrigger,httpsTrigger,runtime,sourceRepository"
    },
    "resourceLocation": {
      "currentLocations": [
        "europe-west1"
      ]
    }
  },
  "insertId": "1xdbim3e16pgu",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "function_name": "pubsub-to-gcs",
      "region": "europe-west1",
      "project_id": "Project-A"
    }
  },
  "timestamp": "2021-10-20T12:21:44.650257Z",
  "severity": "NOTICE",
  "logName": "projects/Project-A/logs/cloudaudit.googleapis.com%2Factivity",
  "operation": {
    "id": "operations/cm9ldHotbGlmZS1kYXRhLXRlc3QvZXVyb3BlLXdlc3QxL3B1YnN1Yi10by1nY3MvVEhFbUQtLTZITWM",
    "producer": "cloudfunctions.googleapis.com",
    "first": true
  },
  "receiveTimestamp": "2021-10-20T12:21:45.832588036Z"
}
4

1 回答 1

1

事实证明这不是 IAM 问题:我尝试从 UI 部署该功能,但是从不同项目中的源存储库部署时这是不可能的。

部署使用gcloud function deploy解决了这个问题。

于 2021-10-21T19:05:01.047 回答