【发布时间】:2020-10-22 11:15:09
【问题描述】:
我希望通过 gcloud API 部署 gcloud hello-world 容器。
实现此目的的正确 run.Service 规范是什么?
我当前的应用程序低于但它失败并出现错误googleapi: Error 404: Requested entity was not found.
package main
import (
"context"
"fmt"
// "sort"
// "google.golang.org/api/option"
run "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/v1",
Kind: "Service",
Metadata: &run.ObjectMeta{
Name: serviceName,
Namespace: projectId,
},
Spec: &run.ServiceSpec{
Template: &run.RevisionTemplate{
Spec: &run.RevisionSpec{
Containers: []*run.Container{{
Image: imageName,
}},
},
},
},
}
createCall := projectsLocationsService.Services.Create("projects/"+projectId+"/locations/"+locationsId, 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)
}
【问题讨论】:
-
嗨,你能提供在哪一行抛出错误和完整的回溯吗? this article 也可能会有所帮助,因为它展示了如何使用 golang 客户端库创建 Cloud Run 服务。