mirror of
https://github.com/alibaba/higress.git
synced 2026-05-26 13:47:27 +08:00
feat: Map Nacos instance weights to Istio WorkloadEntry weights in watchers (#3342)
Co-authored-by: EricaLiu <30773688+Erica177@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@ package v2
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -556,10 +557,19 @@ func (w *watcher) generateServiceEntry(host string, services []model.Instance) *
|
||||
if !isValidIP(service.Ip) {
|
||||
isDnsService = true
|
||||
}
|
||||
// Calculate weight from Nacos instance
|
||||
// Nacos weight is float64, need to convert to uint32 for Istio
|
||||
// Use math.Round to preserve fractional weights (e.g., 0.5, 1.5)
|
||||
// If weight is 0 or negative, use default weight 1
|
||||
weight := uint32(1)
|
||||
if service.Weight > 0 {
|
||||
weight = uint32(math.Round(service.Weight))
|
||||
}
|
||||
endpoint := &v1alpha3.WorkloadEntry{
|
||||
Address: service.Ip,
|
||||
Ports: map[string]uint32{port.Protocol: port.Number},
|
||||
Labels: service.Metadata,
|
||||
Weight: weight,
|
||||
}
|
||||
endpoints = append(endpoints, endpoint)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user