首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用退出代码2完成编译

用退出代码2完成编译
EN

Stack Overflow用户
提问于 2019-08-20 17:37:45
回答 1查看 3.1K关注 0票数 0

我试着在这里运行这个例子:

https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration

我已经设置了我的GOROOT和GOPATH,但仍然有问题。当我运行构建时,我会看到以下错误。

代码语言:javascript
复制
GOROOT=/usr/lib/golang #gosetup
GOPATH=/home/sbadakhc/go #gosetup
/usr/lib/golang/bin/go build -o /tmp/___go_build_main_go /home/sbadakhc/go/src/github.com/sbadakhc/gopro/main.go #gosetup
# k8s.io/client-go/transport
../../../k8s.io/client-go/transport/round_trippers.go:70:11: cannot convert klog.V(9) (type klog.Verbose) to type bool
../../../k8s.io/client-go/transport/round_trippers.go:72:11: cannot convert klog.V(8) (type klog.Verbose) to type bool
../../../k8s.io/client-go/transport/round_trippers.go:74:11: cannot convert klog.V(7) (type klog.Verbose) to type bool
../../../k8s.io/client-go/transport/round_trippers.go:76:11: cannot convert klog.V(6) (type klog.Verbose) to type bool

Compilation finished with exit code 2

密码。

代码语言:javascript
复制
import (
    "fmt"
    "time"

    "k8s.io/apimachinery/pkg/api/errors"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    "k8s.io/client-go/kubernetes"
    "k8s.io/client-go/rest"
    //
    // Uncomment to load all auth plugins
    _ "k8s.io/client-go/plugin/pkg/client/auth"
    //
    // Or uncomment to load specific auth plugins
    // _ "k8s.io/client-go/plugin/pkg/client/auth/azure"
    // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
    // _ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
    // _ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
)

func main() {
    // creates the in-cluster config
    config, err := rest.InClusterConfig()
    if err != nil {
        panic(err.Error())
    }
    // creates the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
    for {
        pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{})
        if err != nil {
            panic(err.Error())
        }
        fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))

        // Examples for error handling:
        // - Use helper functions like e.g. errors.IsNotFound()
        // - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
        _, err = clientset.CoreV1().Pods("default").Get("example-xxxxx", metav1.GetOptions{})
        if errors.IsNotFound(err) {
            fmt.Printf("Pod not found\n")
        } else if statusError, isStatus := err.(*errors.StatusError); isStatus {
            fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message)
        } else if err != nil {
            panic(err.Error())
        } else {
            fmt.Printf("Found pod\n")
        }

        time.Sleep(10 * time.Second)
    }
}

此代码应正确构建。

EN

回答 1

Stack Overflow用户

发布于 2019-08-21 07:19:55

我最终要执行构建,但似乎有很多因素。

  1. 将../k8s.io从我的src目录中删除。
  2. 通过在go.mod文件中显式声明版本,避免使用客户端的最新主分支。

重新运行构建获取新的源和客户端的稳定版本。生成执行时没有出现错误。

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

https://stackoverflow.com/questions/57578927

复制
相关文章

相似问题

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