From 4bce7b9cc4a0dc1ec65f55969ac7442f86e8c0d6 Mon Sep 17 00:00:00 2001 From: Huabing Zhao Date: Fri, 3 Jan 2025 05:13:29 +0000 Subject: [PATCH] fix: nil pointer error Signed-off-by: Huabing Zhao --- internal/gatewayapi/securitypolicy.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/gatewayapi/securitypolicy.go b/internal/gatewayapi/securitypolicy.go index d21f240f1fa..3e00893f662 100644 --- a/internal/gatewayapi/securitypolicy.go +++ b/internal/gatewayapi/securitypolicy.go @@ -962,10 +962,16 @@ func backendRefAuthority(resources *resource.Resources, backendRef *gwapiv1.Back } } - return net.JoinHostPort( - fmt.Sprintf("%s.%s", backendRef.Name, backendNamespace), - strconv.Itoa(int(*backendRef.Port)), - ) + // Port is mandatory for Kubernetes services + if backendKind == resource.KindService { + return net.JoinHostPort( + fmt.Sprintf("%s.%s", backendRef.Name, backendNamespace), + strconv.Itoa(int(*backendRef.Port)), + ) + } + + // Fallback to the backendRef name, normally it's a unix domain socket in this case + return fmt.Sprintf("%s.%s", backendRef.Name, backendNamespace) } func (t *Translator) buildAuthorization(policy *egv1a1.SecurityPolicy) (*ir.Authorization, error) {