mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 04:37:31 +08:00
support multi destination (#119)
This commit is contained in:
@@ -32,6 +32,7 @@ var _ Parser = destination{}
|
|||||||
|
|
||||||
type DestinationConfig struct {
|
type DestinationConfig struct {
|
||||||
McpDestination []*networking.HTTPRouteDestination
|
McpDestination []*networking.HTTPRouteDestination
|
||||||
|
WeightSum int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type destination struct{}
|
type destination struct{}
|
||||||
@@ -99,11 +100,11 @@ func (a destination) Parse(annotations Annotations, config *Ingress, globalConte
|
|||||||
destinations = append(destinations, dest)
|
destinations = append(destinations, dest)
|
||||||
}
|
}
|
||||||
if weightSum != 100 {
|
if weightSum != 100 {
|
||||||
IngressLog.Errorf("destination has invalid weight sum %d within ingress %s/%s", weightSum, config.Namespace, config.Name)
|
IngressLog.Warnf("destination has invalid weight sum %d within ingress %s/%s", weightSum, config.Namespace, config.Name)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
config.Destination = &DestinationConfig{
|
config.Destination = &DestinationConfig{
|
||||||
McpDestination: destinations,
|
McpDestination: destinations,
|
||||||
|
WeightSum: weightSum,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,12 +295,15 @@ func SplitServiceFQDN(fqdn string) (string, string, bool) {
|
|||||||
|
|
||||||
func ConvertBackendService(routeDestination *networking.HTTPRouteDestination) model.BackendService {
|
func ConvertBackendService(routeDestination *networking.HTTPRouteDestination) model.BackendService {
|
||||||
parts := strings.Split(routeDestination.Destination.Host, ".")
|
parts := strings.Split(routeDestination.Destination.Host, ".")
|
||||||
return model.BackendService{
|
service := model.BackendService{
|
||||||
Namespace: parts[1],
|
Namespace: parts[1],
|
||||||
Name: parts[0],
|
Name: parts[0],
|
||||||
Port: routeDestination.Destination.Port.Number,
|
|
||||||
Weight: routeDestination.Weight,
|
Weight: routeDestination.Weight,
|
||||||
}
|
}
|
||||||
|
if routeDestination.Destination.Port != nil {
|
||||||
|
service.Port = routeDestination.Destination.Port.Number
|
||||||
|
}
|
||||||
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLoadBalancerIp(svc *v1.Service) []string {
|
func getLoadBalancerIp(svc *v1.Service) []string {
|
||||||
|
|||||||
@@ -575,6 +575,10 @@ func (c *controller) ConvertHTTPRoute(convertOptions *common.ConvertOptions, wra
|
|||||||
destinationConfig := wrapper.AnnotationsConfig.Destination
|
destinationConfig := wrapper.AnnotationsConfig.Destination
|
||||||
wrapperHttpRoute.HTTPRoute.Route, event = c.backendToRouteDestination(&httpPath.Backend, cfg.Namespace, ingressRouteBuilder, destinationConfig)
|
wrapperHttpRoute.HTTPRoute.Route, event = c.backendToRouteDestination(&httpPath.Backend, cfg.Namespace, ingressRouteBuilder, destinationConfig)
|
||||||
|
|
||||||
|
if destinationConfig != nil {
|
||||||
|
wrapperHttpRoute.WeightTotal = int32(destinationConfig.WeightSum)
|
||||||
|
}
|
||||||
|
|
||||||
if ingressRouteBuilder.Event != common.Normal {
|
if ingressRouteBuilder.Event != common.Normal {
|
||||||
event = ingressRouteBuilder.Event
|
event = ingressRouteBuilder.Event
|
||||||
}
|
}
|
||||||
@@ -961,7 +965,7 @@ func (c *controller) createServiceKey(service *ingress.IngressBackend, namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isCanaryRoute(canary, route *common.WrapperHTTPRoute) bool {
|
func isCanaryRoute(canary, route *common.WrapperHTTPRoute) bool {
|
||||||
return !strings.HasSuffix(route.HTTPRoute.Name, "-canary") && canary.OriginPath == route.OriginPath &&
|
return !route.WrapperConfig.AnnotationsConfig.IsCanary() && canary.OriginPath == route.OriginPath &&
|
||||||
canary.OriginPathType == route.OriginPathType
|
canary.OriginPathType == route.OriginPathType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -570,6 +570,11 @@ func (c *controller) ConvertHTTPRoute(convertOptions *common.ConvertOptions, wra
|
|||||||
var event common.Event
|
var event common.Event
|
||||||
destinationConfig := wrapper.AnnotationsConfig.Destination
|
destinationConfig := wrapper.AnnotationsConfig.Destination
|
||||||
wrapperHttpRoute.HTTPRoute.Route, event = c.backendToRouteDestination(&httpPath.Backend, cfg.Namespace, ingressRouteBuilder, destinationConfig)
|
wrapperHttpRoute.HTTPRoute.Route, event = c.backendToRouteDestination(&httpPath.Backend, cfg.Namespace, ingressRouteBuilder, destinationConfig)
|
||||||
|
|
||||||
|
if destinationConfig != nil {
|
||||||
|
wrapperHttpRoute.WeightTotal = int32(destinationConfig.WeightSum)
|
||||||
|
}
|
||||||
|
|
||||||
if ingressRouteBuilder.Event != common.Normal {
|
if ingressRouteBuilder.Event != common.Normal {
|
||||||
event = ingressRouteBuilder.Event
|
event = ingressRouteBuilder.Event
|
||||||
}
|
}
|
||||||
|
|||||||
21
samples/nacos-discovery/canary.yaml
Normal file
21
samples/nacos-discovery/canary.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
higress.io/destination: service-provider-gray.DEFAULT-GROUP.public.nacos
|
||||||
|
nginx.ingress.kubernetes.io/canary: 'true'
|
||||||
|
nginx.ingress.kubernetes.io/canary-by-header: x-user-id
|
||||||
|
nginx.ingress.kubernetes.io/canary-by-header-value: '100'
|
||||||
|
name: echo-gray
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
resource:
|
||||||
|
apiGroup: networking.higress.io
|
||||||
|
kind: McpBridge
|
||||||
|
name: default
|
||||||
|
path: /echo
|
||||||
|
pathType: Prefix
|
||||||
21
samples/nacos-discovery/multi-destination.yaml
Normal file
21
samples/nacos-discovery/multi-destination.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
higress.io/destination: |
|
||||||
|
33% service-provider.DEFAULT-GROUP.public.nacos
|
||||||
|
33% service-provider-gray.DEFAULT-GROUP.public.nacos
|
||||||
|
34% bar-service.default.svc.cluster.local:5678
|
||||||
|
name: echo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
resource:
|
||||||
|
apiGroup: networking.higress.io
|
||||||
|
kind: McpBridge
|
||||||
|
name: default
|
||||||
|
path: /echo
|
||||||
|
pathType: Prefix
|
||||||
Reference in New Issue
Block a user