Skip to content

Commit f9a0196

Browse files
authored
Merge pull request #298 from jraby/v4_stream_proto
Set Sec-WebSocket-Protocol header from cfg param
2 parents 6b555de + c3d3ea8 commit f9a0196

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

kubernetes/client/ws_client.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
STDIN_CHANNEL = 0
2525
STDOUT_CHANNEL = 1
2626
STDERR_CHANNEL = 2
27+
ERROR_CHANNEL = 3
28+
RESIZE_CHANNEL = 4
2729

2830

2931
class WSClient:
@@ -46,6 +48,10 @@ def __init__(self, configuration, url, headers):
4648
if headers and 'authorization' in headers:
4749
header.append("authorization: %s" % headers['authorization'])
4850

51+
if configuration.ws_streaming_protocol:
52+
header.append("Sec-WebSocket-Protocol: %s" %
53+
configuration.ws_streaming_protocol)
54+
4955
if url.startswith('wss://') and configuration.verify_ssl:
5056
ssl_opts = {
5157
'cert_reqs': ssl.CERT_REQUIRED,
@@ -131,10 +137,10 @@ def readline_stderr(self, timeout=None):
131137
return self.readline_channel(STDERR_CHANNEL, timeout=timeout)
132138

133139
def read_all(self):
134-
"""Read all of the inputs with the same order they recieved. The channel
135-
information would be part of the string. This is useful for
136-
non-interactive call where a set of command passed to the API call and
137-
their result is needed after the call is concluded.
140+
"""Return buffered data received on stdout and stderr channels.
141+
This is useful for non-interactive call where a set of command passed
142+
to the API call and their result is needed after the call is concluded.
143+
Should be called after run_forever() or update()
138144
139145
TODO: Maybe we can process this and return a more meaningful map with
140146
channels mapped for each input.
@@ -174,9 +180,10 @@ def update(self, timeout=0):
174180
channel = ord(data[0])
175181
data = data[1:]
176182
if data:
177-
# keeping all messages in the order they received for
178-
# non-blocking call.
179-
self._all += data
183+
if channel in [STDOUT_CHANNEL, STDERR_CHANNEL]:
184+
# keeping all messages in the order they received for
185+
# non-blocking call.
186+
self._all += data
180187
if channel not in self._channels:
181188
self._channels[channel] = data
182189
else:

kubernetes/e2e_test/test_client.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
import json
1516
import time
1617
import unittest
1718
import uuid
@@ -103,6 +104,10 @@ def test_pod_apis(self):
103104
self.assertEqual("test string 2", line)
104105
resp.write_stdin("exit\n")
105106
resp.update(timeout=5)
107+
line = resp.read_channel(api_client.ws_client.ERROR_CHANNEL)
108+
status = json.loads(line)
109+
self.assertEqual(status['status'], 'Success')
110+
resp.update(timeout=5)
106111
self.assertFalse(resp.is_open())
107112

108113
number_of_pods = len(api.list_pod_for_all_namespaces().items)
@@ -226,4 +231,4 @@ def test_node_apis(self):
226231
for item in api.list_node().items:
227232
node = api.read_node(name=item.metadata.name)
228233
self.assertTrue(len(node.metadata.labels) > 0)
229-
self.assertTrue(isinstance(node.metadata.labels, dict))
234+
self.assertTrue(isinstance(node.metadata.labels, dict))

0 commit comments

Comments
 (0)