Skip to content

Commit 6213b15

Browse files
committed
ensure backend kind is Service and that its port is set
Signed-off-by: Ziv Nevo <[email protected]>
1 parent 9483906 commit 6213b15

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/analyzer/info_to_resource.go

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2828
)
2929

30+
const RouteBackendServiceKind = "Service"
31+
3032
// k8sWorkloadObjectFromInfo creates a Resource object from an Info object
3133
func k8sWorkloadObjectFromInfo(info *resource.Info) (*Resource, error) {
3234
var podSpecV1 *v1.PodTemplateSpec
@@ -205,6 +207,9 @@ func gatewayHTTPRouteFromInfo(info *resource.Info, toExpose servicesToExpose) er
205207
rule := &routeObj.Spec.Rules[i]
206208
for j := range rule.BackendRefs {
207209
backend := &rule.BackendRefs[j]
210+
if (backend.Kind != nil && string(*backend.Kind) != RouteBackendServiceKind) || backend.Port == nil {
211+
continue // ignore backends which are not services and which do not specify a port
212+
}
208213
namespace := routeObj.Namespace
209214
if backend.Namespace != nil {
210215
namespace = string(*backend.Namespace)
@@ -227,6 +232,9 @@ func gatewayGRPCRouteFromInfo(info *resource.Info, toExpose servicesToExpose) er
227232
rule := &routeObj.Spec.Rules[i]
228233
for j := range rule.BackendRefs {
229234
backend := &rule.BackendRefs[j]
235+
if (backend.Kind != nil && string(*backend.Kind) != RouteBackendServiceKind) || backend.Port == nil {
236+
continue // ignore backends which are not services and which do not specify a port
237+
}
230238
port := intstr.FromInt32(int32(*backend.Port))
231239
namespace := routeObj.Namespace
232240
if backend.Namespace != nil {

0 commit comments

Comments
 (0)