You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ca...@apache.org on 2022/07/29 02:25:26 UTC

[rocketmq-operator] branch master updated: fix(nameservice): add sorting for hostIps and instance.Status.NameServers before deepEqual.

This is an automated email from the ASF dual-hosted git repository.

caigy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-operator.git


The following commit(s) were added to refs/heads/master by this push:
     new 7668368  fix(nameservice): add sorting for hostIps and instance.Status.NameServers before deepEqual.
     new b73c752  Merge pull request #104 from shangjin92/dev
7668368 is described below

commit 7668368a84b44ba48c927e1b8804606abc02f267
Author: jim.sj <ji...@alibaba-inc.com>
AuthorDate: Fri Jul 1 11:33:34 2022 +0800

    fix(nameservice): add sorting for hostIps and instance.Status.NameServers before deepEqual.
    
    Sometimes, hostsIps are equal to instance.Status.NameServers, just the order of value is different. But reflect.DeepEqual will return false to this situation, and it will update nameservices always.
    
    For example, hostIps = ['192.168.2.1', '192.168.2.11'], instance.Status.NameServers = ['192.168.2.11', '192.168.2.1']
---
 pkg/controller/nameservice/nameservice_controller.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/pkg/controller/nameservice/nameservice_controller.go b/pkg/controller/nameservice/nameservice_controller.go
index 080a125..2608f51 100644
--- a/pkg/controller/nameservice/nameservice_controller.go
+++ b/pkg/controller/nameservice/nameservice_controller.go
@@ -23,6 +23,7 @@ import (
 	"github.com/google/uuid"
 	"os/exec"
 	"reflect"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -179,6 +180,9 @@ func (r *ReconcileNameService) updateNameServiceStatus(instance *rocketmqv1alpha
 	}
 	hostIps := getNameServers(podList.Items)
 
+	sort.Strings(hostIps)
+	sort.Strings(instance.Status.NameServers)
+
 	// Update status.NameServers if needed
 	if !reflect.DeepEqual(hostIps, instance.Status.NameServers) {
 		oldNameServerListStr := ""