python icon indicating copy to clipboard operation
python copied to clipboard

Unable to send a request to a service proxy

Open mindw opened this issue 8 years ago • 50 comments

I'm trying to make a post request via the proxy API to a service without the k8s cluster without much luck. Found the below candidate API -

connect_post_namespaced_service_proxy
connect_post_namespaced_service_proxy_with_path
proxy_post_namespaced_service
proxy_post_namespaced_service_with_path

But was unable to attach a body (or extra headers to them):

  • Can anyone point to examples or documentation on how to do this?
  • What is the difference between the plain & _with_path APIs (the documentation for bot?
connect_post_namespaced_service_proxy:
       :param str path: Path is the part of URLs that include service endpoints, suffixes, and parameters to use for the current proxy request to service. For example, the whole request URL is http://localhost/api/v1/namespaces/kube-system/services/elasticsearch-logging/_search?q=user:kimchy. Path is _search?q=user:kimchy.

connect_post_namespaced_service_proxy_with_path:
       :param str path2: Path is the part of URLs that include service endpoints, suffixes, and parameters to use for the current proxy request to service. For example, the whole request URL is http://localhost/api/v1/namespaces/kube-system/services/elasticsearch-logging/_search?q=user:kimchy. Path is _search?q=user:kimchy.
  • What is the difference between the two sets of APIs?
connect_post_XXX
proxy_post_XXX

Thanks!

mindw avatar Aug 19 '17 11:08 mindw

Same here.

By examining the code, It looks like it is impossible to modify POST request, because there is no way to change values of these variables:

query_params = {}
header_params = {}
form_params = []
local_var_files = {}
body_params = None

all of them can be found in all of the following functions defined in the CoreV1Api:

connect_post_namespaced_service_proxy_with_http_info
connect_post_namespaced_service_proxy_with_path_with_http_info
proxy_post_namespaced_service_with_http_info
proxy_post_namespaced_service_with_path_with_http_info

Maybe it is connected somehow to the way python client code was generated by the swagger-codegen?

kkocherov avatar Oct 19 '17 09:10 kkocherov

The spec provided by kubernetes main repo only has three parameters for these calls name, namespace and path. If there is a parameter such as body that is missing, we need to add it to the spec hopefully as a fix in kubernetes itself. What are the missing parameters? is it only body? Can you guys run the same commands with kubectl -v9 and confirm missing parameters?

mbohlool avatar Oct 19 '17 17:10 mbohlool

Sent a fix for this: https://github.com/kubernetes/kubernetes/pull/54266 If that gets merged, the next version of the client (5.0) should have the fix. Meanwhile we can decide if we want to patch this back into our 4.0 client.

mbohlool avatar Oct 19 '17 23:10 mbohlool

@mbohlool any news on this one? thanks!

mindw avatar Nov 25 '17 14:11 mindw

looking at the latest code, I'm still not seeing a way to pass in custom headers, for example. Is there something that I'm missing maybe?

slindner05 avatar Mar 13 '19 18:03 slindner05

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jun 11 '19 18:06 fejta-bot

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten

fejta-bot avatar Jul 11 '19 19:07 fejta-bot

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close

fejta-bot avatar Aug 10 '19 20:08 fejta-bot

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close

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.

k8s-ci-robot avatar Aug 10 '19 20:08 k8s-ci-robot

/reopen /assign

roycaihw avatar Aug 27 '19 17:08 roycaihw

@roycaihw: Reopened this issue.

In response to this:

/reopen /assign

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.

k8s-ci-robot avatar Aug 27 '19 17:08 k8s-ci-robot

/remove-lifecycle rotten

What is the difference between the plain & _with_path APIs

I believe those work the same. Kubernetes apiserver allows the request to specify the subpath that you want to connect to either through a query parameter or by directly composing the URL path. Those two APIs reflect the options that the openapi spec gives.

What is the difference between the two sets of APIs?

connect_post_XXX
proxy_post_XXX

the proxy_* methods are deprecated and removed, use connect_* instead

was unable to attach a body (or extra headers to them)

the upstream openapi spec needs to be fixed so that this client library can support writing body and additional headers. I will take a stab

roycaihw avatar Sep 24 '19 01:09 roycaihw

Any update on this? Working on service that accepts POST, PUT, and PATCH requests. It looks like the kubernetes Go client is working, but as mentioned before, the Python client still does not accept body params.

For now we are using kubectl proxy --port=8080 and http://localhost:8080/api/v1/namespaces/<namespace>/services/<service>/proxy/<path> as a workaround for testing.

jbyers19 avatar Dec 11 '19 21:12 jbyers19

@jbyers19 as a workaround, you could use the 'call_api' method directly, sorta like:

path_params = {
        "name": "https:argocd-server:443",
        "namespace": "default",
        "path": "api/v1/session"
    }

body = {
        "username": "admin",
        "password": "password"
    }

response = v1.api_client.call_api(
            '/api/v1/namespaces/{namespace}/services/{name}/proxy/{path}', 'POST',
            path_params,
            [],
            {"Accept": "*/*"},
            body=body,
            post_params=[],
            files={},
            response_type='str',  
            auth_settings=["BearerToken"],
            async_req=False,
            _return_http_data_only=True, 
            _preload_content=True,
            _request_timeout=None,
            collection_formats={})

I'm using the async python client, but this should work with the sync one too I'd guess.

makkus avatar Jan 08 '20 18:01 makkus

I'm trying to convert this into a good first issue / help wanted issue here. To fix the upstream openapi spec, one need to first fix the API installer who constructs the WebService, then regenerate the openapi spec using make generated_files

In the installer I think we are basically missing a .Reads(...) call and potentially a body parameter registration here. One can see other operations who take body parameters as example (delete, create). The tricky part is figuring out if the endpoint expects any schema from the body (seems to be arbitrary) and how to represent that in WebService (something like interface{}?)

/unassign

roycaihw avatar Mar 12 '20 00:03 roycaihw

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jun 10 '20 01:06 fejta-bot

/remove-lifecycle stale

mindw avatar Jun 10 '20 10:06 mindw

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten

fejta-bot avatar Jul 10 '20 10:07 fejta-bot

/remove-lifecycle stale

mindw avatar Jul 10 '20 15:07 mindw

/remove-lifecycle rotten

mindw avatar Jul 10 '20 15:07 mindw

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Oct 08 '20 16:10 fejta-bot

/remove-lifecycle stale

mindw avatar Oct 08 '20 17:10 mindw

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jan 06 '21 18:01 fejta-bot

/remove-lifecycle stale

mindw avatar Jan 10 '21 16:01 mindw

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale

fejta-bot avatar Apr 10 '21 17:04 fejta-bot

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten

fejta-bot avatar May 10 '21 17:05 fejta-bot

/remove-lifecycle rotten

almost 4 years :(

mindw avatar May 10 '21 19:05 mindw

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Aug 08 '21 19:08 k8s-triage-robot

/remove-lifecycle stale

mindw avatar Aug 08 '21 22:08 mindw

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Nov 06 '21 23:11 k8s-triage-robot