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

Kubernetes exec fails when called with Python client #15463

Closed
tigrato opened this issue Aug 12, 2022 · 1 comment · Fixed by #15475
Closed

Kubernetes exec fails when called with Python client #15463

tigrato opened this issue Aug 12, 2022 · 1 comment · Fixed by #15475

Comments

@tigrato
Copy link
Contributor

tigrato commented Aug 12, 2022

Exec into a pod using python kubernetes client fails.

% python3 pod_exec.py
Traceback (most recent call last):
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/stream/ws_client.py", line 519, in websocket_call
    client = WSClient(configuration, url, headers, capture_all)
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/stream/ws_client.py", line 65, in __init__
    self.sock = create_websocket(configuration, url, headers)
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/stream/ws_client.py", line 485, in create_websocket
    websocket.connect(url, **connect_opt)
  File "/opt/homebrew/lib/python3.9/site-packages/websocket_client-1.3.3-py3.9.egg/websocket/_core.py", line 248, in connect
    self.handshake_response = handshake(self.sock, url, *addrs, **options)
  File "/opt/homebrew/lib/python3.9/site-packages/websocket_client-1.3.3-py3.9.egg/websocket/_handshake.py", line 57, in handshake
    status, resp = _get_resp_headers(sock)
  File "/opt/homebrew/lib/python3.9/site-packages/websocket_client-1.3.3-py3.9.egg/websocket/_handshake.py", line 148, in _get_resp_headers
    raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 500 Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/pod_exec.py", line 132, in <module>
    main()
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/pod_exec.py", line 128, in main
    exec_commands(core_v1)
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/pod_exec.py", line 74, in exec_commands
    resp = stream(api_instance.connect_get_namespaced_pod_exec,
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/stream/stream.py", line 35, in _websocket_request
    return api_method(*args, **kwargs)
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/client/api/core_v1_api.py", line 994, in connect_get_namespaced_pod_exec
    return self.connect_get_namespaced_pod_exec_with_http_info(name, namespace, **kwargs)  # noqa: E501
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/client/api/core_v1_api.py", line 1101, in connect_get_namespaced_pod_exec_with_http_info
    return self.api_client.call_api(
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/client/api_client.py", line 348, in call_api
    return self.__call_api(resource_path, method,
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/client/api_client.py", line 180, in __call_api
    response_data = self.request(
  File "/Users/arunnadda/lab_learning/python_library_k8s/python/kubernetes/stream/ws_client.py", line 525, in websocket_call
    raise ApiException(status=0, reason=str(e))
kubernetes.client.exceptions.ApiException: (0)
Reason: Handshake status 500 Internal Server Error

This happens because Teleport expects a SPDY client while Python kubernetes client uses Websockets.

@alex-astronomer
Copy link

Have the same problem which is blocking development. Keeping an eye on the PR linked!

tigrato added a commit that referenced this issue Sep 9, 2022
This PR extends the Kubernetes Service to support the WebSocket protocol in Kubernetes Exec calls.
The Websocket protocol is required so that Kubernetes clients like C#, Python, and Javascript can call the `exec` and `attach` methods.

File `remotecommand_websocket.go` was vendored from [kubernetes repo](https://github.com/kubernetes/kubernetes/blob/d5fdf3135e7c99e5f81e67986ae930f6a2ffb047/pkg/kubelet/cri/streaming/remotecommand/websocket.go).

Fixes #15463

Future work:
- Extend support for  `port-forward`
- Extend support for  `cp`
tigrato added a commit that referenced this issue Sep 11, 2022
This PR extends the Kubernetes Service to support the WebSocket protocol in Kubernetes Exec calls.
The Websocket protocol is required so that Kubernetes clients like C#, Python, and Javascript can call the `exec` and `attach` methods.

File `remotecommand_websocket.go` was vendored from [kubernetes repo](https://github.com/kubernetes/kubernetes/blob/d5fdf3135e7c99e5f81e67986ae930f6a2ffb047/pkg/kubelet/cri/streaming/remotecommand/websocket.go).

Fixes #15463

Future work:
- Extend support for  `port-forward`
- Extend support for  `cp`
tigrato added a commit that referenced this issue Sep 11, 2022
This PR extends the Kubernetes Service to support the WebSocket protocol in Kubernetes Exec calls.
The Websocket protocol is required so that Kubernetes clients like C#, Python, and Javascript can call the `exec` and `attach` methods.

File `remotecommand_websocket.go` was vendored from [kubernetes repo](https://github.com/kubernetes/kubernetes/blob/d5fdf3135e7c99e5f81e67986ae930f6a2ffb047/pkg/kubelet/cri/streaming/remotecommand/websocket.go).

Fixes #15463

Future work:
- Extend support for  `port-forward`
- Extend support for  `cp`
capnspacehook pushed a commit that referenced this issue Sep 12, 2022
This PR extends the Kubernetes Service to support the WebSocket protocol in Kubernetes Exec calls.
The Websocket protocol is required so that Kubernetes clients like C#, Python, and Javascript can call the `exec` and `attach` methods.

File `remotecommand_websocket.go` was vendored from [kubernetes repo](https://github.com/kubernetes/kubernetes/blob/d5fdf3135e7c99e5f81e67986ae930f6a2ffb047/pkg/kubelet/cri/streaming/remotecommand/websocket.go).

Fixes #15463

Future work:
- Extend support for  `port-forward`
- Extend support for  `cp`
tigrato added a commit that referenced this issue Sep 13, 2022
This PR extends the Kubernetes Service to support the WebSocket protocol in Kubernetes Exec calls.
The Websocket protocol is required so that Kubernetes clients like C#, Python, and Javascript can call the `exec` and `attach` methods.

File `remotecommand_websocket.go` was vendored from [kubernetes repo](https://github.com/kubernetes/kubernetes/blob/d5fdf3135e7c99e5f81e67986ae930f6a2ffb047/pkg/kubelet/cri/streaming/remotecommand/websocket.go).

Fixes #15463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants