英文:
Create a Cloudrun Job programmatically with Cloud SQL access?
问题
我需要以编程方式创建一个可以访问Cloud SQL实例的Cloud Run作业。查看我在控制台成功创建的作业的YAML文件,似乎可以通过注释来控制,例如 run.googleapis.com/cloudsql-instances
和 run.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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论