Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复2.2.x版本nacos 没有/nacos/v1/ns/operator/servers 接口的问题 #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions operator/pkg/service/nacos/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type NacosClient struct {
}

type ServersInfo struct {
Servers []struct {
Code int `json:"code"`
Message interface{} `json:"message"`
Data []struct {
IP string `json:"ip"`
Port int `json:"port"`
State string `json:"state"`
Expand All @@ -38,7 +40,7 @@ type ServersInfo struct {
} `json:"extendInfo"`
Address string `json:"address"`
FailAccessCnt int `json:"failAccessCnt"`
} `json:"servers"`
} `json:"data"`
}

func (c *NacosClient) GetClusterNodes(ip string) (ServersInfo, error) {
Expand All @@ -48,9 +50,9 @@ func (c *NacosClient) GetClusterNodes(ip string) (ServersInfo, error) {
var err error

if strings.Contains(ip, ":") {
resp, err = c.httpClient.Get(fmt.Sprintf("http://[%s]:8848/nacos/v1/ns/operator/servers", ip))
resp, err = c.httpClient.Get(fmt.Sprintf("http://[%s]:8848/nacos/v1/core/cluster/nodes", ip))
} else {
resp, err = c.httpClient.Get(fmt.Sprintf("http://%s:8848/nacos/v1/ns/operator/servers", ip))
resp, err = c.httpClient.Get(fmt.Sprintf("http://%s:8848/nacos/v1/core/cluster/nodes", ip))
}

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions operator/pkg/service/operator/Check.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (c *CheckClient) CheckNacos(nacos *nacosgroupv1alpha1.Nacos, pods []corev1.
servers, err := c.nacosClient.GetClusterNodes(pod.Status.PodIP)
myErrors.EnsureNormalMyError(err, myErrors.CODE_CLUSTER_FAILE)
// 确保cr中实例个数和server数量相同
myErrors.EnsureEqual(len(servers.Servers), int(*nacos.Spec.Replicas), myErrors.CODE_CLUSTER_FAILE, "server num is not equal")
for _, svc := range servers.Servers {
myErrors.EnsureEqual(len(servers.Data), int(*nacos.Spec.Replicas), myErrors.CODE_CLUSTER_FAILE, "server num is not equal")
for _, svc := range servers.Data {
myErrors.EnsureEqual(svc.State, "UP", myErrors.CODE_CLUSTER_FAILE, "node is not up")
if leader != "" {
// 确保每个节点leader相同
Expand Down