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:
aias00
2026-01-23 15:56:58 +08:00
committed by GitHub
parent a2eb599eff
commit 255f0bde76
4 changed files with 393 additions and 0 deletions

View File

@@ -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)
}