如何解决gcloud Admin API-创建Cloud Run容器
我正在尝试使用gcloud的go api创建一个容器。
我已经建立了一个项目:
$ gcloud projects list
PROJECT_ID NAME PROJECT_NUMBER
sql-manager-293118 sql-manager 789332021319
还配置了我的应用程序默认凭据。
下面的代码运行良好,但是在创建服务的调用中出现以下错误:
<p>The requested URL <code>/v1alpha1/projects/sql-manager-293118/services?alt=json&prettyPrint=false</code> was not found on this server. <ins>That’s all we know.</ins>
我还使用api运行了更简单的请求(例如,列出了此给定服务的所有可用位置),并且能够重新运行数据而不会出现问题。
任何指导表示赞赏。
package main
import (
"context"
"fmt"
// "sort"
"google.golang.org/api/option"
"google.golang.org/api/run/v1alpha1"
)
const (
createDefaultClientFlag = true
scopes = run.CloudPlatformScope
// List the Cloud Run services in this location
serviceName = "test"
locationsId = "us-central1"
projectId = "sql-manager-293118"
imageName = "gcr.io/cloudrun/hello"
)
func createDefaultClient(ctx context.Context) (*run.APIService,error) {
return run.NewService(ctx)
}
func main() {
// https://godoc.org/google.golang.org/api/run/v1#NewService
var err error = nil
var runService *run.APIService = nil
ctx := context.Background()
runService,err = createDefaultClient(ctx)
if err != nil {
fmt.Println("Error:",err)
return
}
projectsLocationsService := *run.NewProjectsLocationsService(runService)
// Define the service to deploy
tmpservice := &run.Service{
ApiVersion: "serving.knative.dev/v1alpha1",Kind: "Service",Metadata: &run.ObjectMeta{
Name: serviceName,Namespace: projectId,},Spec: &run.ServiceSpec{
RunLatest: &run.ServiceSpecRunLatest{
Configuration: &run.ConfigurationSpec{
RevisionTemplate: &run.RevisionTemplate{
Metadata: &run.ObjectMeta{
DeletionGracePeriodSeconds: 0,Spec: &run.RevisionSpec{
Container: &run.Container{
Image: imageName,Resources: &run.ResourceRequirements{
Limits: map[string]string{"memory": "256Mi"},Stdin: false,StdinOnce: false,Tty: false,ContainerConcurrency: 80,TimeoutSeconds: 300,}
createCall := projectsLocationsService.Services.Create("projects/" + projectId,tmpservice)
service,err := createCall.Do()
fmt.Println(service,err)
if err != nil {
fmt.Printf("Error creating new locationservice: %s",err)
}
fmt.Printf("%#v",service.Spec)
}
解决方法
DazWilkin是正确的,我应该一直使用/projects/${PROJECT}/locations/us-central1/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。