Skip to content
New issue

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

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

Already on GitHub? # to your account

bugfix post header accept error #560

Merged
merged 2 commits into from
Nov 6, 2021

Conversation

JameKeal
Copy link
Member

@JameKeal JameKeal commented Nov 6, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

When using kubectl exec/attach command after access Yurthub, yurthub will return error: no accept content type for request: kubectl create pods: /api/v1/namespaces/xxxx/pods/xxxx/attach?container=xxxx&stderr=true&stdout=true

root@c-8cc95a:/# kubectl exec -it -n ingress-nginx       nginx-ingress-controller-p7m5t env
Error from server (BadRequest): no accept content type is set.
I1105 07:58:11.199787       1 util.go:232] start proxying: get /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz, in flight requests: 26
I1105 07:58:11.199904       1 loadbalancer.go:186] picked backend https://127.0.0.1:6443 by rr algorithm for request kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz
I1105 07:58:11.199923       1 remote.go:100] request: kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz with bearer token: xxx
I1105 07:58:11.204891       1 util.go:215] kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz with status code 200, spent 4.997435ms
I1105 07:58:11.204931       1 util.go:235] kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz request completed, left 25 requests in flight
I1105 07:58:11.252397       1 util.go:232] start proxying: post /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz/attach?container=nginx-ingress-controller&stderr=true&stdout=true, in flight requests: 26
E1105 07:58:11.252557       1 util.go:65] no accept content type for request: kubectl create pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz/attach?container=nginx-ingress-controller&stderr=true&stdout=true
I1105 07:58:11.253406       1 util.go:235] kubectl create pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz/attach?container=nginx-ingress-controller&stderr=true&stdout=true request completed, left 25 requests in flight

We can see that the kubectl command is not set accept in request header when using native kubernetes.

root@c-8cc95a:/# kubectl exec -it -n ingress-nginx       nginx-ingress-controller-p7m5t env -v8
I1105 08:29:58.181864     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.182189     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.183444     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.191414     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.191887     506 round_trippers.go:420] GET https://10.43.0.1:443/api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-p7m5t
I1105 08:29:58.191898     506 round_trippers.go:427] Request Headers:
I1105 08:29:58.191906     506 round_trippers.go:431]     Accept: application/json, */*
I1105 08:29:58.191912     506 round_trippers.go:431]     User-Agent: kubectl/v1.16.1 (linux/amd64) kubernetes/d647ddb
I1105 08:29:58.191920     506 round_trippers.go:431]     Authorization: Bearer <masked>
I1105 08:29:58.200544     506 round_trippers.go:446] Response Status: 200 OK in 8 milliseconds
I1105 08:29:58.200564     506 round_trippers.go:449] Response Headers:
I1105 08:29:58.200571     506 round_trippers.go:452]     Cache-Control: no-cache, private
I1105 08:29:58.200576     506 round_trippers.go:452]     Content-Type: application/json
I1105 08:29:58.200581     506 round_trippers.go:452]     Date: Fri, 05 Nov 2021 08:37:56 GMT
I1105 08:29:58.200730     506 request.go:968] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"nginx-ingress-controller-p7m5t","generateName":"nginx-ingress-controller-","namespace":"ingress-nginx","selfLink":"/api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-p7m5t","uid":"bb7f85f4-b056-45b5-8d19-c471993f5631","resourceVersion":"488139","creationTimestamp":"2021-11-03T08:07:54Z","labels":{"app":"ingress-nginx","controller-revision-hash":"7755fb95fb","pod-template-generation":"1"},"annotations":{"prometheus.io/port":"10254","prometheus.io/scrape":"true"},"ownerReferences":[{"apiVersion":"apps/v1","kind":"DaemonSet","name":"nginx-ingress-controller","uid":"fc30d3f7-66cc-4ade-ba28-fec49d920082","controller":true,"blockOwnerDeletion":true}]},"spec":{"volumes":[{"name":"nginx-ingress-serviceaccount-token-x8rhc","secret":{"secretName":"nginx-ingress-serviceaccount-token-x8rhc","defaultMode":420}}],"containers":[{"name":"nginx-ingress-controller","image":"10.113.80.97/multi-arch/library/sangforpaas/nginx-ingress-controller:nginx-0.25.1-sangfor1" [truncated 3928 chars]
I1105 08:29:58.206910     506 round_trippers.go:420] POST https://10.43.0.1:443/api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-p7m5t/exec?command=env&container=nginx-ingress-controller&stdin=true&stdout=true&tty=true
I1105 08:29:58.206943     506 round_trippers.go:427] Request Headers:
I1105 08:29:58.206950     506 round_trippers.go:431]     X-Stream-Protocol-Version: v4.channel.k8s.io
I1105 08:29:58.206956     506 round_trippers.go:431]     X-Stream-Protocol-Version: v3.channel.k8s.io
I1105 08:29:58.206962     506 round_trippers.go:431]     X-Stream-Protocol-Version: v2.channel.k8s.io
I1105 08:29:58.206967     506 round_trippers.go:431]     X-Stream-Protocol-Version: channel.k8s.io
I1105 08:29:58.206973     506 round_trippers.go:431]     User-Agent: kubectl/v1.16.1 (linux/amd64) kubernetes/d647ddb
I1105 08:29:58.206980     506 round_trippers.go:431]     Authorization: Bearer <masked>
I1105 08:29:58.237224     506 round_trippers.go:446] Response Status: 101 Switching Protocols in 30 milliseconds
I1105 08:29:58.237248     506 round_trippers.go:449] Response Headers:
I1105 08:29:58.237255     506 round_trippers.go:452]     Connection: Upgrade
I1105 08:29:58.237260     506 round_trippers.go:452]     Upgrade: SPDY/3.1
I1105 08:29:58.237264     506 round_trippers.go:452]     X-Stream-Protocol-Version: v4.channel.k8s.io
I1105 08:29:58.237269     506 round_trippers.go:452]     Date: Fri, 05 Nov 2021 08:37:56 GMT
KUBERNETES_PORT=tcp://169.254.2.1:10268
KUBERNETES_PORT_10268_TCP=tcp://169.254.2.1:10268
KUBERNETES_PORT_10268_TCP_ADDR=169.254.2.1
KUBERNETES_PORT_10268_TCP_PORT=10268
KUBERNETES_PORT_10268_TCP_PROTO=tcp
KUBERNETES_SERVICE_HOST=169.254.2.1
KUBERNETES_SERVICE_PORT=10268
KUBERNETES_SERVICE_PORT_HTTPS=10268

So I don't think we need to do anything when the request header accept doesn't exist. Add only deal the context when accept not empty.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


other Note

@openyurt-bot
Copy link
Collaborator

@JameKeal: GitHub didn't allow me to assign the following users: your_reviewer.

Note that only openyurtio members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

When using kubectl exec/attach command after access Yurthub, yurthub will return error: no accept content type for request: kubectl create pods: /api/v1/namespaces/xxxx/pods/xxxx/attach?container=xxxx&stderr=true&stdout=true

root@c-8cc95a:/# kubectl exec -it -n ingress-nginx       nginx-ingress-controller-p7m5t env
Error from server (BadRequest): no accept content type is set.
I1105 07:58:11.199787       1 util.go:232] start proxying: get /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz, in flight requests: 26
I1105 07:58:11.199904       1 loadbalancer.go:186] picked backend https://127.0.0.1:6443 by rr algorithm for request kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz
I1105 07:58:11.199923       1 remote.go:100] request: kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz with bearer token: xxx
I1105 07:58:11.204891       1 util.go:215] kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz with status code 200, spent 4.997435ms
I1105 07:58:11.204931       1 util.go:235] kubectl get pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz request completed, left 25 requests in flight
I1105 07:58:11.252397       1 util.go:232] start proxying: post /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz/attach?container=nginx-ingress-controller&stderr=true&stdout=true, in flight requests: 26
E1105 07:58:11.252557       1 util.go:65] no accept content type for request: kubectl create pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz/attach?container=nginx-ingress-controller&stderr=true&stdout=true
I1105 07:58:11.253406       1 util.go:235] kubectl create pods: /api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-mlrmz/attach?container=nginx-ingress-controller&stderr=true&stdout=true request completed, left 25 requests in flight

We can see that the kubectl command is not set accept in request header when using native kubernetes.

root@c-8cc95a:/# kubectl exec -it -n ingress-nginx       nginx-ingress-controller-p7m5t env -v8
I1105 08:29:58.181864     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.182189     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.183444     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.191414     506 merged_client_builder.go:122] Using in-cluster configuration
I1105 08:29:58.191887     506 round_trippers.go:420] GET https://10.43.0.1:443/api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-p7m5t
I1105 08:29:58.191898     506 round_trippers.go:427] Request Headers:
I1105 08:29:58.191906     506 round_trippers.go:431]     Accept: application/json, */*
I1105 08:29:58.191912     506 round_trippers.go:431]     User-Agent: kubectl/v1.16.1 (linux/amd64) kubernetes/d647ddb
I1105 08:29:58.191920     506 round_trippers.go:431]     Authorization: Bearer <masked>
I1105 08:29:58.200544     506 round_trippers.go:446] Response Status: 200 OK in 8 milliseconds
I1105 08:29:58.200564     506 round_trippers.go:449] Response Headers:
I1105 08:29:58.200571     506 round_trippers.go:452]     Cache-Control: no-cache, private
I1105 08:29:58.200576     506 round_trippers.go:452]     Content-Type: application/json
I1105 08:29:58.200581     506 round_trippers.go:452]     Date: Fri, 05 Nov 2021 08:37:56 GMT
I1105 08:29:58.200730     506 request.go:968] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"nginx-ingress-controller-p7m5t","generateName":"nginx-ingress-controller-","namespace":"ingress-nginx","selfLink":"/api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-p7m5t","uid":"bb7f85f4-b056-45b5-8d19-c471993f5631","resourceVersion":"488139","creationTimestamp":"2021-11-03T08:07:54Z","labels":{"app":"ingress-nginx","controller-revision-hash":"7755fb95fb","pod-template-generation":"1"},"annotations":{"prometheus.io/port":"10254","prometheus.io/scrape":"true"},"ownerReferences":[{"apiVersion":"apps/v1","kind":"DaemonSet","name":"nginx-ingress-controller","uid":"fc30d3f7-66cc-4ade-ba28-fec49d920082","controller":true,"blockOwnerDeletion":true}]},"spec":{"volumes":[{"name":"nginx-ingress-serviceaccount-token-x8rhc","secret":{"secretName":"nginx-ingress-serviceaccount-token-x8rhc","defaultMode":420}}],"containers":[{"name":"nginx-ingress-controller","image":"10.113.80.97/multi-arch/library/sangforpaas/nginx-ingress-controller:nginx-0.25.1-sangfor1" [truncated 3928 chars]
I1105 08:29:58.206910     506 round_trippers.go:420] POST https://10.43.0.1:443/api/v1/namespaces/ingress-nginx/pods/nginx-ingress-controller-p7m5t/exec?command=env&container=nginx-ingress-controller&stdin=true&stdout=true&tty=true
I1105 08:29:58.206943     506 round_trippers.go:427] Request Headers:
I1105 08:29:58.206950     506 round_trippers.go:431]     X-Stream-Protocol-Version: v4.channel.k8s.io
I1105 08:29:58.206956     506 round_trippers.go:431]     X-Stream-Protocol-Version: v3.channel.k8s.io
I1105 08:29:58.206962     506 round_trippers.go:431]     X-Stream-Protocol-Version: v2.channel.k8s.io
I1105 08:29:58.206967     506 round_trippers.go:431]     X-Stream-Protocol-Version: channel.k8s.io
I1105 08:29:58.206973     506 round_trippers.go:431]     User-Agent: kubectl/v1.16.1 (linux/amd64) kubernetes/d647ddb
I1105 08:29:58.206980     506 round_trippers.go:431]     Authorization: Bearer <masked>
I1105 08:29:58.237224     506 round_trippers.go:446] Response Status: 101 Switching Protocols in 30 milliseconds
I1105 08:29:58.237248     506 round_trippers.go:449] Response Headers:
I1105 08:29:58.237255     506 round_trippers.go:452]     Connection: Upgrade
I1105 08:29:58.237260     506 round_trippers.go:452]     Upgrade: SPDY/3.1
I1105 08:29:58.237264     506 round_trippers.go:452]     X-Stream-Protocol-Version: v4.channel.k8s.io
I1105 08:29:58.237269     506 round_trippers.go:452]     Date: Fri, 05 Nov 2021 08:37:56 GMT
KUBERNETES_PORT=tcp://169.254.2.1:10268
KUBERNETES_PORT_10268_TCP=tcp://169.254.2.1:10268
KUBERNETES_PORT_10268_TCP_ADDR=169.254.2.1
KUBERNETES_PORT_10268_TCP_PORT=10268
KUBERNETES_PORT_10268_TCP_PROTO=tcp
KUBERNETES_SERVICE_HOST=169.254.2.1
KUBERNETES_SERVICE_PORT=10268
KUBERNETES_SERVICE_PORT_HTTPS=10268

So I don't think we need to do anything when the request header accept doesn't exist. Add only deal the context when accept not empty.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


other Note

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openyurt-bot openyurt-bot added the size/S size/S 10-29 label Nov 6, 2021
@rambohe-ch
Copy link
Member

@JameKeal Very appreciate for your bugfix, I agree with you that yurthub should keep the same action with kube-apiserver for client requests.

btw: please fix unit test error. and you can check the details of github action results.

@rambohe-ch
Copy link
Member

/lgtm

@openyurt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JameKeal, rambohe-ch

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openyurt-bot openyurt-bot added the approved approved label Nov 6, 2021
@rambohe-ch rambohe-ch merged commit 4baceb1 into openyurtio:master Nov 6, 2021
@JameKeal JameKeal deleted the bugfix-for-header-accept branch November 6, 2021 06:37
@rambohe-ch
Copy link
Member

@JameKeal welcome you to apply OpenYurt community member, and you can reference apply example here: openyurtio/community#30

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
approved approved lgtm lgtm size/S size/S 10-29
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants