Skip to content

Commit

Permalink
Use etcd 3.4 client
Browse files Browse the repository at this point in the history
3.5 seems to have regressed on kubernetes/kubernetes#72102
  • Loading branch information
justinsb committed Feb 4, 2023
1 parent 503eb2b commit 5882193
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 191 deletions.
3 changes: 1 addition & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"

"github.com/spf13/cobra"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"

"sigs.k8s.io/etcdadm/apis"
"sigs.k8s.io/etcdadm/certs"
Expand Down Expand Up @@ -212,7 +211,7 @@ func healthcheck() phase {
cancel()
// Healthy because the cluster reaches consensus for the get request,
// even if permission (to get the key) is denied.
if err == nil || err == rpctypes.ErrPermissionDenied {
if err == nil || etcd.IsPermissionDenied(err) {
log.Println("[health] Local etcd endpoint is healthy")
} else {
return fmt.Errorf("local etcd endpoint is unhealthy: %w", err)
Expand Down
6 changes: 2 additions & 4 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (

log "sigs.k8s.io/etcdadm/pkg/logrus"

"go.etcd.io/etcd/api/v3/etcdserverpb"

"sigs.k8s.io/etcdadm/apis"
"sigs.k8s.io/etcdadm/constants"
"sigs.k8s.io/etcdadm/etcd"
Expand Down Expand Up @@ -132,7 +130,7 @@ func membership() phase {
return nil
}

var members []*etcdserverpb.Member
var members []*etcd.Member
log.Println("[membership] Checking if this member was added")
client, err := etcd.ClientForEndpoint(in.etcdAdmConfig.Endpoint, in.etcdAdmConfig)
if err != nil {
Expand Down Expand Up @@ -197,7 +195,7 @@ func membership() phase {
localMember.Name = in.etcdAdmConfig.Name
localMember.PeerURLs = in.etcdAdmConfig.InitialAdvertisePeerURLs.StringSlice()

var desiredMembers []*etcdserverpb.Member
var desiredMembers []*etcd.Member
for _, m := range members {
if m.ID == localMember.ID {
continue
Expand Down
4 changes: 1 addition & 3 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (

log "sigs.k8s.io/etcdadm/pkg/logrus"

"go.etcd.io/etcd/api/v3/etcdserverpb"

"github.com/spf13/cobra"
"sigs.k8s.io/etcdadm/apis"
"sigs.k8s.io/etcdadm/binary"
Expand Down Expand Up @@ -61,7 +59,7 @@ var resetCmd = &cobra.Command{
log.Println("[reset] etcd service is running")
// Remove self as member from etcd cluster
if !skipRemoveMember {
var localMember *etcdserverpb.Member
var localMember *etcd.Member
log.Println("[membership] Checking if this member was removed")
client, err := etcd.ClientForEndpoint(etcdAdmConfig.LoopbackClientURL.String(), &etcdAdmConfig)
if err != nil {
Expand Down
27 changes: 19 additions & 8 deletions etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,26 @@ import (
"strings"
"time"

"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/client/pkg/v3/transport"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/etcdutl/v3/snapshot"
clientv3 "go.etcd.io/etcd/clientv3"
snapshot "go.etcd.io/etcd/clientv3/snapshot"
"go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
etcdpb "go.etcd.io/etcd/etcdserver/etcdserverpb"
"go.etcd.io/etcd/pkg/transport"

"sigs.k8s.io/etcdadm/apis"
)

// Some type aliases to try to isolate us from etcd client churn

type Member = etcdpb.Member

func IsPermissionDenied(err error) bool {
return err == rpctypes.ErrPermissionDenied
}

// ClientForEndpoint returns an etcd client that will use the given etcd endpoint.
func ClientForEndpoint(endpoint string, cfg *apis.EtcdAdmConfig) (*clientv3.Client, error) {

tlsInfo := transport.TLSInfo{
CertFile: cfg.EtcdctlCertFile,
KeyFile: cfg.EtcdctlKeyFile,
Expand All @@ -50,7 +60,7 @@ func ClientForEndpoint(endpoint string, cfg *apis.EtcdAdmConfig) (*clientv3.Clie
}

// MemberForPeerURLs searches the list for a member with matching peerURLs.
func MemberForPeerURLs(members []*etcdserverpb.Member, peerURLs []string) (*etcdserverpb.Member, bool) {
func MemberForPeerURLs(members []*Member, peerURLs []string) (*Member, bool) {
for _, m := range members {
if stringSlicesEqual(m.PeerURLs, peerURLs) {
return m, true
Expand All @@ -73,7 +83,7 @@ func stringSlicesEqual(l, r []string) bool {
}

// MemberForID searches the list for a member with a matching ID.
func MemberForID(members []*etcdserverpb.Member, id uint64) (*etcdserverpb.Member, bool) {
func MemberForID(members []*Member, id uint64) (*Member, bool) {
for _, m := range members {
if m.ID == id {
return m, true
Expand All @@ -83,12 +93,13 @@ func MemberForID(members []*etcdserverpb.Member, id uint64) (*etcdserverpb.Membe
}

// Started checks whether the member has started.
func Started(member *etcdserverpb.Member) bool {
func Started(member *Member) bool {
unstarted := (member.Name == "" && len(member.ClientURLs) == 0)
return !unstarted
}

// RestoreSnapshot initializes the etcd data directory from a snapshot
// Deprecated: we should be using the correct library version for this.
func RestoreSnapshot(cfg *apis.EtcdAdmConfig) error {
sp := snapshot.NewV3(nil)

Expand All @@ -104,7 +115,7 @@ func RestoreSnapshot(cfg *apis.EtcdAdmConfig) error {
}

// InitialClusterFromMembers derives an "initial cluster" string from a member list
func InitialClusterFromMembers(members []*etcdserverpb.Member) string {
func InitialClusterFromMembers(members []*Member) string {
namePeerURLs := []string{}
for _, m := range members {
for _, u := range m.PeerURLs {
Expand Down
35 changes: 16 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,52 @@ module sigs.k8s.io/etcdadm

go 1.18

// This is 3.4.14; see https://github.com/etcd-io/etcd/issues/11154 for the reason.
replace go.etcd.io/etcd => go.etcd.io/etcd v0.5.0-alpha.5.0.20201125193152-8a03d2e9614b // indirect

require go.etcd.io/etcd v0.5.0-alpha.5.0.20201125193152-8a03d2e9614b

require (
github.com/google/go-cmp v0.5.9
github.com/pkg/errors v0.9.1
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
go.etcd.io/etcd/api/v3 v3.5.7
go.etcd.io/etcd/client/pkg/v3 v3.5.7
go.etcd.io/etcd/client/v3 v3.5.7
go.etcd.io/etcd/etcdutl/v3 v3.5.7
k8s.io/apimachinery v0.26.0
k8s.io/client-go v0.26.0
k8s.io/component-base v0.26.0
k8s.io/component-base v0.22.0-beta.0
k8s.io/klog/v2 v2.80.1
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/etcd/client/v2 v2.305.7 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/raft/v3 v3.5.7 // indirect
go.etcd.io/etcd/server/v3 v3.5.7 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.25.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.0 // indirect
Expand All @@ -59,8 +56,8 @@ require (
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154 // indirect
google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
Expand Down
Loading

0 comments on commit 5882193

Please sign in to comment.