My golang service uses k8s go api to communicate with Kubernetes clusters. Some of them are v1.9.6, while some clusters of v1.17.0 were recently added.
I am using go.mod to manage dependencies. However I am having trouble combining dependencies of different versions.
For example using dependencies for the old API look like this:
module k8sOld
go 1.13
replace k8s.io/api => k8s.io/api v0.0.0-20180127130940-acf347b865f2
require (
k8s.io/api v0.0.0-20180127130940-acf347b865f2
k8s.io/apimachinery v0.0.0-20180126010752-19e3f5aa3adc
k8s.io/client-go v6.0.1-0.20180321184741-e56f95336983+incompatible
k8s.io/kube-openapi v0.0.0-20200615155156-dffdd1682719
)
When I added newer version of Kubernetes API I tried it like this:
module k8sOld
go 1.13
replace k8s.io/api => k8s.io/api v0.0.0-20180127130940-acf347b865f2
replace k8s.io/api/new => k8s.io/api v0.17.0
require (
k8s.io/api v0.0.0-20180127130940-acf347b865f2
k8s.io/apimachinery v0.0.0-20180126010752-19e3f5aa3adc
k8s.io/client-go v6.0.1-0.20180321184741-e56f95336983+incompatible
k8s.io/kube-openapi v0.0.0-20200615155156-dffdd1682719
k8s.io/api v0.17.0
k8s.io/apimachinery v0.17.0
k8s.io/client-go v0.17.0
)
I named the package for new packages “k8s.io/{subpackage}/new” and used replace to point to the newer version.
I am not sure if this is ok and that is the first question.
The second and most basic one is ,supposing I find a way to refer to newer version, how can I refer subpackages of packages?
For example how can I use k8s.io/api/core/v1?
“k8s.io/api/{VERSION NAMING CONVENTION}/core/v1”
I tried naming it, but it does not seem to work.
I also tried adding k8s.io/api/core/v1 {version number}
to the require
part of go.mod, but it cannot be used this way.
Any ideas on how I can use different versions of k8s go api under the same hood?