Use stream module to call exec/attach calls
This commit is contained in:
parent
55ef46b6cf
commit
27ba35aa81
@ -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
|
||||
|
||||
|
||||
@ -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).
|
||||
|
||||
@ -4,6 +4,7 @@ from kubernetes import config
|
||||
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 @@ exec_command = [
|
||||
'/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",
|
||||
|
||||
@ -19,3 +19,4 @@ __version__ = "3.0.0-snapshot"
|
||||
import kubernetes.client
|
||||
import kubernetes.config
|
||||
import kubernetes.watch
|
||||
import kubernetes.stream
|
||||
|
||||
@ -20,6 +20,7 @@ import uuid
|
||||
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 @@ class TestClient(unittest.TestCase):
|
||||
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 @@ class TestClient(unittest.TestCase):
|
||||
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,
|
||||
|
||||
1
kubernetes/stream
Symbolic link
1
kubernetes/stream
Symbolic link
@ -0,0 +1 @@
|
||||
base/stream
|
||||
Loading…
Reference in New Issue
Block a user