相关代码如下:
import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/api/legacyscheme"
)
...
func PodExec(clusterId string, namespace string, podName string, containerName string, cmd string) (){
...
req.VersionedParams(&core.PodExecOptions{
Container: containerName,
Command: []string{"bash", "-c", cmd},
Stdin: false,
Stdout: true,
Stderr: true,
TTY: false,
}, legacyscheme.ParameterCodec) //FIXME Here is the concerned code.
}
...
glide.yaml
如下:
package: xxx-k8s-apiserver
import:
- package: github.com/astaxie/beego
version: v1.10.1
- package: k8s.io/api
subpackages:
- apps/v1
- core/v1
- package: k8s.io/apimachinery
subpackages:
- pkg/api/errors
- pkg/api/resource
- pkg/apis/meta/v1
- pkg/util/intstr
- pkg/util/yaml
- package: k8s.io/client-go
version: v10.0.0
当我go build
在我的项目中运行时,会出现这样的错误。
# xxx-k8s-apiserver/models
models/pod.go:82:3: cannot use legacyscheme.ParameterCodec (type "xxx-k8s-apiserver/vendor/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime".ParameterCodec) as type "xxx-k8s-apiserver/vendor/k8s.io/apimachinery/pkg/runtime".ParameterCodec in argument to req.VersionedParams:
"xxx-k8s-apiserver/vendor/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime".ParameterCodec does not implement "xxx-k8s-apiserver/vendor/k8s.io/apimachinery/pkg/runtime".ParameterCodec (wrong type for DecodeParameters method)
have DecodeParameters(url.Values, "xxx-k8s-apiserver/vendor/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/schema".GroupVersion, "xxx-k8s-apiserver/vendor/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime".Object) error
want DecodeParameters(url.Values, "xxx-k8s-apiserver/vendor/k8s.io/apimachinery/pkg/runtime/schema".GroupVersion, "xxx-k8s-apiserver/vendor/k8s.io/apimachinery/pkg/runtime".Object) error
然后我查看./vendor
目录,似乎glide
或dep
以某种方式错误地组织了依赖路径。依赖关系不是平坦的,因为vendor
在供应商路径中有另一个./vendor/k8s.io/kubernetes/vendor
。