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

the clientv3 readme is out of date for go modules #11772

Closed
vrischmann opened this issue Apr 8, 2020 · 10 comments
Closed

the clientv3 readme is out of date for go modules #11772

vrischmann opened this issue Apr 8, 2020 · 10 comments
Labels

Comments

@vrischmann
Copy link

I'm getting a project started which uses etcd and the clientv3/concurrency package. The project uses go modules.

The README says to just run go get go.etcd.io/etcd/clientv3 but with go mod this is what it produces:

module etcd-buggy

go 1.14

require (
        github.com/coreos/etcd v2.3.8+incompatible // indirect
        go.etcd.io/etcd v2.3.8+incompatible
)

it defaults to an old version from 2017. A simple program like this compiles:

package main

import (
        "log"

        "go.etcd.io/etcd/clientv3"
)

func main() {
        cli, err := clientv3.New(clientv3.Config{
                Endpoints: []string{"localhost:12345"},
        })
        if err != nil {
                log.Fatal(err)
        }

        _ = cli
}

but if I try to use the concurrency package it fails:

package main

import (
        "log"

        "go.etcd.io/etcd/clientv3"
        "go.etcd.io/etcd/clientv3/concurrency"
)

func main() {
        cli, err := clientv3.New(clientv3.Config{
                Endpoints: []string{"localhost:12345"},
        })
        if err != nil {
                log.Fatal(err)
        }

        session, err := concurrency.NewSession(cli)
        if err != nil {
                log.Fatal(err)
        }

        _ = session
}

with this error:

# etcd-buggy
./main2.go:18:40: cannot use cli (type *"go.etcd.io/etcd/clientv3".Client) as type *"github.com/coreos/etcd/clientv3".Client in argument to concurrency.NewSession

at this point I tried to explicitily get the v3.4.7 tag but it fails:

go get go.etcd.io/etcd/[email protected]: go.etcd.io/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3

I also tried to get the v3.3.20 tag but it fails too, first with this:

../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/auth.go:22:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/auth/authpb
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:28:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/balancer
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:29:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/balancer/picker
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:30:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:31:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/credentials
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/watch.go:26:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/mvcc/mvccpb

then if I try to update github.com/coreos/etcd/clientv3 to v3.3.20 I get this:

go: github.com/coreos/etcd imports
        github.com/coreos/etcd/etcdmain imports
        github.com/coreos/etcd/etcdserver imports
        github.com/coreos/etcd/mvcc/backend imports
        github.com/coreos/bbolt: github.com/coreos/[email protected]: parsing go.mod:
        module declares its path as: go.etcd.io/bbolt
                but was required as: github.com/coreos/bbolt

In the end the only thing that worked for me is to just go get go.etcd.io/etcd/clientv3@master, this is not a good solution however.

Is there something I'm missing to be able to use a tagged release of clientv3 with go modules ?

@despondency
Copy link

despondency commented Apr 9, 2020

Same problem here with 3.3.20.

github.com/coreos/etcd/integration imports
	github.com/coreos/etcd/etcdserver imports
	github.com/coreos/etcd/mvcc/backend imports
	github.com/coreos/bbolt: github.com/coreos/[email protected]: parsing go.mod:
	module declares its path as: go.etcd.io/bbolt
	        but was required as: github.com/coreos/bbolt

go.mod file

module service-discovery

require (
	github.com/coreos/etcd v3.3.20+incompatible
	github.com/coreos/go-semver v0.3.0 // indirect
	github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
	github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
	github.com/gogo/protobuf v1.3.1 // indirect
	github.com/golang/protobuf v1.3.5 // indirect
	github.com/google/uuid v1.1.1 // indirect
	go.uber.org/zap v1.14.1 // indirect
	google.golang.org/genproto v0.0.0-20200408120641-fbb3ad325eb7 // indirect
	google.golang.org/grpc v1.28.1 // indirect
)

go 1.14

Also results in this upon compilation

# github.com/coreos/etcd/clientv3/balancer/picker
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/picker/err.go:37:44: undefined: balancer.PickOptions
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/picker/roundrobin_balanced.go:55:54: undefined: balancer.PickOptions
# github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/resolver/endpoint/endpoint.go:114:78: undefined: resolver.BuildOption
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/resolver/endpoint/endpoint.go:182:31: undefined: resolver.ResolveNowOption

@vrischmann
Copy link
Author

Yeah got that one too, I think after adding replace github.com/coreos/bbolt => go.etcd.io/bbolt v3.3.20 the import error resolved and then I got this one.

@utrack
Copy link

utrack commented Apr 9, 2020

The last bunch of errors happens because of #11721

@liangjfblue
Copy link

i add replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.3 in go.mod, it resolved the error

@despondency
Copy link

despondency commented Apr 12, 2020

Thank you liangjfblue both of my errors are now gone and my full go.mod file looks like this:

module service-discovery

replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.3

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 // indirect

require (
	github.com/coreos/bbolt v0.0.0-00010101000000-000000000000 // indirect
	github.com/coreos/etcd v3.3.20+incompatible
	github.com/coreos/go-semver v0.3.0 // indirect
	github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
	github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
	github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
	github.com/gogo/protobuf v1.3.1 // indirect
	github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
	github.com/golang/protobuf v1.3.5 // indirect
	github.com/google/btree v1.0.0 // indirect
	github.com/google/uuid v1.1.1 // indirect
	github.com/gorilla/websocket v1.4.2 // indirect
	github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
	github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
	github.com/jonboulle/clockwork v0.1.0 // indirect
	github.com/prometheus/client_golang v1.5.1 // indirect
	github.com/soheilhy/cmux v0.1.4 // indirect
	github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect
	github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
	go.etcd.io/bbolt v1.3.4 // indirect
	go.uber.org/zap v1.14.1 // indirect
	golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
	google.golang.org/genproto v0.0.0-20200408120641-fbb3ad325eb7 // indirect
	google.golang.org/grpc v1.28.1 // indirect
	sigs.k8s.io/yaml v1.2.0 // indirect
)

go 1.14

@vrischmann
Copy link
Author

I feel like we shouldn't have to resort to such hacks to just get a working client.

Having no experience with etcd, getting things working was extremely frustrating, almost to the point of completely dropping etcd from the project.

@zhanghepeng
Copy link

1.code

package main

import (
	"context"
	"go.etcd.io/etcd/clientv3"
	"time"
)

func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"192.168.20.204:2379", "192.168.20.205:2379", "192.168.20.206:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		// handle error!
	}
	defer cli.Close()
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	_, err = cli.Put(ctx, "sample_key", "sample_value")
	cancel()
	if err != nil {
		// handle error!
	}
}

2.step

D:\Code\golang\gowork\测试\etcd>go version
go version go1.14 windows/amd64

D:\Code\golang\gowork\测试\etcd>go mod init test
go: creating new go.mod: module test

D:\Code\golang\gowork\测试\etcd>go mod tidy
......
go: found github.com/golang/groupcache/lru in github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
go: test imports
        go.etcd.io/etcd/clientv3 tested by
        go.etcd.io/etcd/clientv3.test imports
        github.com/coreos/etcd/auth imports
        github.com/coreos/etcd/mvcc/backend imports
        github.com/coreos/bbolt: github.com/coreos/[email protected]: parsing go.mod:
        module declares its path as: go.etcd.io/bbolt
                but was required as: github.com/coreos/bbolt

D:\Code\golang\gowork\测试\etcd>go mod edit -replace github.com/coreos/[email protected]=go.etcd.io/[email protected]

D:\Code\golang\gowork\测试\etcd>go mod tidy
......
go: finding module for package go.etcd.io/bbolt
go: finding module for package github.com/gorilla/websocket
go: found github.com/gorilla/websocket in github.com/gorilla/websocket v1.4.2
go: found go.etcd.io/bbolt in go.etcd.io/bbolt v1.3.4
go: go.etcd.io/[email protected] used for two different module paths (github.com/coreos/bbolt and go.etcd.io/bbolt)

D:\Code\golang\gowork\测试\etcd>go run main.go
......
go: found github.com/coreos/go-semver/semver in github.com/coreos/go-semver v0.3.0
# github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\resolver\endpoint\endpoint.go:114:78: undefined: resolver.BuildOption
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\resolver\endpoint\endpoint.go:182:31: undefined: resolver.ResolveNowOption
# github.com/coreos/etcd/clientv3/balancer/picker
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\picker\err.go:37:44: undefined: balancer.PickOptions
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\picker\roundrobin_balanced.go:55:54: undefined: balancer.PickOptions

D:\Code\golang\gowork\测试\etcd>go mod edit -replace google.golang.org/[email protected]=google.golang.org/[email protected]

D:\Code\golang\gowork\测试\etcd>go run main.go

D:\Code\golang\gowork\测试\etcd>go build main.go

D:\Code\golang\gowork\测试\etcd>

3.command

go version 1.14

go mod init test
go mod edit -replace github.com/coreos/[email protected]=go.etcd.io/[email protected]
go mod edit -replace google.golang.org/[email protected]=google.golang.org/[email protected]
go mod tidy
go run main.go

@wuyanxin
Copy link

import (
  	"github.com/coreos/etcd/clientv3"
)

i use github.com/coreos/etcd to replace go.etcd.io/etcd and it works

go mod init
go mod edit -replace github.com/coreos/[email protected]=go.etcd.io/[email protected]
go mod edit -replace google.golang.org/[email protected]=google.golang.org/[email protected]
go mod tidy

@dean2021
Copy link

dean2021 commented Aug 7, 2020

Thank you liangjfblue both of my errors are now gone and my full go.mod file looks like this:

感谢 liangjfblue 我的两个错误现在都消失了,我的完整 go.mod 文件看起来像这样:

module service-discovery

replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.3

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 // indirect

require (
	github.com/coreos/bbolt v0.0.0-00010101000000-000000000000 // indirect
	github.com/coreos/etcd v3.3.20+incompatible
	github.com/coreos/go-semver v0.3.0 // indirect
	github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
	github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
	github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
	github.com/gogo/protobuf v1.3.1 // indirect
	github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
	github.com/golang/protobuf v1.3.5 // indirect
	github.com/google/btree v1.0.0 // indirect
	github.com/google/uuid v1.1.1 // indirect
	github.com/gorilla/websocket v1.4.2 // indirect
	github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
	github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
	github.com/jonboulle/clockwork v0.1.0 // indirect
	github.com/prometheus/client_golang v1.5.1 // indirect
	github.com/soheilhy/cmux v0.1.4 // indirect
	github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect
	github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
	go.etcd.io/bbolt v1.3.4 // indirect
	go.uber.org/zap v1.14.1 // indirect
	golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
	google.golang.org/genproto v0.0.0-20200408120641-fbb3ad325eb7 // indirect
	google.golang.org/grpc v1.28.1 // indirect
	sigs.k8s.io/yaml v1.2.0 // indirect
)

go 1.14

老铁牛逼!

@stale
Copy link

stale bot commented Nov 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 5, 2020
@stale stale bot closed this as completed Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

7 participants