Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect repository layour for v2 Go Modules #239

Closed
alex1989hu opened this issue Jan 16, 2020 · 12 comments · Fixed by #240 or #265
Closed

Incorrect repository layour for v2 Go Modules #239

alex1989hu opened this issue Jan 16, 2020 · 12 comments · Fixed by #240 or #265

Comments

@alex1989hu
Copy link
Contributor

It is impossible to use repository with Go Modules because it breaks the mandatory requirements for v2.

It works with v1.2.2 but not with v2.0.0.
https://sum.golang.org/lookup/github.com/kubernetes-csi/[email protected]

$ go get -v github.com/kubernetes-csi/[email protected]
go: finding github.com/kubernetes-csi/external-snapshotter v2.0.0
go: finding github.com/kubernetes-csi/external-snapshotter v2.0.0
go: errors parsing go.mod
go.mod:10: require github.com/kubernetes-csi/external-snapshotter: version "v2.0.0" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

Details and requirements:

@xing-yang
Copy link
Collaborator

Hi @pohly, can you take a look?

@pohly
Copy link
Contributor

pohly commented Jan 17, 2020

@xing-yang you need to do something similar to kubernetes-csi/csi-test#232

You can probably drop the "dep" compatibility symlinks. This seems less important for external-snapshotter than it was for csi-test.

@alex1989hu
Copy link
Contributor Author

@xing-yang you need to do something similar to kubernetes-csi/csi-test#232

You can probably drop the "dep" compatibility symlinks. This seems less important for external-snapshotter than it was for csi-test.

Agree, drop the dep compatibility.

@alex1989hu
Copy link
Contributor Author

If I understood well the documentation, a new tag should be also added once v2 is in to let dependant project use the implementations here. But it needs a deep dive into docs.

@pohly
Copy link
Contributor

pohly commented Jan 17, 2020

If I understood well the documentation, a new tag should be also added once v2 is in to let dependant project use the implementations here.

That's correct. The existing v2.0.0 release needs to be replaced by a v2.0.1.

@xing-yang
Copy link
Collaborator

I'm still getting the same error after merging the fix and cutting the v2.0.1 release:

# go get -v github.com/kubernetes-csi/[email protected]
go: finding github.com/kubernetes-csi/external-snapshotter v2.0.1
go: finding github.com/kubernetes-csi/external-snapshotter v2.0.1
go get github.com/kubernetes-csi/[email protected]: github.com/kubernetes-csi/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

I tried csi-test, but it also does not work for me.

# go get -v github.com/kubernetes-csi/[email protected]
go: finding github.com/kubernetes-csi/csi-test v3.0.0
go: finding github.com/kubernetes-csi/csi-test v3.0.0
go get github.com/kubernetes-csi/[email protected]: github.com/kubernetes-csi/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3

Reopen this issue.
@alex1989hu let me know if it works for you now.
@pohly any comments?

@xing-yang xing-yang reopened this Jan 23, 2020
@alex1989hu
Copy link
Contributor Author

The original issue is solved, dependency can be resolved now. You can check it: https://sum.golang.org/lookup/github.com/kubernetes-csi/external-snapshotter/[email protected]

code-generator remains only.

Example go.mod

 module github.com/foo/bar

 go 1.13

 require (
     github.com/kubernetes-csi/external-snapshotter/v2 v2.0.1
 )

Import statements have to be updated to use it correctly:

package main

import (
snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
)

// Your code here

@alex1989hu
Copy link
Contributor Author

I think it is a defect of code-generator: incorrectly resolve package path => wants to write into v2 directory instead of resolving v2 as package path. To overcome this, the following workaround works:

Step 1

% docker run --rm -it golang:1.13
root@ebbe414b9f65:/go# mkdir -p src/github.com/kubernetes-csi
root@ebbe414b9f65:/go# cd src/github.com/kubernetes-csi
root@ebbe414b9f65:/go/src/github.com/kubernetes-csi# git clone https://github.com/kubernetes-csi/external-snapshotter.git
root@ebbe414b9f65:/go/src/github.com/kubernetes-csi# cd external-snapshotter/
root@d5d5f0a0e82a:/go/src/github.com/kubernetes-csi/external-snapshotter# # optional - git checkout -b release-2.0 origin/release-2.0
root@ebbe414b9f65:/go/src/github.com/kubernetes-csi/external-snapshotter# rm -fr v2/

Step 2 - add v2 to hack/update-generated-code.sh

diff --git a/hack/update-generated-code.sh b/hack/update-generated-code.sh
index f0254b1a..dc560e05 100755
--- a/hack/update-generated-code.sh
+++ b/hack/update-generated-code.sh
@@ -27,7 +27,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-ge
 #                  k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
 #                  instead of the $GOPATH directly. For normal projects this can be dropped.
 bash ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
-  github.com/kubernetes-csi/external-snapshotter/pkg/client github.com/kubernetes-csi/external-snapshotter/pkg/apis \
+  github.com/kubernetes-csi/external-snapshotter/v2/pkg/client github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis \
   volumesnapshot:v1beta1 \
   --go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

Step 3

root@ebbe414b9f65:/go/src/github.com/kubernetes-csi/external-snapshotter# ln -sfvn $(pwd) v2
root@d5d5f0a0e82a:/go/src/github.com/kubernetes-csi/external-snapshotter# rm -fr pkg/client
root@ebbe414b9f65:/go/src/github.com/kubernetes-csi/external-snapshotter# hack/update-generated-code.sh
go: downloading k8s.io/gengo v0.0.0-20190822140433-26a664648505
go: downloading github.com/spf13/pflag v1.0.5
go: downloading k8s.io/klog v1.0.0
go: extracting k8s.io/gengo v0.0.0-20190822140433-26a664648505
go: extracting k8s.io/klog v1.0.0
go: extracting github.com/spf13/pflag v1.0.5
go: downloading golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7
go: extracting golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7
go: finding k8s.io/gengo v0.0.0-20190822140433-26a664648505
go: finding github.com/spf13/pflag v1.0.5
go: finding k8s.io/klog v1.0.0
go: finding golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7
Generating deepcopy funcs
Generating clientset for volumesnapshot:v1beta1 at github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/clientset
Generating listers for volumesnapshot:v1beta1 at github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/listers
Generating informers for volumesnapshot:v1beta1 at github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/informers

root@ebbe414b9f65:/go/src/github.com/kubernetes-csi/external-snapshotter# git status pkg/ --short
 M pkg/apis/volumesnapshot/v1beta1/zz_generated.deepcopy.go
 M pkg/client/clientset/versioned/clientset.go
 M pkg/client/clientset/versioned/doc.go
 M pkg/client/clientset/versioned/fake/clientset_generated.go
 M pkg/client/clientset/versioned/fake/doc.go
 M pkg/client/clientset/versioned/fake/register.go
 M pkg/client/clientset/versioned/scheme/doc.go
 M pkg/client/clientset/versioned/scheme/register.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/doc.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/fake/doc.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/fake/fake_volumesnapshot.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/fake/fake_volumesnapshot_client.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/fake/fake_volumesnapshotclass.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/fake/fake_volumesnapshotcontent.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/generated_expansion.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/volumesnapshot.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/volumesnapshot_client.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/volumesnapshotclass.go
 M pkg/client/clientset/versioned/typed/volumesnapshot/v1beta1/volumesnapshotcontent.go
 M pkg/client/informers/externalversions/factory.go
 M pkg/client/informers/externalversions/generic.go
 M pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go
 M pkg/client/informers/externalversions/volumesnapshot/interface.go
 M pkg/client/informers/externalversions/volumesnapshot/v1beta1/interface.go
 M pkg/client/informers/externalversions/volumesnapshot/v1beta1/volumesnapshot.go
 M pkg/client/informers/externalversions/volumesnapshot/v1beta1/volumesnapshotclass.go
 M pkg/client/informers/externalversions/volumesnapshot/v1beta1/volumesnapshotcontent.go
 M pkg/client/listers/volumesnapshot/v1beta1/expansion_generated.go
 M pkg/client/listers/volumesnapshot/v1beta1/volumesnapshot.go
 M pkg/client/listers/volumesnapshot/v1beta1/volumesnapshotclass.go
 M pkg/client/listers/volumesnapshot/v1beta1/volumesnapshotcontent.go

Step 4 - revert v2 directory

root@ebbe414b9f65:/go/src/github.com/kubernetes-csi/external-snapshotter# git checkout -- v2/

@xing-yang
Copy link
Collaborator

One more step: git checkout -- hack/update-generated-code.sh

@xing-yang
Copy link
Collaborator

It tried it and it worked for me, but too complicated and error prone. I wonder if v2 should actually be the physical path while pkg and cmd should be symlinks, but I'm not sure what additional problems that will bring.

Can you submit a PR and add these steps to hack/README.md?

@pohly
Copy link
Contributor

pohly commented Jan 24, 2020 via email

@xing-yang
Copy link
Collaborator

@pohly that works. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants