Vendoring Kubernetes
2019-09-06Despite using Kubernetes as a module is not encouraged, there are some projects that are following this approach.
In order to make this easier, now that we have go modules in
Kubernetes, I wrote a small tool called vendor-kubernetes
.
It is highly recommended that you have kubernetes
cloned into a
directory, along with all the staging repositories that will be
reported on the resulting go.mod
file, such as:
~ > tree -L 1 ~/projects/go/src/k8s.io /home/ereslibre/projects/go/src/k8s.io ├── api ├── apiextensions-apiserver ├── apimachinery ├── apiserver ├── autoscaler ├── client-go ├── cli-runtime ├── cloud-provider ├── cluster-bootstrap ├── code-generator ├── component-base ├── cri-api ├── csi-translation-lib ├── kops ├── kubeadm ├── kube-aggregator ├── kube-controller-manager ├── kubectl ├── kubelet ├── kube-proxy ├── kubernetes ├── kube-scheduler ├── legacy-cloud-providers ├── metrics ├── node-api ├── sample-apiserver ├── sample-cli-plugin ├── sample-controller ├── test-infra └── website 30 directories, 0 files
The usage is very straightforward, you have to pass a
--kubernetes-version
argument, and optionally a --kubernetes-path
argument, like:
~/p/g/s/g/e/vendor-kubernetes (master) > go run -mod=vendor main.go --kubernetes-tag 1.16.0-beta.1 --kubernetes-path ~/projects/go/src/k8s.io require ( k8s.io/kubernetes v1.16.0-beta.1 ) replace ( k8s.io/api => k8s.io/api v0.0.0-20190822053644-6185379c914a k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190822063004-0670dc4fec4e k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190820074809-31b1e1ea64dc k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190822060508-785eacbd19ae k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190822063658-442a64f3fed7 k8s.io/client-go => k8s.io/client-go v0.0.0-20190822054823-0a74433fb222 k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190822065847-2058b41dfbb6 k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20190822065536-566e5fc137f7 k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190820100630-060a3d12ce80 k8s.io/component-base => k8s.io/component-base v0.0.0-20190822055535-1f6a258f5d89 k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190820110325-95eec93e2395 k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20190822070154-f51cd605b3ee k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20190822061015-a4f93a8219ed k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20190822065235-826221481525 k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20190822064323-7e0495d8a3ff k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20190822064931-4470440ed041 k8s.io/kubectl => k8s.io/kubectl v0.0.0-20190822071625-14af4a63a1e1 k8s.io/kubelet => k8s.io/kubelet v0.0.0-20190822064626-fa8f3d935631 k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20190822070624-3a30a18bba71 k8s.io/metrics => k8s.io/metrics v0.0.0-20190822063337-6c03eb8600ee k8s.io/node-api => k8s.io/node-api v0.0.0-20190822070940-24e163ffb9e7 k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20190822061642-ab22eab63834 k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.0.0-20190822064016-bcca3cc588da k8s.io/sample-controller => k8s.io/sample-controller v0.0.0-20190822062306-1b561d990eb5 )
If you are missing any of the mentioned dependencies,
vendor-kubernetes
will clone it in memory and resolve the date and
commit in an automatic fashion:
~/p/g/s/g/e/vendor-kubernetes (master) > rm -rf ~/projects/go/src/k8s.io/cluster-bootstrap/ ~/p/g/s/g/e/vendor-kubernetes (master) > go run -mod=vendor main.go --kubernetes-tag 1.16.0-beta.1 --kubernetes-path ~/projects/go/src/k8s.io project /home/ereslibre/projects/go/src/k8s.io/cluster-bootstrap not found; cloning project https://github.com/kubernetes/cluster-bootstrap in memory require ( k8s.io/kubernetes v1.16.0-beta.1 ) replace ( k8s.io/api => k8s.io/api v0.0.0-20190822053644-6185379c914a k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190822063004-0670dc4fec4e k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190820074809-31b1e1ea64dc k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190822060508-785eacbd19ae k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190822063658-442a64f3fed7 k8s.io/client-go => k8s.io/client-go v0.0.0-20190822054823-0a74433fb222 k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190822065847-2058b41dfbb6 k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20190822065536-566e5fc137f7 k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190820100630-060a3d12ce80 k8s.io/component-base => k8s.io/component-base v0.0.0-20190822055535-1f6a258f5d89 k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190820110325-95eec93e2395 k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20190822070154-f51cd605b3ee k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20190822061015-a4f93a8219ed k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20190822065235-826221481525 k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20190822064323-7e0495d8a3ff k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20190822064931-4470440ed041 k8s.io/kubectl => k8s.io/kubectl v0.0.0-20190822071625-14af4a63a1e1 k8s.io/kubelet => k8s.io/kubelet v0.0.0-20190822064626-fa8f3d935631 k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20190822070624-3a30a18bba71 k8s.io/metrics => k8s.io/metrics v0.0.0-20190822063337-6c03eb8600ee k8s.io/node-api => k8s.io/node-api v0.0.0-20190822070940-24e163ffb9e7 k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20190822061642-ab22eab63834 k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.0.0-20190822064016-bcca3cc588da k8s.io/sample-controller => k8s.io/sample-controller v0.0.0-20190822062306-1b561d990eb5 )
Please, note that Kubernetes itself is not meant to be used as a
module (subcomponents are). In the meantime, this tool can help you to
get your go.mod
right.
GitHub repository: https://github.com/ereslibre/vendor-kubernetes