|
4 | 4 | from kubernetes.client import configuration
|
5 | 5 | from kubernetes.client.apis import core_v1_api
|
6 | 6 | from kubernetes.client.rest import ApiException
|
| 7 | +from kubernetes.stream import stream |
7 | 8 |
|
8 | 9 | config.load_kube_config()
|
9 | 10 | configuration.assert_hostname = False
|
|
55 | 56 | '/bin/sh',
|
56 | 57 | '-c',
|
57 | 58 | '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) |
62 | 63 | print("Response: " + resp)
|
63 | 64 |
|
64 | 65 | # Calling exec interactively.
|
65 | 66 | 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) |
72 | 72 | commands = [
|
73 | 73 | "echo test1",
|
74 | 74 | "echo \"This message goes to stderr\" >&2",
|
|
0 commit comments