Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用go客户端接口创建Kubernetes crd_Kubernetes - Fatal编程技术网

无法使用go客户端接口创建Kubernetes crd

无法使用go客户端接口创建Kubernetes crd,kubernetes,Kubernetes,我按照上的示例创建了Kubernetes CRD 我的控制器工作正常,我可以监听CRD的创建/更新/删除事件。直到我尝试使用go客户端接口创建对象 这是我的CRD type MyEndpoint struct { metav1.TypeMeta `json:",inline"` // Standard object's metadata. // More info: https://git.k8s.io/community/contributors/devel/ap

我按照上的示例创建了Kubernetes CRD

我的控制器工作正常,我可以监听CRD的创建/更新/删除事件。直到我尝试使用go客户端接口创建对象

这是我的CRD

type MyEndpoint struct {
    metav1.TypeMeta   `json:",inline"`

    // Standard object's metadata.
    // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
    // +optional
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
}
我可以使用kubectl创建CRD定义和对象,没有任何问题。但是当我使用下面的代码创建对象时,我失败了

myepDeploy := &crdv1.MyEndpoint{
    TypeMeta: metav1.TypeMeta{
        Kind:       "MyEndpoint",
        APIVersion: "mydom.k8s.io/v1",
    },
    ObjectMeta: metav1.ObjectMeta{
        Name: podName,
        Labels: map[string]string{
            "serviceName": serviceName,
            "nodeIP": nodeName,
            "port": "5000"
        },
    },
}
epClient := myclientset.MycontrollerV1().MyEndpoints("default")
epClient.Create(myepDeploy)
但我犯了以下错误:

object *v1.MyEndpoint does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message
我看了看其他标准类型,不知道它们是否实现了这样的接口。我在谷歌上搜索,但没有得到任何运气


有什么想法吗?请帮忙。顺便说一句,我在minikube上跑步

对于大多数常见类型和简单类型,编组工作是开箱即用的。在结构更复杂的情况下,您可能需要手动实现编组接口


您可以尝试对MyEndpoint结构的一部分进行注释,以找出问题的确切原因

当您的客户端
epClient
尝试将
MyEndpoint
对象封送到protobuf时,会发生此错误。这是因为您的rest客户端配置。尝试将内容类型设置为
“application/json”

如果使用下面的代码生成配置,请更改内容类型

cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
    glog.Fatalf("Error building kubeconfig: %s", err.Error())
}

cfg.ContentType = "application/json"

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
    glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
}