【问题标题】:gcloud API: example run.Service for deploying a containergcloud API:用于部署容器的示例 run.Service
【发布时间】: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 服务。

标签: go gcloud


【解决方案1】:

我通过将 run "google.golang.org/api/run/v1alpha1" 更改为 run "google.golang.org/api/run/v1" 来实现此功能

【讨论】:

  • 为了他人的利益,也请发布工作源代码。我假设您也必须更改 Go 类型和 Kubernetes 类型。
  • 这是唯一需要的改变。
猜你喜欢
  • 2016-01-25
  • 1970-01-01
  • 2018-07-21
  • 2021-10-17
  • 2019-03-08
  • 1970-01-01
  • 2018-07-15
  • 2020-04-23
  • 1970-01-01
相关资源
最近更新 更多