This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks-controller.git
The following commit(s) were added to refs/heads/unstable by this push:
new 15211c5 Fix missing password if it's set (#122)
15211c5 is described below
commit 15211c57c8db363589706361133c01cb3367514f
Author: hulk <[email protected]>
AuthorDate: Tue Oct 10 22:40:10 2023 +0800
Fix missing password if it's set (#122)
---
controller/probe/cluster.go | 7 +++++++
metadata/cluster.go | 16 +++++++++++++++-
server/cluster.go | 1 +
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/controller/probe/cluster.go b/controller/probe/cluster.go
index 21b1fb2..35ce159 100644
--- a/controller/probe/cluster.go
+++ b/controller/probe/cluster.go
@@ -65,6 +65,7 @@ func (c *Cluster) probe(ctx context.Context, cluster
*metadata.Cluster) (*metada
var latestEpoch int64
var latestNode *metadata.NodeInfo
+ password := ""
currentClusterStr, _ := cluster.ToSlotString()
for index, shard := range cluster.Shards {
for _, node := range shard.Nodes {
@@ -73,6 +74,11 @@ func (c *Cluster) probe(ctx context.Context, cluster
*metadata.Cluster) (*metada
zap.String("role", node.Role),
zap.String("addr", node.Addr),
)
+ // all nodes in the cluster should have the same
password,
+ // so we just use the first node's password
+ if password == "" {
+ password = node.Password
+ }
if _, ok := c.failureCounts[node.Addr]; !ok {
c.failureCounts[node.Addr] = 0
}
@@ -130,6 +136,7 @@ func (c *Cluster) probe(ctx context.Context, cluster
*metadata.Cluster) (*metada
if err != nil {
return nil, err
}
+ latestClusterInfo.SetPassword(password)
err = c.storage.UpdateCluster(ctx, c.namespace,
latestClusterInfo)
if err != nil {
return nil, err
diff --git a/metadata/cluster.go b/metadata/cluster.go
index 29b0bc2..ef5e902 100644
--- a/metadata/cluster.go
+++ b/metadata/cluster.go
@@ -40,6 +40,15 @@ type Cluster struct {
Config ClusterConfig `json:"config"`
}
+// SetPassword will set the password for all nodes in the cluster.
+func (cluster *Cluster) SetPassword(password string) {
+ for i := 0; i < len(cluster.Shards); i++ {
+ for j := 0; j < len(cluster.Shards[i].Nodes); j++ {
+ cluster.Shards[i].Nodes[j].Password = password
+ }
+ }
+}
+
func (cluster *Cluster) CheckOverlap(slotRange *SlotRange) error {
for idx, shard := range cluster.Shards {
if shard.HasOverlap(slotRange) {
@@ -104,7 +113,12 @@ func ParseCluster(clusterStr string) (*Cluster, error) {
if err != nil {
return nil, fmt.Errorf("master node parser slot
error, node info[%q]", nodeString)
}
- shard := Shard{}
+ shard := Shard{
+ Nodes: make([]NodeInfo, 0),
+ SlotRanges: make([]SlotRange, 0),
+ ImportSlot: -1,
+ MigratingSlot: -1,
+ }
shard.Nodes = append(shard.Nodes, node)
shard.SlotRanges = append(shard.SlotRanges, *slots)
shards = append(shards, shard)
diff --git a/server/cluster.go b/server/cluster.go
index 13d3fbc..fdea094 100644
--- a/server/cluster.go
+++ b/server/cluster.go
@@ -195,6 +195,7 @@ func (hander *ClusterHandler) Import(c *gin.Context) {
responseError(c, err)
return
}
+ clusterInfo.SetPassword(req.Password)
clusterInfo.Name = clusterName
if err := hander.storage.CreateCluster(c, namespace, clusterInfo); err
!= nil {