Skip to content

Commit 4d5868a

Browse files
authored
Merge pull request kubernetes#99741 from liggitt/client-go-install
Update client-go install instructions
2 parents 9ed4d94 + 41c12a8 commit 4d5868a

File tree

1 file changed

+63
-44
lines changed

1 file changed

+63
-44
lines changed
+63-44
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Installing client-go
22

3-
## For the casual user
3+
## Using the latest version
44

5-
If you want to write a simple script, don't care about a reproducible client
6-
library install, don't mind getting HEAD (which may be less stable than a
7-
particular release), then simply:
5+
If you want to use the latest version of this library, use go1.16+ and run:
86

97
```sh
10-
go get k8s.io/client-go@master
8+
go get k8s.io/client-go@latest
119
```
1210

1311
This will record a dependency on `k8s.io/client-go` in your go module.
@@ -17,65 +15,86 @@ The next time you `go build`, `go test`, or `go run` your project,
1715
and detailed dependency version info will be added to your `go.mod` file
1816
(or you can also run `go mod tidy` to do this directly).
1917

20-
This assumes you are using go modules with go 1.11+.
21-
If you get a message like `cannot use path@version syntax in GOPATH mode`,
22-
see the instructions for [enabling go modules](#enabling-go-modules).
18+
## Using a specific version
2319

24-
## Dependency management for the serious (or reluctant) user
20+
If you want to use a particular version of the `k8s.io/client-go` library,
21+
you can indicate which version of `client-go` your project requires:
2522

26-
Reasons why you might need to use a dependency management system:
27-
* You use a dependency that client-go also uses, and don't want two copies of
28-
the dependency compiled into your application. For some dependencies with
29-
singletons or global inits (e.g. `glog`) this wouldn't even compile...
30-
* You want to lock in a particular version (so you don't have to change your
31-
code every time we change a public interface).
32-
* You want your install to be reproducible. For example, for your CI system or
33-
for new team members.
23+
- If you are using Kubernetes versions >= `v1.17.0`, use a corresponding `v0.x.y` tag.
24+
For example, `k8s.io/[email protected]` corresponds to Kubernetes `v1.20.4`:
3425

35-
### Enabling go modules
26+
```sh
27+
go get k8s.io/[email protected]
28+
```
3629

37-
Dependency management tools are built into go 1.11+ in the form of [go modules](https://github.com/golang/go/wiki/Modules).
38-
These are used by the main Kubernetes repo (>= `v1.15.0`) and `client-go` (>= `kubernetes-1.15.0`) to manage dependencies.
39-
If you are using go 1.11 or 1.12 and are working with a project located within `$GOPATH`,
40-
you must opt into using go modules:
30+
- If you are using Kubernetes versions < `v1.17.0`, use a corresponding `kubernetes-1.x.y` tag.
31+
For example, `k8s.io/[email protected]` corresponds to Kubernetes `v1.16.3`:
4132

4233
```sh
43-
export GO111MODULE=on
34+
go get k8s.io/[email protected]
4435
```
4536

46-
Ensure your project has a `go.mod` file defined at the root of your project.
47-
If you do not already have one, `go mod init` will create one for you:
37+
You can now import and use the `k8s.io/client-go` APIs in your project.
38+
The next time you `go build`, `go test`, or `go run` your project,
39+
`k8s.io/client-go` and its dependencies will be downloaded (if needed),
40+
and detailed dependency version info will be added to your `go.mod` file
41+
(or you can also run `go mod tidy` to do this directly).
42+
43+
## Troubleshooting
4844

45+
### Go versions prior to 1.16
46+
47+
If you get a message like
48+
`module k8s.io/client-go@latest found (v1.5.2), but does not contain package k8s.io/client-go/...`,
49+
you are likely using a go version prior to 1.16 and must explicitly specify the k8s.io/client-go version you want.
50+
For example:
4951
```sh
50-
go mod init
52+
go get k8s.io/[email protected]
5153
```
5254

53-
### Add client-go as a dependency
55+
### Conflicting requirements for older client-go versions
5456

55-
Indicate which version of `client-go` your project requires:
57+
If you get a message like
58+
`module k8s.io/api@latest found, but does not contain package k8s.io/api/auditregistration/v1alpha1`,
59+
something in your build is likely requiring an old version of `k8s.io/client-go` like `v11.0.0+incompatible`.
5660

57-
- If you are using Kubernetes versions >= `v1.17.0`, use a corresponding
58-
`v0.x.y` tag. For example, `k8s.io/[email protected]` corresponds to Kubernetes `v1.17.0`:
61+
First, try to fetch a more recent version. For example:
62+
```sh
63+
go get k8s.io/[email protected]
64+
```
5965

66+
If that doesn't resolve the problem, see what is requiring an `...+incompatible` version of client-go,
67+
and update to use a newer version of that library, if possible:
6068
```sh
61-
go get k8s.io/client-go@v0.17.0
69+
go mod graph | grep " k8s.io/client-go@"
6270
```
6371

64-
You can also use a non-semver `kubernetes-1.x.y` tag to refer to a version
65-
of `client-go` corresponding to a given Kubernetes release. Prior to Kubernetes
66-
`v1.17.0` these were the only tags available for use with go modules.
67-
For example, `kubernetes-1.16.3` corresponds to Kubernetes `v1.16.3`.
68-
However, it is recommended to use semver-like `v0.x.y` tags over non-semver
69-
`kubernetes-1.x.y` tags to have a seamless experience with go modules.
72+
As a last resort, you can force the build to use a specific version of client-go,
73+
even if some of your dependencies still want `...+incompatible` versions. For example:
74+
```sh
75+
go mod edit -replace=k8s.io/client-go=k8s.io/[email protected]
76+
go get k8s.io/[email protected]
77+
```
78+
79+
### Go modules disabled
7080

71-
- If you are using Kubernetes versions < `v1.17.0` (replace `kubernetes-1.16.3` with the desired version):
81+
If you get a message like `cannot use path@version syntax in GOPATH mode`,
82+
you likely do not have go modules enabled.
83+
84+
Dependency management tools are built into go 1.11+ in the form of
85+
[go modules](https://github.com/golang/go/wiki/Modules).
86+
These are used by the main Kubernetes repo (>= `v1.15.0`) and
87+
`client-go` (>= `kubernetes-1.15.0`) to manage dependencies.
88+
If you are using go 1.11 or 1.12 and are working with a project located within `$GOPATH`,
89+
you must opt into using go modules:
7290

7391
```sh
74-
go get k8s.io/[email protected]
92+
export GO111MODULE=on
7593
```
7694

77-
You can now import and use the `k8s.io/client-go` APIs in your project.
78-
The next time you `go build`, `go test`, or `go run` your project,
79-
`k8s.io/client-go` and its dependencies will be downloaded (if needed),
80-
and detailed dependency version info will be added to your `go.mod` file
81-
(or you can also run `go mod tidy` to do this directly).
95+
Ensure your project has a `go.mod` file defined at the root of your project.
96+
If you do not already have one, `go mod init` will create one for you:
97+
98+
```sh
99+
go mod init
100+
```

0 commit comments

Comments
 (0)