kubernetes-client / python

Official Python client library for kubernetes
http://kubernetes.io/
Apache License 2.0
6.82k stars 3.27k forks source link

Unable to send a request to a service proxy #325

Open mindw opened 7 years ago

mindw commented 7 years ago

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):

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!
kkocherov commented 7 years ago

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?

mbohlool commented 7 years ago

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 commented 7 years ago

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.

mindw commented 7 years ago

@mbohlool any news on this one? thanks!

slindner05 commented 5 years ago

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?

fejta-bot commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

k8s-ci-robot commented 5 years ago

@fejta-bot: Closing this issue.

In response to [this](https://github.com/kubernetes-client/python/issues/325#issuecomment-520176141): >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](https://github.com/fejta). >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
roycaihw commented 5 years ago

/reopen /assign

k8s-ci-robot commented 5 years ago

@roycaihw: Reopened this issue.

In response to [this](https://github.com/kubernetes-client/python/issues/325#issuecomment-525413512): >/reopen >/assign Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
roycaihw commented 5 years ago

/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

jbyers19 commented 4 years ago

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.

makkus commented 4 years ago

@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.

roycaihw commented 4 years ago

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

fejta-bot commented 4 years ago

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

mindw commented 4 years ago

/remove-lifecycle stale

fejta-bot commented 4 years ago

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

mindw commented 4 years ago

/remove-lifecycle stale

mindw commented 4 years ago

/remove-lifecycle rotten

fejta-bot commented 4 years ago

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

mindw commented 4 years ago

/remove-lifecycle stale

fejta-bot commented 3 years ago

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

mindw commented 3 years ago

/remove-lifecycle stale

fejta-bot commented 3 years ago

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 commented 3 years ago

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

mindw commented 3 years ago

/remove-lifecycle rotten

almost 4 years :(

k8s-triage-robot commented 3 years ago

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:

You can:

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

/lifecycle stale

mindw commented 3 years ago

/remove-lifecycle stale

k8s-triage-robot commented 3 years ago

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:

You can:

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

/lifecycle stale

mindw commented 3 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

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:

You can:

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

/lifecycle stale

mindw commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

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:

You can:

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

/lifecycle stale

mindw commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

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:

You can:

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

/lifecycle stale

mindw commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

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:

You can:

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

/lifecycle stale

mindw commented 2 years ago

/remove-lifecycle stale

au-sebastian-alcaino commented 1 year ago

tried that but was getting the same 503 error for a GET request with. service proxy. it seems that the url encoding happening within api_client.py __call_api method is breaking the request. As a workaround I made the call directly to api_client.request and that fixed the issue.

as a sidenote. Golang api is sending the request to https://host:port/api/v1/namespaces/${NAMESPACE}/services/${SERVICE_NAME}:http/path/to/resource while python does something completely different. once I made the url look like golang then it worked.

k8s-triage-robot commented 1 year ago

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

This bot triages un-triaged issues according to the following rules:

You can:

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

/lifecycle stale

mindw commented 1 year ago

/remove-lifecycle stale

k8s-triage-robot commented 1 year ago

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

This bot triages un-triaged issues according to the following rules:

You can:

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

/lifecycle stale

mindw commented 1 year ago

/remove-lifecycle stale

k8s-triage-robot commented 10 months ago

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

This bot triages un-triaged issues according to the following rules:

You can:

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

/lifecycle stale

mindw commented 10 months ago

/remove-lifecycle stale

k8s-triage-robot commented 7 months ago

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

This bot triages un-triaged issues according to the following rules:

You can:

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

/lifecycle stale

mindw commented 7 months ago

/remove-lifecycle stale

k8s-triage-robot commented 4 months ago

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

This bot triages un-triaged issues according to the following rules:

You can:

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

/lifecycle stale

mindw commented 3 months ago

/remove-lifecycle stale