Skip to content

Commit 27ba35a

Browse files
committed
Use stream module to call exec/attach calls
1 parent 55ef46b commit 27ba35a

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Master
2+
- Adding stream package to support calls like exec. The old way of calling them is deprecated. See [Troubleshooting](README.md#why-execattach-calls-doesnt-work)).
3+
14
# v3.0.0
25
- Fix Operation names for subresources kubernetes/kubernetes#49357
36

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,7 @@ You'll need a version with OpenSSL version 1.0.0 or later.
160160
If you get an `ssl.CertificateError` complaining about hostname match, your installed packages does not meet version [requirements](requirements.txt).
161161
Specifically check `ipaddress` and `urllib3` package versions to make sure they met requirements in [requirements.txt](requirements.txt) file.
162162

163+
### Why Exec/Attach calls doesn't work
164+
Starting from 4.0 release, we do not support directly calling exec or attach calls. you should use stream module to call them. so instead
165+
of `resp = api.connect_get_namespaced_pod_exec(name, ...` you should call `resp = stream(api.connect_get_namespaced_pod_exec, name, ...`.
166+
See more at [exec example](examples/exec.py).

examples/exec.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from kubernetes.client import configuration
55
from kubernetes.client.apis import core_v1_api
66
from kubernetes.client.rest import ApiException
7+
from kubernetes.stream import stream
78

89
config.load_kube_config()
910
configuration.assert_hostname = False
@@ -55,20 +56,19 @@
5556
'/bin/sh',
5657
'-c',
5758
'echo This message goes to stderr >&2; echo This message goes to stdout']
58-
resp = api.connect_get_namespaced_pod_exec(name, 'default',
59-
command=exec_command,
60-
stderr=True, stdin=False,
61-
stdout=True, tty=False)
59+
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
60+
command=exec_command,
61+
stderr=True, stdin=False,
62+
stdout=True, tty=False)
6263
print("Response: " + resp)
6364

6465
# Calling exec interactively.
6566
exec_command = ['/bin/sh']
66-
resp = api.connect_get_namespaced_pod_exec(name, 'default',
67-
command=exec_command,
68-
stderr=True, stdin=True,
69-
stdout=True, tty=False,
70-
71-
_preload_content=False)
67+
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
68+
command=exec_command,
69+
stderr=True, stdin=True,
70+
stdout=True, tty=False,
71+
_preload_content=False)
7272
commands = [
7373
"echo test1",
7474
"echo \"This message goes to stderr\" >&2",

kubernetes/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
import kubernetes.client
2020
import kubernetes.config
2121
import kubernetes.watch
22+
import kubernetes.stream

kubernetes/e2e_test/test_client.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from kubernetes.client import api_client
2121
from kubernetes.client.apis import core_v1_api
2222
from kubernetes.e2e_test import base
23+
from kubernetes.stream import stream
2324

2425

2526
def short_uuid():
@@ -74,22 +75,22 @@ def test_pod_apis(self):
7475
exec_command = ['/bin/sh',
7576
'-c',
7677
'for i in $(seq 1 3); do date; done']
77-
resp = api.connect_get_namespaced_pod_exec(name, 'default',
78+
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
7879
command=exec_command,
7980
stderr=False, stdin=False,
8081
stdout=True, tty=False)
8182
print('EXEC response : %s' % resp)
8283
self.assertEqual(3, len(resp.splitlines()))
8384

8485
exec_command = 'uptime'
85-
resp = api.connect_post_namespaced_pod_exec(name, 'default',
86+
resp = stream(api.connect_post_namespaced_pod_exec, name, 'default',
8687
command=exec_command,
8788
stderr=False, stdin=False,
8889
stdout=True, tty=False)
8990
print('EXEC response : %s' % resp)
9091
self.assertEqual(1, len(resp.splitlines()))
9192

92-
resp = api.connect_post_namespaced_pod_exec(name, 'default',
93+
resp = stream(api.connect_post_namespaced_pod_exec, name, 'default',
9394
command='/bin/sh',
9495
stderr=True, stdin=True,
9596
stdout=True, tty=False,

kubernetes/stream

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
base/stream

0 commit comments

Comments
 (0)