@@ -19,34 +19,7 @@ and detailed dependency version info will be added to your `go.mod` file
19
19
20
20
This assumes you are using go modules with go 1.11+.
21
21
If you get a message like ` cannot use path@version syntax in GOPATH mode ` ,
22
- you can choose to [ opt into using go modules] ( #go-modules ) .
23
- If you are using a version of go prior to 1.11, or do not wish to use
24
- go modules, you can download ` k8s.io/client-go ` to your ` $GOPATH ` instead:
25
-
26
- ``` sh
27
- go get -u k8s.io/client-go/...
28
- go get -u k8s.io/apimachinery/...
29
- cd $GOPATH /src/k8s.io/client-go
30
- git checkout v11.0.0
31
- cd $GOPATH /src/k8s.io/apimachinery
32
- git checkout kubernetes-1.14.0
33
- ```
34
-
35
- This downloads a version of ` k8s.io/client-go ` prior to v1.12.0,
36
- which includes most of its dependencies in its ` k8s.io/client-go/vendor ` path
37
- (except for ` k8s.io/apimachinery ` and ` glog ` ).
38
-
39
- We excluded ` k8s.io/apimachinery ` and ` glog ` from ` k8s.io/client-go/vendor ` to
40
- prevent ` go get ` users from hitting issues like
41
- [ #19 ] ( https://github.com/kubernetes/client-go/issues/19 ) and
42
- [ #83 ] ( https://github.com/kubernetes/client-go/issues/83 ) . If your project shares
43
- other dependencies with client-go, and you hit issues similar to #19 or #83 ,
44
- then you'll need to look down at the next section.
45
-
46
- Note: the official go policy is that libraries should not vendor their
47
- dependencies. This was unworkable for us, since our dependencies change and HEAD
48
- on every dependency has not necessarily been tested with client-go. In fact,
49
- HEAD from all dependencies may not even compile with client-go!
22
+ see the instructions for [ enabling go modules] ( #enabling-go-modules ) .
50
23
51
24
## Dependency management for the serious (or reluctant) user
52
25
@@ -59,15 +32,10 @@ Reasons why you might need to use a dependency management system:
59
32
* You want your install to be reproducible. For example, for your CI system or
60
33
for new team members.
61
34
62
- There are three tools you could in theory use for this. Instructions
63
- for each follows.
64
-
65
- ### Go modules
35
+ ### Enabling go modules
66
36
67
37
Dependency management tools are built into go 1.11+ in the form of [ go modules] ( https://github.com/golang/go/wiki/Modules ) .
68
- These are used by the main Kubernetes repo (>= 1.15) and ` client-go ` (on master, and v12.0.0+) to manage dependencies.
69
- When using ` client-go ` v12.0.0+ and go 1.11.4+, go modules are the recommended dependency management tool.
70
-
38
+ These are used by the main Kubernetes repo (>= ` v1.15.0 ` ) and ` client-go ` (>= ` kubernetes-1.15.0 ` ) to manage dependencies.
71
39
If you are using go 1.11 or 1.12 and are working with a project located within ` $GOPATH ` ,
72
40
you must opt into using go modules:
73
41
@@ -82,117 +50,16 @@ If you do not already have one, `go mod init` will create one for you:
82
50
go mod init
83
51
```
84
52
85
- Indicate which version of ` client-go ` your project requires.
86
- For ` client-go ` on v12.0.0 (and later), this is a single step:
87
-
88
- ``` sh
89
-
90
- ```
53
+ ### Add client-go as a dependency
91
54
92
- For ` client-go ` prior to v12.0.0, you also need to indicate the required versions of ` k8s.io/api ` and ` k8s.io/apimachinery ` :
55
+ Indicate which version of ` client-go ` your project requires (replace ` kubernetes-1.15.0 ` with the desired version) :
93
56
94
57
``` sh
95
- go get k8s.io/
[email protected] # replace v11.0.0 with the required version (or use kubernetes-1.x.y tags if desired)
96
- go get k8s.io/
[email protected] # replace kubernetes-1.14.0 with the required version
97
- go get k8s.io/
[email protected] # replace kubernetes-1.14.0 with the required version
58
+
98
59
```
99
60
100
61
You can now import and use the ` k8s.io/client-go ` APIs in your project.
101
62
The next time you ` go build ` , ` go test ` , or ` go run ` your project,
102
63
` k8s.io/client-go ` and its dependencies will be downloaded (if needed),
103
64
and detailed dependency version info will be added to your ` go.mod ` file
104
- (or you can also run ` go mod tidy ` to do this directly).
105
-
106
- ### Glide
107
-
108
- [ Glide] ( https://github.com/Masterminds/glide ) is another popular dependency
109
- management tool for Go. Glide will manage your /vendor directory, but unlike
110
- godep, will not use or modify your $GOPATH (there's no equivalent of
111
- ` godep restore ` or ` godep save ` ).
112
-
113
- Generally, it's best to avoid Glide's many subcommands, favoring modifying
114
- Glide's manifest file (` glide.yaml ` ) directly, then running
115
- ` glide update --strip-vendor ` . First create a ` glide.yaml ` file at the root of
116
- your project:
117
-
118
- ``` yaml
119
- package : ( your project's import path ) # e.g. github.com/foo/bar
120
- import :
121
- - package : k8s.io/client-go
122
- version : v12.0.0 # replace v12.0.0 with the required version
123
- ` ` `
124
-
125
- Second, add a Go file that imports ` client-go` somewhere in your project,
126
- otherwise `client-go`'s dependencies will not be added to your project's
127
- vendor/. Then run the following command in the same directory as `glide.yaml` :
128
-
129
- ` ` ` sh
130
- glide update --strip-vendor
131
- ` ` `
132
-
133
- This can also be abbreviated as :
134
-
135
- ` ` ` sh
136
- glide up -v
137
- ` ` `
138
-
139
- At this point, `k8s.io/client-go` should be added to your project's vendor/.
140
- ` client-go` ' s dependencies should be flattened and be added to your project' s
141
- vendor/ as well.
142
-
143
- Glide will detect the versions of dependencies `client-go` specified in
144
- ` client-go` ' s Godep.json file, and automatically set the versions of these
145
- imports in your /vendor directory. It will also record the detected version of
146
- all dependencies in the `glide.lock` file.
147
-
148
- Projects that require a different version of a dependency than `client-go`
149
- requests can override the version manually in `glide.yaml`. For example:
150
-
151
- ```yaml
152
- package: ( your project' s import path ) # e.g. github.com/foo/bar
153
- import :
154
- - package : k8s.io/client-go
155
- version : v12.0.0 # replace v12.0.0 with the required version
156
- # Use a newer version of go-spew even though client-go wants an old one.
157
- - package : github.com/davecgh/go-spew
158
- version : v1.1.0
159
- ` ` `
160
-
161
- After modifying, run ` glide up -v` again to re-populate your /vendor directory.
162
-
163
- Optionally, Glide users can also use [`glide-vc`](https://github.com/sgotti/glide-vc)
164
- after running `glide up -v` to remove unused files from /vendor.
165
-
166
- # ## Godep
167
-
168
- [godep](https://github.com/tools/godep) is an older dependency management tool, which was
169
- used by the main Kubernetes repo (<= 1.14) and `client-go` (<= v11.0) to manage dependencies.
170
-
171
- Before proceeding with the below instructions, you should ensure that your
172
- $GOPATH is empty except for containing your own package and its dependencies,
173
- and you have a copy of godep somewhere in your $PATH.
174
-
175
- To install `client-go` and place its dependencies in your `$GOPATH` :
176
-
177
- ` ` ` sh
178
- go get k8s.io/client-go/...
179
- cd $GOPATH/src/k8s.io/client-go
180
- git checkout v11.0.0 # v11.0.0 or older
181
- # cd 1.5 # only necessary with 1.5 and 1.4 clients.
182
- godep restore ./...
183
- ` ` `
184
-
185
- At this point, `client-go`'s dependencies have been placed in your $GOPATH, but
186
- if you were to build, `client-go` would still see its own copy of its
187
- dependencies in its `vendor` directory. You have two options at this point.
188
-
189
- If you would like to keep dependencies in your own project's vendor directory,
190
- then you can continue like this :
191
-
192
- ` ` ` sh
193
- cd $GOPATH/src/<my-pkg>
194
- godep save ./...
195
- ` ` `
196
-
197
- Alternatively, if you want to build using the dependencies in your `$GOPATH`,
198
- then `rm -rf vendor/` to remove `client-go`'s copy of its dependencies.
65
+ (or you can also run ` go mod tidy ` to do this directly).
0 commit comments