diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e77d07bd..02aa329488 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index f2a99e77fb..e4822bb837 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/examples/exec.py b/examples/exec.py index b5ad044341..7dade408ad 100644 --- a/examples/exec.py +++ b/examples/exec.py @@ -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 @@ -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", diff --git a/kubernetes/__init__.py b/kubernetes/__init__.py index 993c4e735b..37c56efa9b 100644 --- a/kubernetes/__init__.py +++ b/kubernetes/__init__.py @@ -19,3 +19,4 @@ import kubernetes.client import kubernetes.config import kubernetes.watch +import kubernetes.stream diff --git a/kubernetes/base b/kubernetes/base index 168c5e761f..31e13b1f28 160000 --- a/kubernetes/base +++ b/kubernetes/base @@ -1 +1 @@ -Subproject commit 168c5e761fc8a60a332e38342fda04350d64fe33 +Subproject commit 31e13b1f28113b6f71384047c8d5baaa79f0810e diff --git a/kubernetes/e2e_test/test_client.py b/kubernetes/e2e_test/test_client.py index 30e7b68e4c..26b0a37d06 100644 --- a/kubernetes/e2e_test/test_client.py +++ b/kubernetes/e2e_test/test_client.py @@ -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(): @@ -74,7 +75,7 @@ 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) @@ -82,14 +83,14 @@ def test_pod_apis(self): 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, diff --git a/kubernetes/stream b/kubernetes/stream new file mode 120000 index 0000000000..387e18fe54 --- /dev/null +++ b/kubernetes/stream @@ -0,0 +1 @@ +base/stream \ No newline at end of file