sshkube 0.2.4__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sshkube-0.2.4 → sshkube-0.3.0}/PKG-INFO +1 -1
- {sshkube-0.2.4 → sshkube-0.3.0}/pyproject.toml +1 -1
- {sshkube-0.2.4 → sshkube-0.3.0}/sshkube/__main__.py +17 -6
- {sshkube-0.2.4 → sshkube-0.3.0}/LICENSE +0 -0
- {sshkube-0.2.4 → sshkube-0.3.0}/README.md +0 -0
- {sshkube-0.2.4 → sshkube-0.3.0}/sshkube/__init__.py +0 -0
- {sshkube-0.2.4 → sshkube-0.3.0}/sshkube/socat.py +0 -0
|
@@ -60,6 +60,16 @@ def wait_for_port(port, timeout=1, backoff=1, retries=3):
|
|
|
60
60
|
sock.close()
|
|
61
61
|
raise RuntimeError(f"Proxy server didn't start!")
|
|
62
62
|
|
|
63
|
+
def kubectl_livez(port, timeout=1):
|
|
64
|
+
import ssl, urllib.request, urllib.error
|
|
65
|
+
try:
|
|
66
|
+
with urllib.request.urlopen(f"https://127.0.0.1:{port}/livez", timeout=timeout, context=ssl._create_unverified_context()) as res:
|
|
67
|
+
return res.getcode()
|
|
68
|
+
except urllib.error.HTTPError as e:
|
|
69
|
+
return e.getcode()
|
|
70
|
+
except:
|
|
71
|
+
return 600
|
|
72
|
+
|
|
63
73
|
class PidFile:
|
|
64
74
|
pidfile = workdir/'pid'
|
|
65
75
|
def __init__(self, *, netloc, pid, port):
|
|
@@ -168,7 +178,10 @@ def start_server(*, server, force):
|
|
|
168
178
|
def _start_server(*, server, force):
|
|
169
179
|
pid = PidFile.read()
|
|
170
180
|
if pid:
|
|
171
|
-
if pid.netloc != server
|
|
181
|
+
if force or pid.netloc != server:
|
|
182
|
+
_kill_server()
|
|
183
|
+
elif kubectl_livez(pid.port) >= 500:
|
|
184
|
+
# permission denied error is also fine if connection is broken we get a 600
|
|
172
185
|
_kill_server()
|
|
173
186
|
else:
|
|
174
187
|
return
|
|
@@ -187,6 +200,8 @@ def _start_server(*, server, force):
|
|
|
187
200
|
proc = Popen(make_ssh_cmd(server=server, flags=[f"-NL{port}:{k8s_server_parsed.netloc}"]), start_new_session=True)
|
|
188
201
|
try:
|
|
189
202
|
wait_for_port(port)
|
|
203
|
+
if kubectl_livez(port) >= 500:
|
|
204
|
+
raise click.UsageError('Kubernetes not available')
|
|
190
205
|
PidFile(netloc=server, pid=proc.pid, port=port).write()
|
|
191
206
|
except RuntimeError as e:
|
|
192
207
|
proc.kill()
|
|
@@ -262,11 +277,7 @@ def openssl(*, server, verify):
|
|
|
262
277
|
_openssl(server=server, verify=verify)
|
|
263
278
|
|
|
264
279
|
def _openssl(*, server, verify):
|
|
265
|
-
|
|
266
|
-
socat = shutil.which('socat')
|
|
267
|
-
if socat:
|
|
268
|
-
subprocess.run([socat, '-', f"openssl:{server}:443,verify={verify}"])
|
|
269
|
-
elif sys.platform == 'win32':
|
|
280
|
+
if sys.platform == 'win32':
|
|
270
281
|
import winloop
|
|
271
282
|
winloop.run(_async_openssl(server=server, verify=verify))
|
|
272
283
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|