无法从k8s获取client-go。

huangapple go评论92阅读模式
英文:

not able to get the client-go from k8s

问题

我尝试了我能想到的所有可能的方法,但我无法让基本示例与Kubernetes和Go语言一起工作。我对所有的godeps、gilde和govendor都很陌生,我承认这一点,但即使如此,我也不知道如何简单地获取这个在示例文件中引用的包。

具体来说,这是在这里写的 - https://github.com/kubernetes/client-go/tree/release-1.5

如何获取

你可以使用go get来获取client-go的一个版本,例如,go get k8s.io/client-go/1.4/... 或者 go get k8s.io/client-go/1.4/kubernetes。

当我执行这个命令时,输出如下 -

警告: "k8s.io/client-go/1.4/..." 没有匹配的包,无法加载包: package .: 在 /Users/shubhadeeproychowdhury/projects/go/src 中没有可构建的Go源文件。

尽管它在我的GOPATH的src目录下克隆了一些东西,放在了一个名为k8s的目录中。

最后,在同一个链接中,他们谈到了依赖管理和其他内容,其中提到了client-go目录下的1.4目录。但我在克隆的k8s目录中找不到那个目录。

我已经尝试了两天安装基本包并运行示例代码,但是无法成功。我感到非常尴尬和困惑。请问有人可以给我提供一份清晰的逐步说明,告诉我如何入门吗?

注意1:我有其他几个Go项目,到目前为止我都没有使用过依赖管理。我不想为了安装和使用这个项目而搞乱我的其他项目。我相信一定有办法。

注意2:我找到了这个链接 - https://stackoverflow.com/questions/37135933/samples-on-kubernetes-golang-client 但它没有解释如何克服获取到我的Go工作空间并运行示例代码的主要障碍。

Kubernetes的开发人员,如果你们在听,请在文档中更加详细地说明。我很愿意帮助改进文档,只是我现在不知道如何迈出第一步。

请帮帮我。

英文:

I have tried all the possible paths that I can think of, I am not able to put the base examples to work with kubernetes and Go lang. I am new to all the godeps, gilde, govendor thing, I will give myself that, but even then I have no idea how can I simply get this package which is referenced like this in the example file -

"k8s.io/client-go/1.4/kubernetes"
	"k8s.io/client-go/1.4/pkg/api"
	"k8s.io/client-go/1.4/tools/clientcmd"

And to be precise, this is what is written here - https://github.com/kubernetes/client-go/tree/release-1.5

> How to get it
>
> You can go get to get a release of client-go, e.g., go get
> k8s.io/client-go/1.4/... or go get k8s.io/client-go/1.4/kubernetes.

Now when I do this. This is the output -

> warning: "k8s.io/client-go/1.4/..." matched no packages can't load
> package: package .: no buildable Go source files in
> /Users/shubhadeeproychowdhury/projects/go/src

Although it clones things in a directory called k8s under src in my GOPATH.

Finally in the same link they are talking about dependency management and things, where they refer to a directory 1.4 under the client-do directory. I can not see that directory anywhere in the cloned k8s directory.

I have been trying to install the basic packages and run the example codes for two days now, I can't. I really feel awkward and strange. Can any one please help me with a clear step by step instructions on how to get started?

Note - 1: I have several other Go projects and I have not used dependency management so far. I do not want to mess up my other projects in order to try to install and use this one. I am sure there is way.

Note - 2: I have found this link - https://stackoverflow.com/questions/37135933/samples-on-kubernetes-golang-client But it does not explain to me how to get over the primary hurdle to get it in my Go workspace and run the example code.

Kubernetes people, if you are listening, please be a little bit more elaborate in your documentation if possible. I will be happy to lend a hand in that, it is just that I do not know how to take the frist step at this point of time.

Please help

答案1

得分: 2

我自己也遇到了同样的问题。以前我只需要运行go get k8s.io/client-go/1.4/kubernetes就可以了。但现在这个命令会失败,显示如下错误信息:

package k8s.io/client-go/1.4/kubernetes: cannot find package "k8s.io/client-go/1.4/kubernetes" in any of:

虽然文档提到了使用包管理工具,但我不想使用它们,因为Go本身已经有了vendor目录。我通过以下步骤解决了这个问题:

  1. 在项目根目录下创建vendor目录。
  2. 在vendor目录下创建k8s.io目录,这是为了修复库对自身的引用。
  3. k8s.io目录下执行git clone https://github.com/kubernetes/client-go.git
  4. client-go目录下执行git checkout v1.5.0(或者你想要的版本)。注意,要进行checkout,因为v1.4/v1.5只存在于特定的提交中,例如master分支已经没有这些版本了。
  5. 在你的项目中使用import k8s.io/client-go/1.5/kubernetes导入。
英文:

I had the same issue myself. Previously all I needed to do was go get k8s.io/client-go/1.4/kubernetes and I was good to go. Now that fails with:

package k8s.io/client-go/1.4/kubernetes: cannot find package "k8s.io/client-go/1.4/kubernetes" in any of:

While documentation mentions use of package management tools I did not want to use them as there is already vendor directory from Go itself. I was able to resolve the issue by doing this:

  1. Create vendor directory in your project root.
  2. In vendor directory create k8s.io directory. This is to fix references from the library to itself.
  3. In k8s.io directory do git clone https://github.com/kubernetes/client-go.git
  4. In client-go directory do git checkout v1.5.0 (or the version you want). Checkout is important as v1.4/v1.5 are only in specific commits. Master for example no longer have these.
  5. In your project import with k8s.io/client-go/1.5/kubernetes

答案2

得分: 0

假设你已经有一个glide.yaml文件,执行以下命令来获取一个包:glide get [package-name]。
在你的情况下,执行 glide get k8s.io/client-go/1.4/kubernetes 就可以了。

英文:

Do a glide get [package-name], assuming you already have a glide.yaml present.
In your case glide get k8s.io/client-go/1.4/kubernetes should do the trick.

huangapple
  • 本文由 发表于 2016年11月10日 22:59:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/40530682.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定