Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #363 from justinsb/etcd_client_34_works
Browse files Browse the repository at this point in the history
Use etcd 3.4 client
  • Loading branch information
k8s-ci-robot authored Feb 4, 2023
2 parents 1dd5dc2 + faf4eaa commit d3c7c31
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 202 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ jobs:
- name: Run create cluster e2e test
run: ./test/e2e/cluster.sh

# cluster-create-phases-test:
# runs-on: ubuntu-latest
# needs: build
# steps:
# - uses: actions/checkout@master
# - uses: actions/cache@v2
# with:
# path: ./etcdadm
# key: ${{ runner.os }}-etcdadm-bin-${{ github.sha }}
# - name: Run create cluster with etcdadm phases e2e test
# run: ./test/e2e/cluster_phases.sh
cluster-create-phases-test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@master
- uses: actions/cache@v2
with:
path: ./etcdadm
key: ${{ runner.os }}-etcdadm-bin-${{ github.sha }}
- name: Run create cluster with etcdadm phases e2e test
run: ./test/e2e/cluster_phases.sh
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 @@ -214,7 +213,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 @@ -199,7 +197,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
29 changes: 21 additions & 8 deletions etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,29 @@ 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

// Member is an alias to the Member message used in the etcd protocol.
type Member = etcdpb.Member

// IsPermissionDenied returns true if the error is the well-known etcd permission-denied error.
func IsPermissionDenied(err error) bool {
return err == rpctypes.ErrPermissionDenied
}

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

tlsInfo := transport.TLSInfo{
CertFile: cfg.EtcdctlCertFile,
KeyFile: cfg.EtcdctlKeyFile,
Expand All @@ -51,7 +63,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 @@ -74,7 +86,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 @@ -84,12 +96,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 @@ -105,7 +118,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 d3c7c31

Please sign in to comment.