diff --git a/pkg/ingress/kube/ingress/controller.go b/pkg/ingress/kube/ingress/controller.go index dfeb6c675..a05543a26 100644 --- a/pkg/ingress/kube/ingress/controller.go +++ b/pkg/ingress/kube/ingress/controller.go @@ -17,7 +17,6 @@ package ingress import ( "errors" "fmt" - "github.com/alibaba/higress/pkg/cert" "path" "reflect" "sort" @@ -25,6 +24,8 @@ import ( "sync" "time" + "github.com/alibaba/higress/pkg/cert" + "github.com/hashicorp/go-multierror" networking "istio.io/api/networking/v1alpha3" "istio.io/istio/pilot/pkg/model" @@ -890,15 +891,28 @@ func (c *controller) storeBackendTrafficPolicy(wrapper *common.WrapperConfig, ba } if common.ValidateBackendResource(backend.Resource) && wrapper.AnnotationsConfig.Destination != nil { for _, dest := range wrapper.AnnotationsConfig.Destination.McpDestination { + portNumber := dest.Destination.GetPort().GetNumber() serviceKey := common.ServiceKey{ Namespace: "mcp", Name: dest.Destination.Host, + Port: int32(portNumber), ServiceFQDN: dest.Destination.Host, } if _, exist := store[serviceKey]; !exist { - store[serviceKey] = &common.WrapperTrafficPolicy{ - TrafficPolicy: &networking.TrafficPolicy{}, - WrapperConfig: wrapper, + if serviceKey.Port != 0 { + store[serviceKey] = &common.WrapperTrafficPolicy{ + PortTrafficPolicy: &networking.TrafficPolicy_PortTrafficPolicy{ + Port: &networking.PortSelector{ + Number: uint32(serviceKey.Port), + }, + }, + WrapperConfig: wrapper, + } + } else { + store[serviceKey] = &common.WrapperTrafficPolicy{ + TrafficPolicy: &networking.TrafficPolicy{}, + WrapperConfig: wrapper, + } } } } diff --git a/pkg/ingress/kube/ingressv1/controller.go b/pkg/ingress/kube/ingressv1/controller.go index d96b95e59..063bddcbb 100644 --- a/pkg/ingress/kube/ingressv1/controller.go +++ b/pkg/ingress/kube/ingressv1/controller.go @@ -891,15 +891,28 @@ func (c *controller) storeBackendTrafficPolicy(wrapper *common.WrapperConfig, ba } if common.ValidateBackendResource(backend.Resource) && wrapper.AnnotationsConfig.Destination != nil { for _, dest := range wrapper.AnnotationsConfig.Destination.McpDestination { + portNumber := dest.Destination.GetPort().GetNumber() serviceKey := common.ServiceKey{ Namespace: "mcp", Name: dest.Destination.Host, + Port: int32(portNumber), ServiceFQDN: dest.Destination.Host, } if _, exist := store[serviceKey]; !exist { - store[serviceKey] = &common.WrapperTrafficPolicy{ - TrafficPolicy: &networking.TrafficPolicy{}, - WrapperConfig: wrapper, + if serviceKey.Port != 0 { + store[serviceKey] = &common.WrapperTrafficPolicy{ + PortTrafficPolicy: &networking.TrafficPolicy_PortTrafficPolicy{ + Port: &networking.PortSelector{ + Number: uint32(serviceKey.Port), + }, + }, + WrapperConfig: wrapper, + } + } else { + store[serviceKey] = &common.WrapperTrafficPolicy{ + TrafficPolicy: &networking.TrafficPolicy{}, + WrapperConfig: wrapper, + } } } }