使用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
虽然我找不到通过gcloud CLI实现这一点的方法,但您可以通过控制台UI为应用程序引擎资源设置标签,步骤如下:
- 转到应用程序引擎服务页面
- 标记要添加标签的服务的复选框
- 在页面的右上角,单击";显示信息面板";然后进行标记
此处记录了此过程。
此外,您可以在Google的Issue Tracker中提交功能请求,要求在gcloud CLI中添加标签选项。
标签现在是API的一部分,但看起来并没有文档化。通过REST API使用PATCH可以为应用程序引擎设置服务标签。
https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services/patch
服务类型不包括labels
,但如果运行gcloud app services describe SERVICE --format=json
,则会看到响应中包含标签。
使用卷曲设置标签的示例:
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"
派对有点晚了,但我们需要做一些类似的事情,但使用C#AppEngine客户端库(Google.Apis.AppEngine.v1(。这对我们使用最新版本的库有效,假设您已经检索到AppEngine服务对象,并且您知道您的目标项目ID和服务名称:
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();