mirror of
https://github.com/alibaba/higress.git
synced 2026-06-08 12:17:28 +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:
@@ -15,6 +15,7 @@
|
||||
package nacos
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -352,10 +353,19 @@ func (w *watcher) generateServiceEntry(host string, services []model.SubscribeSe
|
||||
portList = append(portList, port)
|
||||
}
|
||||
}
|
||||
// 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