# istio_empty-backend-refs.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: istio
spec:
  controllerName: istio.io/gateway-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: gateway
  namespace: istio-system
spec:
  addresses:
  - value: istio-ingressgateway
    type: Hostname
  gatewayClassName: istio
  listeners:
  - name: default
    hostname: "*.domain.example"
    port: 80
    protocol: HTTP
    allowedRoutes:
      namespaces:
        from: All
---
# Test case for https://github.com/istio/istio/issues/59356
# HTTPRoute with empty backendRefs should return 404 (not 500).
# Currently the code does not distinguish between empty backendRefs
# (no backends at all) and zero-weight backendRefs.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: no-backend
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["no-backend.domain.example"]
  rules:
  # Rule with no backendRefs at all - should return 404 per spec, but currently returns 500
  - matches:
    - path:
        type: PathPrefix
        value: /no-backend
  # Rule with empty backendRefs list - should also return 404 per spec, but currently returns 500
  - matches:
    - path:
        type: PathPrefix
        value: /empty-list
    backendRefs: []
---
# HTTPRoute with zero-weight backendRefs should return 500 per spec
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: zero-weight-backend
  namespace: default
spec:
  parentRefs:
  - name: gateway
    namespace: istio-system
  hostnames: ["zero-weight.domain.example"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /zero-weight
    backendRefs:
    - name: httpbin
      port: 80
      weight: 0