gpt4 book ai didi

go - 编译完成,退出代码为 2

转载 作者:数据小太阳 更新时间:2023-10-29 03:36:05 24 4
gpt4 key购买 nike

我正在尝试运行此处的示例:

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

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

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

代码。

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)
}
}

此代码应该正确构建。

最佳答案

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

  1. 从我的 src 目录中删除了 ../../../k8s.io。

  2. 通过在 go.mod 文件中明确声明一个版本,避免使用 client-go 的最新主分支。

重新运行构建获取新源和客户端的稳定版本。构建执行无误。

关于go - 编译完成,退出代码为 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57578927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com