首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >gcloud API:部署容器的示例run.Service

gcloud API:部署容器的示例run.Service
EN

Stack Overflow用户
提问于 2020-10-22 19:15:10
回答 1查看 71关注 0票数 1

我希望通过gcloud API部署gcloud hello-world容器。

实现这一目标的正确run.Service规范是什么?

我当前的应用程序如下所示,但它失败了,并显示错误googleapi: Error 404: Requested entity was not found.

代码语言:javascript
代码运行次数:0
运行
复制
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)
}
EN

回答 1

Stack Overflow用户

发布于 2020-10-29 17:58:43

我通过将run "google.golang.org/api/run/v1alpha1"更改为run "google.golang.org/api/run/v1"来实现这一点

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64481064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档