diff --git a/pkg/apis/configuration/validation/globalconfiguration.go b/pkg/apis/configuration/validation/globalconfiguration.go index 689fa625ef..6b3c24b46f 100644 --- a/pkg/apis/configuration/validation/globalconfiguration.go +++ b/pkg/apis/configuration/validation/globalconfiguration.go @@ -105,11 +105,18 @@ func (gcv *GlobalConfigurationValidator) checkIPPortProtocolConflicts(combinatio } existingProtocol, exists := combinations[ip][listener.Port] - if exists { - if existingProtocol == listener.Protocol { - return field.Duplicate(fieldPath, fmt.Sprintf("Listener %s: Duplicated port/protocol combination %d/%s", listener.Name, listener.Port, listener.Protocol)) - } else if listener.Protocol == "HTTP" || existingProtocol == "HTTP" { - return field.Invalid(fieldPath.Child("port"), listener.Port, fmt.Sprintf("Listener %s: Port %d is used with a different protocol (current: %s, new: %s)", listener.Name, listener.Port, existingProtocol, listener.Protocol)) + if !exists { + return nil + } + + switch listener.Protocol { + case "HTTP", "TCP": + if existingProtocol == "HTTP" || existingProtocol == "TCP" { + return field.Invalid(fieldPath.Child("protocol"), listener.Protocol, fmt.Sprintf("Listener %s: Duplicated ip:port protocol combination %d/%s", listener.Name, listener.Port, listener.Protocol)) + } + case "UDP": + if existingProtocol == "UDP" { + return field.Invalid(fieldPath.Child("protocol"), listener.Protocol, fmt.Sprintf("Listener %s: Duplicated ip:port protocol combination %d/%s", listener.Name, listener.Port, listener.Protocol)) } } diff --git a/pkg/apis/configuration/validation/globalconfiguration_test.go b/pkg/apis/configuration/validation/globalconfiguration_test.go index 709967db71..ceff693a86 100644 --- a/pkg/apis/configuration/validation/globalconfiguration_test.go +++ b/pkg/apis/configuration/validation/globalconfiguration_test.go @@ -234,6 +234,20 @@ func TestValidateListeners_PassesOnValidIPListeners(t *testing.T) { {Name: "listener-2", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"}, }, }, + { + name: "UDP and HTTP Listeners with Same Port", + listeners: []conf_v1.Listener{ + {Name: "listener-1", IPv4: "127.0.0.1", Port: 8080, Protocol: "UDP"}, + {Name: "listener-2", IPv4: "127.0.0.1", Port: 8080, Protocol: "HTTP"}, + }, + }, + { + name: "UDP and TCP Listeners with Same Port", + listeners: []conf_v1.Listener{ + {Name: "listener-1", IPv4: "127.0.0.1", Port: 8080, Protocol: "UDP"}, + {Name: "listener-2", IPv4: "127.0.0.1", Port: 8080, Protocol: "TCP"}, + }, + }, } gcv := createGlobalConfigurationValidator()