Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway-apis: HTTPRoute with 0 weight still forward the request to backend #31745

Closed
nak3 opened this issue Mar 28, 2021 · 5 comments · Fixed by #34129
Closed

gateway-apis: HTTPRoute with 0 weight still forward the request to backend #31745

nak3 opened this issue Mar 28, 2021 · 5 comments · Fixed by #34129
Labels
lifecycle/automatically-closed Indicates a PR or issue that has been closed automatically.

Comments

@nak3
Copy link
Member

nak3 commented Mar 28, 2021

Bug description

  • Istio still forwards the request to backend even when HTTPRoute sets weight: 0.

[X] Networking

Expected behavior

  • weight: 0 should not forward the request.

Steps to reproduce the bug

1. Prepare k8s cluster with non-default cluster domain

2. Install Istio

For example, I am using the following manifest.

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  values:
    global:
      proxy:
        autoInject: disabled
        clusterDomain: cluster.local
      useMCP: false
      # The third-party-jwt is not enabled on all k8s.
      # See: https://istio.io/docs/ops/best-practices/security/#configure-third-party-service-account-tokens
      jwtPolicy: first-party-jwt
    pilot:
      autoscaleMin: 1
      autoscaleMax: 3
      cpu:
        targetAverageUtilization: 60
      env:
        PILOT_ENABLED_SERVICE_APIS: true

    gateways:
      istio-ingressgateway:
        autoscaleMin: 1
        autoscaleMax: 3
        type: NodePort

  addonComponents:
    pilot:
      enabled: true

  components:
    ingressGateways:
      - name: istio-ingressgateway
        enabled: true
        k8s:
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
3. deploy Gateway,GatewayClass,HTTPRoute (with weight=0) ,Deployments
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
  name: gateway-demo
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: GatewayClass
metadata:
  name: istio
spec:
  controller: istio.io/gateway-controller
---
kind: Gateway
apiVersion: networking.x-k8s.io/v1alpha1
metadata:
  name: simple-gateway
  namespace: gateway-demo
spec:
  gatewayClassName: istio
  listeners:  # Use GatewayClass defaults for listener definition.
  - protocol: HTTP
    port: 80
    routes:
      kind: HTTPRoute
      namespaces:
        from: "All"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo
  namespace: gateway-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo
  template:
    metadata:
      labels:
        app: foo
    spec:
      containers:
      - name: whereami
        image: docker.io/kennethreitz/httpbin
        ports:
          - containerPort: 80
        env:
        - name: METADATA
          value: "foo"
---
apiVersion: v1
kind: Service
metadata:
  name: foo-svc
  namespace: gateway-demo
spec:
  selector:
    app: foo
  ports:
  - port: 8000
    targetPort: 80
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: HTTPRoute
metadata:
  name: test
  namespace: gateway-demo
spec:
  gateways:
    allow: SameNamespace
  hostnames:
  - "*"
  rules:
  - forwardTo:
    - port: 8000
      serviceName: foo-svc
      weight: 0
    matches:
    - path:
        type: Prefix
        value: /
EOF

4. Access to the service

The access still works.

$ curl $IP:$PORT/headers -s -o /dev/null -w "%{http_code}" 
200

Version

$ istioctl version
client version: 1.10-alpha.75974d56a327e9857f36d17151b2ef3146745b92
control plane version: 1.10-dev
data plane version: 1.10-alpha.75974d56a327e9857f36d17151b2ef3146745b92 (2 proxies)
@howardjohn
Copy link
Member

What is the expectation when you have a single host with weight=0? I am not actually sure what the spec defines here? It seems like maybe it should be invalid?

@nak3
Copy link
Member Author

nak3 commented Mar 30, 2021

As per spec comment:
https://github.com/kubernetes-sigs/gateway-api/blob/1caea70dce2571124a7a4887d32076ff8aa166e2/apis/v1alpha1/httproute_types.go#L624-L627

   // If only one backend is specified and it has a weight greater than 0, 100%
   // of the traffic is forwarded to that backend. If weight is set to 0, no
   // traffic should be forwarded for this entry.

it seems that weight = 0 for only one backend is not invalid but just should not forward the traffic.

@howardjohn
Copy link
Member

hmm.. and what should happen? we send a 404? it really seems odd to have only a single weight=0 backend..

@nak3
Copy link
Member Author

nak3 commented Mar 30, 2021

Okay, I will open an issue against gateway-apis repo to make sure.

@nak3
Copy link
Member Author

nak3 commented Mar 30, 2021

Opened kubernetes-sigs/gateway-api#596

@istio-policy-bot istio-policy-bot added the lifecycle/stale Indicates a PR or issue hasn't been manipulated by an Istio team member for a while label Jun 28, 2021
@istio-policy-bot istio-policy-bot added the lifecycle/automatically-closed Indicates a PR or issue that has been closed automatically. label Jul 13, 2021
nak3 added a commit to nak3/istio that referenced this issue Jul 18, 2021
As per kubernetes-sigs/gateway-api#596,
the traffic should not be forwarded when weight is 0.

This patch updates it.

Fix istio#31745
@nak3 nak3 reopened this Jul 19, 2021
@istio-policy-bot istio-policy-bot removed the lifecycle/stale Indicates a PR or issue hasn't been manipulated by an Istio team member for a while label Jul 19, 2021
istio-testing pushed a commit that referenced this issue Jul 20, 2021
* Do not forward the traffic to backend when weight is 0

As per kubernetes-sigs/gateway-api#596,
the traffic should not be forwarded when weight is 0.

This patch updates it.

Fix #31745

* Add release note

* Return 503 when total weight is zero

* Add test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/automatically-closed Indicates a PR or issue that has been closed automatically.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants