我正在尝试在Go中使用Kubernetes客户端API创建一个pod,并且在TravisCI中遇到了以下错误,
ERRO Running error: buildir: analysis skipped: errors in package: [/home/travis/gopath/src/github.com/pravarag/test-repo/check_pod.go:25:70: cannot use desiredPod (variable of type *"k8s.io/api/core/v1".Pod) as context.Context value in argument to s.kubeClient.CoreV1().Pods(desiredPod.Namespace).Create: missing method Deadline /home/travis/gopath/src/github.com/pravarag/test-repo/check_pod.go:25:80: too few arguments in call to s.kubeClient.CoreV1().Pods(desiredPod.Namespace).Create
下面是代码,
import (
"fmt"
"go.uber.org/zap"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (s *server) createPod() {
// build the pod definition
desiredPod := getPodObjet()
pod, err := s.kubeClient.CoreV1().Pods(desiredPod.Namespace).Create(desiredPod)
if err != nil {
s.log.Fatal("Failed to create the static pod", zap.Error(err))
}
fmt.Println("Created Pod: ", pod.Name)
}
我试图检查该错误指向什么,似乎K8s客户端代码中的实际pod接口在这里:需要3个参数:一个是,我试图将值传递为:https://godoc.org/k8s.io/client-go/kubernetes/typed/core/v1#PodInterface"context.Context""pod *v1.Pod""opts metav1.CreateOptions"
pod, err :=s.kubeClient.CoreV1().Pods(desiredPod.Namespace).Create(context.Context, desiredPod, opts metav1.CreateOptions{})
但这也行不通。即使在IDE中,代码lint也指向缺少参数,但是我已经看到过几个示例,这些示例用于以上述方式创建以前工作过的Pod。
蓝山帝景
相关分类