Skip to content

Commit

Permalink
feat: etcd default prefix namaepsace
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanViast committed Sep 27, 2024
1 parent 686b037 commit 483bbd4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ IMAGE_NAME?=h00000000s/easegress
BUILDER_IMAGE_NAME?=megaease/golang:1.21.7-alpine

# Version
RELEASE?=v2.7.3
RELEASE?=v2.7.3-rc1

# Git Related
GIT_REPO_INFO=$(shell cd ${MKFILE_DIR} && git config --get remote.origin.url)
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
"go.etcd.io/etcd/client/v3/namespace"
"go.etcd.io/etcd/server/v3/embed"

"github.com/megaease/easegress/v2/pkg/logger"
Expand Down Expand Up @@ -325,6 +326,9 @@ func (c *cluster) getClient() (*clientv3.Client, error) {
return nil, fmt.Errorf("create client failed: %v", err)
}

client.KV = namespace.NewKV(client.KV, c.opt.Cluster.Prefix)
client.Lease = namespace.NewLease(client.Lease, c.opt.Cluster.Prefix)

logger.Infof("client is ready")

c.client = client
Expand Down
7 changes: 4 additions & 3 deletions pkg/cluster/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"context"
"time"

"github.com/megaease/easegress/v2/pkg/logger"
"go.etcd.io/etcd/api/v3/mvccpb"
clientv3 "go.etcd.io/etcd/client/v3"

"github.com/megaease/easegress/v2/pkg/logger"
"go.etcd.io/etcd/client/v3/namespace"
)

type syncer struct {
Expand Down Expand Up @@ -78,7 +78,8 @@ func (s *syncer) watch(key string, prefix bool) (clientv3.Watcher, clientv3.Watc
if prefix {
opts = append(opts, clientv3.WithPrefix())
}
watcher := clientv3.NewWatcher(s.client)

watcher := namespace.NewWatcher(s.client, s.cluster.opt.Cluster.Prefix)
watchChan := watcher.Watch(context.Background(), key, opts...)
logger.Debugf("watcher created for key %s (prefix: %v)", key, prefix)
return watcher, watchChan
Expand Down
3 changes: 2 additions & 1 deletion pkg/cluster/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"go.etcd.io/etcd/api/v3/mvccpb"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/namespace"

"github.com/megaease/easegress/v2/pkg/logger"
)
Expand All @@ -40,7 +41,7 @@ func (c *cluster) Watcher() (Watcher, error) {
return nil, fmt.Errorf("get client failed: %v", err)
}

w := clientv3.NewWatcher(client)
w := namespace.NewWatcher(client.Watcher, c.opt.Cluster.Prefix)

return &watcher{
w: w,
Expand Down
2 changes: 2 additions & 0 deletions pkg/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ClusterOptions struct {
// Secondary members define URLs to connect to cluster formed by primary members.
PrimaryListenPeerURLs []string `yaml:"primary-listen-peer-urls"`
MaxCallSendMsgSize int `yaml:"max-call-send-msg-size"`
Prefix string `yaml:"prefix"`
}

// Options is the start-up options.
Expand Down Expand Up @@ -119,6 +120,7 @@ func addClusterVars(opt *Options) {
opt.flags.StringSliceVar(&opt.Cluster.ListenPeerURLs, "listen-peer-urls", []string{"http://localhost:2380"}, "List of URLs to listen on for cluster peer traffic.")
opt.flags.StringSliceVar(&opt.Cluster.AdvertiseClientURLs, "advertise-client-urls", []string{"http://localhost:2379"}, "List of this member's client URLs to advertise to the rest of the cluster.")
opt.flags.StringSliceVar(&opt.Cluster.InitialAdvertisePeerURLs, "initial-advertise-peer-urls", []string{"http://localhost:2380"}, "List of this member's peer URLs to advertise to the rest of the cluster.")
opt.flags.StringVar(&opt.Cluster.Prefix, "prefix", "", "etcd default prefix namespace")
opt.flags.StringToStringVarP(&opt.Cluster.InitialCluster, "initial-cluster", "", nil, "List of (member name, URL) pairs that will form the cluster. E.g. primary-1=http://localhost:2380.")
opt.flags.StringVar(&opt.Cluster.StateFlag, "state-flag", "new", "Cluster state (new, existing)")
opt.flags.StringSliceVar(&opt.Cluster.PrimaryListenPeerURLs, "primary-listen-peer-urls", []string{"http://localhost:2380"}, "List of peer URLs of primary members. Define this only, when cluster-role is secondary.")
Expand Down

0 comments on commit 483bbd4

Please sign in to comment.