使用编程方式创建一个具有Cloud SQL访问权限的Cloudrun作业?

huangapple go评论74阅读模式
英文:

Create a Cloudrun Job programmatically with Cloud SQL access?

问题

我需要以编程方式创建一个可以访问Cloud SQL实例的Cloud Run作业。查看我在控制台成功创建的作业的YAML文件,似乎可以通过注释来控制,例如 run.googleapis.com/cloudsql-instancesrun.googleapis.com/vpc-access-connector。当我尝试在Java构建器中添加这些注释时:

builder.putAnnotations(
    "run.googleapis.com/cloudsql-instances",
    "my-instance")

最终我会收到一个错误消息:

INVALID_ARGUMENT: 在 CreateJobRequest.job.template.annotations[run.googleapis.com/vpc-access-egress] 中的违规:Cloud Run API v2 不支持系统注释。

这让我觉得以 run.googleapis.com 开头的注释可能是不允许的。如果是这种情况,那么在我以编程方式创建作业时,是否不可能连接到私有Cloud SQL数据库呢?

英文:

I need to create a cloudrun job programmatically that can access a cloudsql instance. Looking at the yml from the a job I created successfully in the console, it looks like that is controlled with annotations like run.googleapis.com/cloudsql-instances and run.googleapis.com/vpc-access-connector. When I try to add those annotations in the java builder:

                  builder.putAnnotations(
                          "run.googleapis.com/cloudsql-instances",
                          "my-instance")

I ultimately get an error:

INVALID_ARGUMENT: Violation in CreateJobRequest.job.template.annotations[run.googleapis.com/vpc-access-egress]: system annotations are not supported in Cloud Run API v2.

Which makes me think the annotations starting with run.googleapis.com are not allowed. If that is the case, is it impossible to connect to a private cloudsql database when I am creating a job programmatically?

答案1

得分: 1

你正在查看的YAML文件适用于Cloud Run v1 API,但你正在使用v2 API。在v2中,VPC设置是模板中的一个字段,而不是一个注释。你可以在这里查看文档:https://cloud.google.com/run/docs/reference/rest/v2/TaskTemplate

英文:

The yaml you're looking at is for the Cloud Run v1 API but you're using the v2 API. In v2, VPC settings are a field in the template rather than an annotation. You can see the docs here: https://cloud.google.com/run/docs/reference/rest/v2/TaskTemplate

huangapple
  • 本文由 发表于 2023年6月29日 08:27:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定