For kubernetes v1.7, compatibility matrix suggest 4.0.beta.0 version of client-go.
After upgrading the version to 4.0.beta.0, I get bellow compilation errors:
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:897: in.ObjectMeta.DeepCopyInto undefined (type v1.ObjectMeta has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1013: in.ObjectMeta.DeepCopyInto undefined (type v1.ObjectMeta has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1079: in.ObjectMeta.DeepCopyInto undefined (type v1.ObjectMeta has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1440: in.StartedAt.DeepCopyInto undefined (type v1.Time has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1457: in.StartedAt.DeepCopyInto undefined (type v1.Time has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1458: in.FinishedAt.DeepCopyInto undefined (type v1.Time has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1788: in.ObjectMeta.DeepCopyInto undefined (type v1.ObjectMeta has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1967: in.ObjectMeta.DeepCopyInto undefined (type v1.ObjectMeta has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1970: in.FirstTimestamp.DeepCopyInto undefined (type v1.Time has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1971: in.LastTimestamp.DeepCopyInto undefined (type v1.Time has no field or method DeepCopyInto)
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go:1971: too many errors
Is there any ETA on how to fix this? Right now the tag v.4.0.0-beta.0 is totally unusable for us as well. I believe this also block others as well who upgraded recently to Kubernetes v1.7 and want to use the compatible Go client with it.
k8s.io/api shouldn't be vendored for 1.7. This is unreleased code from kube master branch. Something is wrong with your vendoring. It looks like you try to use it with k8s.io/apimachinery from 1.7. That's gonna break.
@sttts you mean apimachinery from kube master, right?
Thanks @sttts for the information. Where can I get the information on which api & apimachinery I should lock my dependencies so I can use the v4.0.0-beta0 branch ?
@fatih I just went through this with a clean GOPATH. I'll have details in just a minute.
go get github.com/tools/godepgo get k8s.io/client-gocd $GOPATH/src/k8s.io/client-gogit checkout v4.0.0-beta0godep restoreIf you are also vendoring kube/kube code, I would recommend you check out the latest v1.7.x tag for it.
In addition, k8s.io/apimachinery should use branch release-1.7 and k8s.io/apiextensions-apiserver should use commit be41f5093e2b05c7a0befe35b04b715eb325ab43.
@fatih I think I figured out that what which version client-go is compatible with new apimachinery. Try out these revisions this may help.
- package: k8s.io/apimachinery
version: 12d70001ef0c75fc5a26057ca73d3caf5e2cf682
- package: k8s.io/api
- package: k8s.io/client-go
version: 45673e060eb921b510677b1123737ad1158e49fa
k8s.io/api should not be needed. It is unreleased alpha quality code. If you happen to need that, something with your vendoring is broken (or you really want the latest and greatest alpha quality code).
Can we close this issue? If you use v4.0.0-beta.0, everything will work. I wrote a blog post on how to do this using godep, and you can achieve similar results using tools like dep, govendor, and glide.
Thanks all. The blog post from @ncdc was sufficient. We don't use Godeps, instead we use govendor. Because we already have client-go vendored to v2.0.0, these were the steps I've done:
# remove old client-go and vendor v4.0.0-beta.0
$ govendor remove k8s.io/client-go/...
$ rm -rf $GOPATH/k8s.io
$ govendor fetch k8s.io/client-go/^@=v4.0.0-beta.0
# get the correct git sha for the sub dependencies (i.e apimachinery)
$ cd $GOPATH/k8s.io/client-go/Godeps
$ vi Godeps.json
# re-vendor the correct apimachinery
$ govendor fetch k8s.io/apimachinery/...@abe34e4f5b4413c282a83011892cbeea5b32223b
After upgrading from v2.0.0 to v4.0.0-beta0 we also had to change some import paths, types and functions as it's not a backwards compatible version. Below is a script we use for our own monorepo. Note that the commands might be different for you own, but just adding them so you know how you can use all the tools like sed, gofmt, govers, etc.. to refactor a large scale monorepo. I know there could be better options and I wish that the upgrade to v4.0.0-beta0 was backwards compatible change. I assume they will be another break after the k8s.ioa/api split but that's a future thing. It was not easy to upgrade and hope going gorward it'll be better with time.
Here is the script (note that even with that, you might have to manually make changes to the codebase):
#!/bin/bash
set -e
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
# our monorepo code
pushd "$GOPATH/do"
read -d '' imports << "EOF"
k8s.io/client-go/pkg/api/resource k8s.io/apimachinery/pkg/api/resource
k8s.io/client-go/pkg/labels k8s.io/apimachinery/pkg/labels
k8s.io/client-go/pkg/util/validation k8s.io/apimachinery/pkg/util/validation
k8s.io/client-go/pkg/api/errors k8s.io/apimachinery/pkg/api/errors
k8s.io/client-go/pkg/api/meta k8s.io/apimachinery/pkg/apis/meta/v1
k8s.io/client-go/pkg/api/unversioned k8s.io/apimachinery/pkg/apis/meta/v1
k8s.io/client-go/pkg/runtime k8s.io/apimachinery/pkg/runtime
k8s.io/client-go/pkg/runtime/serializer k8s.io/apimachinery/pkg/runtime/serializer
k8s.io/client-go/pkg/fields k8s.io/apimachinery/pkg/fields
k8s.io/client-go/pkg/util/intstr k8s.io/apimachinery/pkg/util/intstr
k8s.io/client-go/pkg/selection k8s.io/apimachinery/pkg/selection
k8s.io/client-go/pkg/watch k8s.io/apimachinery/pkg/watch
EOF
echo "==> Renaming imports ..."
while read -r line; do
deps=($line)
govers -d -m ${deps[0]}$ ${deps[1]}
done <<< "$imports"
pushd "teams/delivery"
echo "==> Renaming types ..."
find . -name '*.go' -exec sed -i '' -- 's:unversioned.TypeMeta:metav1.TypeMeta:' {} \; \
-exec sed -i '' -- 's:unversioned.ListMeta:metav1.ListMeta:' {} \; \
-exec sed -i '' -- 's:unversioned.List:metav1.List:' {} \; \
-exec sed -i '' -- 's:unversioned.NewTime:metav1.NewTime:' {} \; \
-exec sed -i '' -- 's:unversioned.Now:metav1.Now:' {} \; \
-exec sed -i '' -- 's:unversioned.LabelSelector:metav1.LabelSelector:' {} \; \
-exec sed -i '' -- 's:meta.Object:metav1.Object:' {} \; \
-exec sed -i '' -- 's:unversioned.ObjectKind:schema.ObjectKind:' {} \; \
-exec sed -i '' -- 's:unversioned.GroupVersion:schema.GroupVersion:' {} \; \
-exec sed -i '' -- 's:unversioned.GroupResource:schema.GroupResource:' {} \; \
-exec sed -i '' -- 's:v1.ObjectMeta:metav1.ObjectMeta:' {} \; \
-exec sed -i '' -- 's:v1.GetReference:reference.GetReference:' {} \; \
-exec sed -i '' -- 's:"k8s.io/apimachinery/pkg/apis/meta/v1":metav1 "k8s.io/apimachinery/pkg/apis/meta/v1":' {} \; \
-exec sed -i '' -- 's:v1.DeleteOptions:metav1.DeleteOptions:' {} \; \
-exec sed -i '' -- 's:v1.ListOptions:metav1.ListOptions:' {} \;
echo "==> Rewriting functions..."
gofmt -w -r='a.CronJobs(b).Get(c) -> a.CronJobs(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.Jobs(b).Get(c) -> a.Jobs(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.ConfigMaps(b).Get(c) -> a.ConfigMaps(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.ReplicaSets(b).Get(c) -> a.ReplicaSets(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.Deployments(b).Get(c) -> a.Deployments(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.Pods(b).Get(c) -> a.Pods(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.Services(b).Get(c) -> a.Services(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.Ingresses(b).Get(c) -> a.Ingresses(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.PersistentVolumes(b).Get(c) -> a.PersistentVolumes(b).Get(c, metav1.GetOptions{})' ./..
gofmt -w -r='a.Secrets(b).Get(c) -> a.Secrets(b).Get(c, metav1.GetOptions{})' ./..
echo "==> Formatting files and adding unimported packages..."
goimports -w ./..
popd
popd
Could you possibly provide direction for users of glide? I tried using the following:
- package: k8s.io/client-go/rest
version: v4.0.0-beta.0
- package: k8s.io/client-go/tools/clientcmd
version: v4.0.0-beta.0
- package: k8s.io/kubernetes/pkg/kubectl/cmd
version: v1.7.6
But I still get the compilation errors.
Most helpful comment
Can we close this issue? If you use v4.0.0-beta.0, everything will work. I wrote a blog post on how to do this using
godep, and you can achieve similar results using tools likedep,govendor, andglide.