Skip to content

Use stream module to call exec/attach calls #344

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

Merged
merged 2 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Master
- 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)).

# v3.0.0
- Fix Operation names for subresources kubernetes/kubernetes#49357

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ You'll need a version with OpenSSL version 1.0.0 or later.
If you get an `ssl.CertificateError` complaining about hostname match, your installed packages does not meet version [requirements](requirements.txt).
Specifically check `ipaddress` and `urllib3` package versions to make sure they met requirements in [requirements.txt](requirements.txt) file.

### Why Exec/Attach calls doesn't work
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
of `resp = api.connect_get_namespaced_pod_exec(name, ...` you should call `resp = stream(api.connect_get_namespaced_pod_exec, name, ...`.
See more at [exec example](examples/exec.py).
20 changes: 10 additions & 10 deletions examples/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from kubernetes.client import configuration
from kubernetes.client.apis import core_v1_api
from kubernetes.client.rest import ApiException
from kubernetes.stream import stream

config.load_kube_config()
configuration.assert_hostname = False
Expand Down Expand Up @@ -55,20 +56,19 @@
'/bin/sh',
'-c',
'echo This message goes to stderr >&2; echo This message goes to stdout']
resp = api.connect_get_namespaced_pod_exec(name, 'default',
command=exec_command,
stderr=True, stdin=False,
stdout=True, tty=False)
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
command=exec_command,
stderr=True, stdin=False,
stdout=True, tty=False)
print("Response: " + resp)

# Calling exec interactively.
exec_command = ['/bin/sh']
resp = api.connect_get_namespaced_pod_exec(name, 'default',
command=exec_command,
stderr=True, stdin=True,
stdout=True, tty=False,

_preload_content=False)
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
command=exec_command,
stderr=True, stdin=True,
stdout=True, tty=False,
_preload_content=False)
commands = [
"echo test1",
"echo \"This message goes to stderr\" >&2",
Expand Down
1 change: 1 addition & 0 deletions kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
import kubernetes.client
import kubernetes.config
import kubernetes.watch
import kubernetes.stream
2 changes: 1 addition & 1 deletion kubernetes/base
7 changes: 4 additions & 3 deletions kubernetes/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from kubernetes.client import api_client
from kubernetes.client.apis import core_v1_api
from kubernetes.e2e_test import base
from kubernetes.stream import stream


def short_uuid():
Expand Down Expand Up @@ -74,22 +75,22 @@ def test_pod_apis(self):
exec_command = ['/bin/sh',
'-c',
'for i in $(seq 1 3); do date; done']
resp = api.connect_get_namespaced_pod_exec(name, 'default',
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
command=exec_command,
stderr=False, stdin=False,
stdout=True, tty=False)
print('EXEC response : %s' % resp)
self.assertEqual(3, len(resp.splitlines()))

exec_command = 'uptime'
resp = api.connect_post_namespaced_pod_exec(name, 'default',
resp = stream(api.connect_post_namespaced_pod_exec, name, 'default',
command=exec_command,
stderr=False, stdin=False,
stdout=True, tty=False)
print('EXEC response : %s' % resp)
self.assertEqual(1, len(resp.splitlines()))

resp = api.connect_post_namespaced_pod_exec(name, 'default',
resp = stream(api.connect_post_namespaced_pod_exec, name, 'default',
command='/bin/sh',
stderr=True, stdin=True,
stdout=True, tty=False,
Expand Down
1 change: 1 addition & 0 deletions kubernetes/stream