【问题标题】:Adding labels for GCP App Engine Services为 GCP App Engine 服务添加标签
【发布时间】:2020-11-01 18:23:18
【问题描述】:

使用gcloud 命令或至少来自GCP console 管理App Engine labels 的任何建议。我正在尝试为已部署的应用程序添加 label

看不到使用gcloud 命令更新App Engine Service 标签参数的任何选项

 $ gcloud app instances
 ERROR: (gcloud.app.instances) Command name argument expected.

 Available commands for gcloud app instances:

  delete                  Delete a specified instance.
  describe                Display all data about an existing instance.
  disable-debug           Disable debug mode for an instance.
  enable-debug            Enable debug mode for an instance (only works on
                          the flexible environment).
  list                    List the instances affiliated with the current App
                          Engine project.
  scp                     SCP from or to the VM of an App Engine Flexible
                          instance.
  ssh                     SSH into the VM of an App Engine Flexible
                          instance.

还有任何从terraform 管理的选项吗? .

找不到任何attributes 来管理labels 下的任何内容

 https://www.terraform.io/docs/providers/google/r/app_engine_standard_app_version.html
 https://www.terraform.io/docs/providers/google/r/app_engine_application.html

【问题讨论】:

  • 我尝试了很多东西,无法找到用于此的公共 API。即使在文档中,也只提到了控制台。没有为此的api :(

标签: google-app-engine google-cloud-platform terraform


【解决方案1】:

虽然我找不到通过 gcloud CLI 执行此操作的方法,但您可以通过控制台 UI 为 App Engine 资源设置标签,步骤如下:

  1. 转到 App Engine 服务页面。
  2. 选中要添加标签的服务的复选框。
  3. 在页面右上角,点击“显示信息面板”,然后点击标签。

这个过程记录在here。

此外,请随时在 Google's Issue Tracker 中提出功能请求,要求在 gcloud CLI 中添加标签选项。

【讨论】:

  • 非常感谢。我会为此提出功能要求。
【解决方案2】:

标签现在是 API 的一部分,但看起来并没有记录在案。通过 REST API 使用 PATCH 可以为 App Engine 的服务设置标签。

https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services/patch

Service 类型不包含labels,但如果您运行gcloud app services describe SERVICE --format=json,您会看到响应中包含标签。

使用 curl 设置标签的示例:

curl \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      -X PATCH \
      -d '{"labels":{"label_name":"label_value"}}' \
     "https://appengine.googleapis.com/v1/apps/${project}/services/${service}?updateMask=labels"

【讨论】:

    【解决方案3】:

    聚会有点晚了,但我们需要做一些类似的事情,但使用 C# AppEngine 客户端库 (Google.Apis.Appengine.v1)。这适用于我们使用最新版本的库,假设您已经检索到 AppEngine 服务对象,并且您知道您的目标 projectId 和服务名称:

    var labels = new Dictionary<string,string>(); //Set your labels in here
    service.Labels = labels;
    var patchRequest = appEngineService.Apps.Services.Patch(service, project, 
    serviceId);
    patchRequest.UpdateMask = "Labels";
    return await patchRequest.ExecuteAsync();
    

    【讨论】:

    • 现在API公开了,期待terraform支持它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2019-08-25
    • 1970-01-01
    相关资源
    最近更新 更多