1
1
# Installing client-go
2
2
3
- ## For the casual user
3
+ ## Using the latest version
4
4
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:
8
6
9
7
``` sh
10
- go get k8s.io/client-go@master
8
+ go get k8s.io/client-go@latest
11
9
```
12
10
13
11
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,
17
15
and detailed dependency version info will be added to your ` go.mod ` file
18
16
(or you can also run ` go mod tidy ` to do this directly).
19
17
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
23
19
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:
25
22
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 ` :
34
25
35
- ### Enabling go modules
26
+ ``` sh
27
+
28
+ ```
36
29
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 ` :
41
32
42
33
``` sh
43
- export GO111MODULE=on
34
+
44
35
```
45
36
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
48
44
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:
49
51
``` sh
50
- go mod init
52
+
51
53
```
52
54
53
- ### Add client-go as a dependency
55
+ ### Conflicting requirements for older client-go versions
54
56
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 ` .
56
60
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
+
64
+ ```
59
65
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:
60
68
``` sh
61
- go get k8s.io/client-go@v0.17.0
69
+ go mod graph | grep " k8s.io/client-go@"
62
70
```
63
71
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
+
77
+ ```
78
+
79
+ ### Go modules disabled
70
80
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:
72
90
73
91
``` sh
74
-
92
+ export GO111MODULE=on
75
93
```
76
94
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