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

switch dep to go mod and upgrade go version #67

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .Gopkg.toml

This file was deleted.

4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: go
go_import_path: sigs.k8s.io/sig-storage-lib-external-provisioner
go:
- 1.11.1
- 1.13.7
services: docker
install:
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
script:
- make verify
- make test
Expand Down
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
all: verify test

dep:
cp .Gopkg.toml Gopkg.toml
-dep init
dep ensure
go mod tidy

verify: dep
go get -u github.com/alecthomas/gometalinter
gometalinter --install
# todo gometalinter is DEPRECATED, Use https://github.com/golangci/golangci-lint
GO111MODULE=off go get -u github.com/alecthomas/gometalinter
GO111MODULE=off gometalinter --install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be enhanced to get a fixed version of gometalinter while you are touching this code? Like depending on "master" for Kubernetes, depending on master of gometalinter (or golangci-lint) has the risk that changes in those project(s) break this project.

I know that this is more complicated because (for reasons that I don't understand) go get in non-module mode doesn't support specifying a version, but perhaps it works when adding it as module and then building?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with GO111MODULE=off its not easy, but we can fix it later by replacing with golangci-lint. In fact gometalinter is DEPRECATED, so its 'fixed'.

repo-infra/verify/verify-go-src.sh -v
repo-infra/verify/verify-boilerplate.sh

Expand All @@ -30,9 +29,4 @@ test: dep
go test ./allocator

clean:
rm -rf ./vendor
rm -rf ./Gopkg.toml
rm -rf ./Gopkg.lock
rm -rf ./examples/hostpath-provisioner/vendor
rm -rf ./examples/hostpath-provisioner/Gopkg.lock
rm -rf ./test/e2e/kubernetes
50 changes: 0 additions & 50 deletions examples/hostpath-provisioner/Gopkg.toml

This file was deleted.

5 changes: 1 addition & 4 deletions examples/hostpath-provisioner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ IMAGE?=hostpath-provisioner
all: dep hostpath-provisioner image

dep:
-dep init
dep ensure
go mod tidy

hostpath-provisioner:
CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o hostpath-provisioner .
Expand All @@ -27,6 +26,4 @@ image: hostpath-provisioner
docker build -t $(IMAGE) -f Dockerfile.scratch .

clean:
rm -rf vendor
rm -rf Gopkg.lock
rm -rf hostpath-provisioner
16 changes: 16 additions & 0 deletions examples/hostpath-provisioner/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module sigs.k8s.io/kubernetes-sigs/sig-storage-lib-external-provisioner/examples/hostpath-provisioner

go 1.13

require (
github.com/miekg/dns v1.1.27 // indirect
github.com/prometheus/client_golang v1.4.1 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/client-go v0.0.0-20200131194156-19522ff28802 // release-14.0
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20200124190032-861946025e34 // indirect
sigs.k8s.io/sig-storage-lib-external-provisioner v4.0.1+incompatible
)
285 changes: 285 additions & 0 deletions examples/hostpath-provisioner/go.sum

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module sigs.k8s.io/sig-storage-lib-external-provisioner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the next release with this change will have to be v5.0.0 because introducing Go module support is a breaking change. Also, because the major version is > 1, versioned imports become mandatory.

This means that sigs.k8s.io/sig-storage-lib-external-provisioner has to be replaced with sigs.k8s.io/sig-storage-lib-external-provisioner/v5 here and in all import statements in the code itself.

This also raises the question whether importing with dep is still supposed to work. It doesn't out-of-the-box anymore because dep doesn't understand versioned imports.

We worked around that with symlinks elsewhere, see kubernetes-csi/external-attacher#209 and kubernetes-csi/csi-test#232.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a single commit is added to fix this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message of that commit ("add compatibility with dep") misses the main reason for doing this: "go mod" will also refuse to pull the code unless the /v5 suffix matches the major version number.

Not sure whether you want to fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git message amended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably explained this wrong 😁

The "/v5" suffix isn't needed by dep, quite the opposite, it just gets confused by it. It's needed by "go mod". Anyway, let's leave the commit message as-is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm new to this pattern. I just read https://blog.golang.org/v2-go-modules and in their example they don't symlink, instead they keep v0/v1 in the top-level and they let all the versions coexist in the same branch.

I don't want to follow that example because this library makes breaking changes quite often and it would be a pain to retroactively make v2-v5 directories.

But I think symlinking could get pretty tedious as well. If I want to refactor and add/delete a file, I need to make sure the symlink under /v5 is updated accordingly? Is there a common script all our repos could share that could make validation & maintenance of these symlinks easier?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when I want to release a v6? Would I simply rename v5 to v6?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to follow that example because this library makes breaking changes quite often and it would be a pain to retroactively make v2-v5 directories.

I agree, having multiple different versions in the same branch looks awkward. It's probably only relevant if developers really need to support multiple API versions.

Symlinking is a stop-gap measure to continue supporting dep. I don't know how important that is for the consumers of this library. It is something that could be scripted, but there is no script at the moment.

What happens when I want to release a v6? Would I simply rename v5 to v6?

Yes.


go 1.13

require (
github.com/miekg/dns v1.1.27
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/prometheus/client_golang v1.4.1
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/client-go v0.0.0-20200131194156-19522ff28802 // release-14.0
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20200124190032-861946025e34 // indirect
)
Loading