[Windows] GoLand 加载 k8s v1.14或之前版本 源码

先说结论:

别试了。

从k8s v1.15源码起,依赖管理才开始使用go module。

在此之前,包括v1.14各版本的依赖管理都是用的是godep,见官方文档。

这里记录为了下载依赖做过的尝试:

尝试1

To extract and download dependencies into $GOPATH we provide a script: hack/godep-restore.sh. If you run this tool, it will restore into your own $GOPATH. If you wrap it in run-in-gopath.sh it will restore into your _output/ directory.

– https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/godep.md

如果使用v1.14项目中的工具:hack/run-in-gopath.sh hack/godep-restore.sh -v,在Windows环境下会报错:

➜ kubernetes (release-1.14) hack/run-in-gopath.sh hack/godep-restore.sh -v
!!! [0913 16:08:57] Unsupported host OS.  Must be Linux or Mac OS X.
ln: /c/Users/dell/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/kubernetes: cannot overwrite directory
!!! [0913 16:09:18] Call tree:
!!! [0913 16:09:18]  1: /c/Users/dell/go/src/k8s.io/kubernetes/hack/lib/golang.sh:496 kube::golang::create_gopath_tree(...)
!!! [0913 16:09:18]  2: hack/run-in-gopath.sh:30 kube::golang::setup_env(...)
!!! Error in /c/Users/dell/go/src/k8s.io/kubernetes/hack/lib/golang.sh:439
  Error in /c/Users/dell/go/src/k8s.io/kubernetes/hack/lib/golang.sh:439. 'ln -snf "${KUBE_ROOT}" "${go_pkg_dir}"' exited with status 1
Call stack:
  1: /c/Users/dell/go/src/k8s.io/kubernetes/hack/lib/golang.sh:439 kube::golang::create_gopath_tree(...)
  2: /c/Users/dell/go/src/k8s.io/kubernetes/hack/lib/golang.sh:496 kube::golang::setup_env(...)
  3: hack/run-in-gopath.sh:30 main(...)
Exiting with status 1

尝试2

如果强行go mod init ..., go mod tidy 会出现部分依赖载入版本不匹配(默认会去下载latest),导致GoLand中部分调用跳转无法使用。

尝试3

在k8s项目GitHub repo中找go.mod最早出现的版本:

从历史版本列表:https://github.com/kubernetes/kubernetes/commits/release-1.15?after=a34f1e483104bd51c3e9a6aec3dbbcf6301789da+34&branch=release-1.15&path[]=go.mod&qualified_name=refs%2Fheads%2Frelease-1.15

可以看出,最早的有效submit是在v1.15.0-alpha.1 https://github.com/kubernetes/kubernetes/commit/d0261b10770210f83edbcfe379db24e1b82a9e86

结语

希望这段弯路分享能节省你的时间。

你可能感兴趣的:(windows,kubernetes)