From 7cbf51907c52fa6df24ec2467b17b8b418165dc9 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Sun, 4 Jun 2023 12:31:06 +0800 Subject: [PATCH 1/2] fix: add repeated pods in sentinel --- pkg/controllers/sentinel/handler.go | 3 ++- pkg/controllers/sentinel/kubernetes.go | 3 ++- pkg/controllers/sentinel/monitor.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/controllers/sentinel/handler.go b/pkg/controllers/sentinel/handler.go index 98d4894..c97bf54 100644 --- a/pkg/controllers/sentinel/handler.go +++ b/pkg/controllers/sentinel/handler.go @@ -15,7 +15,7 @@ type KVRocksSentinelHandler struct { k8s *k8s.Client kvrocks *kvrocks.Client log logr.Logger - pods []string + pods map[string]struct{} requeue bool } @@ -31,6 +31,7 @@ func NewKVRocksSentinelHandler( kvrocks: kvrocks, log: logger, key: key, + pods: map[string]struct{}{}, requeue: false, } } diff --git a/pkg/controllers/sentinel/kubernetes.go b/pkg/controllers/sentinel/kubernetes.go index fa33e96..34d67ae 100644 --- a/pkg/controllers/sentinel/kubernetes.go +++ b/pkg/controllers/sentinel/kubernetes.go @@ -31,8 +31,9 @@ func (h *KVRocksSentinelHandler) ensureKubernetes() error { if err != nil { return err } + for _, pod := range pods.Items { - h.pods = append(h.pods, pod.Status.PodIP) + h.pods[pod.Status.PodIP] = struct{}{} } h.log.Info("kubernetes resources ok") return nil diff --git a/pkg/controllers/sentinel/monitor.go b/pkg/controllers/sentinel/monitor.go index 7695ebe..ad3b0f5 100644 --- a/pkg/controllers/sentinel/monitor.go +++ b/pkg/controllers/sentinel/monitor.go @@ -76,7 +76,7 @@ func (h *KVRocksSentinelHandler) getMasterMsg(key types.NamespacedName, password func (h *KVRocksSentinelHandler) ensureMonitor(masterIP, masterName, password string) error { sentinelPassword := h.instance.Spec.Password - for _, sentinelIP := range h.pods { + for sentinelIP := range h.pods { master, err := h.kvrocks.GetMasterFromSentinel(sentinelIP, sentinelPassword, masterName) if err != nil || master != masterIP { h.kvrocks.RemoveMonitor(sentinelIP, sentinelPassword, masterName) From e7020443733b79f017c12e819c2cf8d0732a95b8 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Sun, 4 Jun 2023 12:38:39 +0800 Subject: [PATCH 2/2] fix: add repeated pods in sentinel --- pkg/controllers/sentinel/handler.go | 3 +-- pkg/controllers/sentinel/kubernetes.go | 3 ++- pkg/controllers/sentinel/monitor.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controllers/sentinel/handler.go b/pkg/controllers/sentinel/handler.go index c97bf54..98d4894 100644 --- a/pkg/controllers/sentinel/handler.go +++ b/pkg/controllers/sentinel/handler.go @@ -15,7 +15,7 @@ type KVRocksSentinelHandler struct { k8s *k8s.Client kvrocks *kvrocks.Client log logr.Logger - pods map[string]struct{} + pods []string requeue bool } @@ -31,7 +31,6 @@ func NewKVRocksSentinelHandler( kvrocks: kvrocks, log: logger, key: key, - pods: map[string]struct{}{}, requeue: false, } } diff --git a/pkg/controllers/sentinel/kubernetes.go b/pkg/controllers/sentinel/kubernetes.go index 34d67ae..f13e141 100644 --- a/pkg/controllers/sentinel/kubernetes.go +++ b/pkg/controllers/sentinel/kubernetes.go @@ -32,8 +32,9 @@ func (h *KVRocksSentinelHandler) ensureKubernetes() error { return err } + h.pods = []string{} for _, pod := range pods.Items { - h.pods[pod.Status.PodIP] = struct{}{} + h.pods = append(h.pods, pod.Status.PodIP) } h.log.Info("kubernetes resources ok") return nil diff --git a/pkg/controllers/sentinel/monitor.go b/pkg/controllers/sentinel/monitor.go index ad3b0f5..7695ebe 100644 --- a/pkg/controllers/sentinel/monitor.go +++ b/pkg/controllers/sentinel/monitor.go @@ -76,7 +76,7 @@ func (h *KVRocksSentinelHandler) getMasterMsg(key types.NamespacedName, password func (h *KVRocksSentinelHandler) ensureMonitor(masterIP, masterName, password string) error { sentinelPassword := h.instance.Spec.Password - for sentinelIP := range h.pods { + for _, sentinelIP := range h.pods { master, err := h.kvrocks.GetMasterFromSentinel(sentinelIP, sentinelPassword, masterName) if err != nil || master != masterIP { h.kvrocks.RemoveMonitor(sentinelIP, sentinelPassword, masterName)