Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
backport: [fix] only filter endpoints by protocol of service port
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <[email protected]>
  • Loading branch information
reaver-flomesh committed Nov 18, 2023
1 parent e08215e commit f30a208
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions controllers/flb/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"sort"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -490,7 +489,7 @@ func (r *ServiceReconciler) deleteEntryFromFLB(ctx context.Context, svc *corev1.
setting := r.settings[svc.Namespace]
result := make(map[string][]string)
for _, port := range svc.Spec.Ports {
if !isSupportedProtocol(port) {
if !isSupportedProtocol(port.Protocol) {
continue
}

Expand Down Expand Up @@ -577,7 +576,7 @@ func (r *ServiceReconciler) getEndpoints(ctx context.Context, svc *corev1.Servic
result := make(map[string][]string)

for _, port := range svc.Spec.Ports {
if !isSupportedProtocol(port) {
if !isSupportedProtocol(port.Protocol) {
continue
}

Expand All @@ -588,11 +587,7 @@ func (r *ServiceReconciler) getEndpoints(ctx context.Context, svc *corev1.Servic
matchedPortNameFound := false

for i, epPort := range ss.Ports {
if epPort.Protocol != corev1.ProtocolTCP {
continue
}

var targetPort int32
targetPort := int32(0)

if port.Name == "" {
// port.Name is optional if there is only one port
Expand All @@ -612,7 +607,7 @@ func (r *ServiceReconciler) getEndpoints(ctx context.Context, svc *corev1.Servic
}

for _, epAddress := range ss.Addresses {
ep := net.JoinHostPort(epAddress.IP, strconv.Itoa(int(targetPort)))
ep := net.JoinHostPort(epAddress.IP, fmt.Sprintf("%d", targetPort))
result[svcKey] = append(result[svcKey], ep)
}
}
Expand Down Expand Up @@ -1012,8 +1007,8 @@ func (r *ServiceReconciler) servicesByNamespace(ns client.Object) []reconcile.Re
return requests
}

func isSupportedProtocol(port corev1.ServicePort) bool {
switch port.Protocol {
func isSupportedProtocol(protocol corev1.Protocol) bool {
switch protocol {
case corev1.ProtocolTCP, corev1.ProtocolUDP:
return true
default:
Expand Down

0 comments on commit f30a208

Please sign in to comment.