在创建后标记 Google Cloud Platform 部署

斯蒂芬·迪米格

我们有一个批处理标记器,用于处理新创建资源的活动日志,然后我们将标签应用于计费目的。我们正在尝试以这种方式自动标记我们的部署,因为我们发现失败的部署正在累积并产生相当数量的成本。我的问题是我无法标记部署。

我需要向部署添加全局标签,但我以编程方式尝试的所有内容似乎都不起作用。

我尝试使用这样的现有配置:

manifests = self.deploymentManagerService.manifests().list(project=project, 

deployment=deployment_name).execute()
config = manifests['manifests'][0]['config']
...
content_dict = eval(json.dumps(json.loads(config['content'])))
output = StringIO.StringIO()
yaml.dump(content_dict, output, encoding=None)

body = {'labels': labels, 'fingerprint': fingerprint, 'name': deployment_name,  'target': {'config': { 'content': output.getvalue()}}}
print "BODY=", body
deploymentManagerService.deployments().patch(project=project,
                                             deployment=deployment_name,
                                             body=body).execute()

这正确地标记了部署,但由于路径问题而在更新中出错。

我尝试了一个空的资源部分:

 body = {'labels': labels, 'fingerprint': fingerprint, 'name': deployment_name,  'target': {'config': { 'content': 'resources:\n'}}}

这会标记部署,但会清除配置(不好)。

我没有尝试任何配置或目标并得到 400。我不知所措。

布赖恩·麦卡松

无需获取清单。使用patch是正确的想法,但您需要添加一个额外的标题下面是一个例子:

dep = self.deploymentManagerService.deployments().get(
    deployment=deployment, project=project).execute()
body = {'labels': [{'key': 'foo', 'value': 'bar'}],
        'fingerprint': dep['fingerprint']}

req = self.deploymentManagerService.deployments().patch(
    project=project, deployment=deployment, body=body)
# This header is required for patch requests to work correctly.
req.headers['X-Cloud-DM-Patch'] = 'True'
res = req.execute()

此外,您可能希望:

  1. 如果存在并发修改(HTTP 409 冲突),则重试整个块。
  2. 考虑您希望如何处理现有标签(如果您的用例中可以有现有标签)。
  3. 有一个循环来等待从execute结束返回的长时间运行的操作

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 Google Cloud Platform 上部署 Vue Build

将create-react-app构建部署到Google Cloud Platform后找不到URL

使用Google Cloud Platform部署React应用程序

在Google Cloud Platform中创建实例模板

通过 Cloud Functions 创建 Google Cloud Platform 预算

如何在 Google Cloud Platform 上部署 GRPC 服务器和客户端?

如何使用Kubernetes和Gitlab CI / CD在Google Cloud Platform中部署登台?

Google Cloud Platform应用程序部署导致502服务器错误

将C ++应用程序部署到Google Cloud Platform Kubernetes引擎

将带有 textract 模块的 Python 应用程序部署到 Google Cloud Platform

增加Google Cloud Platform Kubernetes Wordpress点击部署上的PHP.ini文件上传限制

将Flask应用程序部署到Google Cloud Platform时无法获得正确的TensorFlow版本

Ingress-Nginx-Controller找不到在Google Cloud Platform上部署的第二项服务

无法使用Php 7.3将laravel 7部署到Google Cloud Platform

如何将flask-socketio 应用程序部署到Google Cloud Platform App Engine

部署到Google Cloud Run后如何回滚

Google Cloud Endpoints,在本地工作,部署后无法工作

如何创建在 Google Cloud Platform 中创建的 MongoDB 用户?

Google Cloud Messaging VS Google Cloud Platform

使用Google Cloud Platform Deployment Manager模板创建存储桶

在Google Cloud Platform中创建HTTP负载均衡器

无法在Google Cloud Platform中创建Jupyter Notebook实例

在Google Cloud Platform上创建自动磁盘快照(备份)保留

Google Cloud Function部署失败

无法从Google Cloud删除部署

Google Cloud Platform:如何重命名Google Cloud Platform项目?

Google Cloud Platform文件位置

Google Cloud Platform个人帐单

Google Cloud Platform数据显示