sshkube 0.2.3__tar.gz → 0.2.4__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.3 → sshkube-0.2.4}/PKG-INFO +1 -1
- {sshkube-0.2.3 → sshkube-0.2.4}/pyproject.toml +1 -1
- {sshkube-0.2.3 → sshkube-0.2.4}/sshkube/__main__.py +16 -14
- {sshkube-0.2.3 → sshkube-0.2.4}/LICENSE +0 -0
- {sshkube-0.2.3 → sshkube-0.2.4}/README.md +0 -0
- {sshkube-0.2.3 → sshkube-0.2.4}/sshkube/__init__.py +0 -0
- {sshkube-0.2.3 → sshkube-0.2.4}/sshkube/socat.py +0 -0
|
@@ -62,15 +62,20 @@ def wait_for_port(port, timeout=1, backoff=1, retries=3):
|
|
|
62
62
|
|
|
63
63
|
class PidFile:
|
|
64
64
|
pidfile = workdir/'pid'
|
|
65
|
-
def __init__(self, *, pid, port):
|
|
65
|
+
def __init__(self, *, netloc, pid, port):
|
|
66
|
+
self.netloc = netloc
|
|
66
67
|
self.pid = pid
|
|
67
68
|
self.port = port
|
|
68
69
|
|
|
69
70
|
@staticmethod
|
|
70
71
|
def read():
|
|
71
72
|
if PidFile.pidfile.exists():
|
|
72
|
-
pid, _,
|
|
73
|
-
|
|
73
|
+
pid, _, netloc_port = PidFile.pidfile.read_text().partition(':')
|
|
74
|
+
netloc, _, port = netloc_port.partition(':')
|
|
75
|
+
if not _:
|
|
76
|
+
port = netloc
|
|
77
|
+
netloc = ''
|
|
78
|
+
pidfile = PidFile(netloc=netloc, pid=int(pid), port=int(port))
|
|
74
79
|
if pidfile.running:
|
|
75
80
|
return pidfile
|
|
76
81
|
else:
|
|
@@ -79,7 +84,7 @@ class PidFile:
|
|
|
79
84
|
def write(self):
|
|
80
85
|
if PidFile.pidfile.exists(): raise RuntimeError('PID file already exists')
|
|
81
86
|
PidFile.pidfile.parent.mkdir(parents=True, exist_ok=True)
|
|
82
|
-
PidFile.pidfile.write_text(f"{self.pid}:{self.port}")
|
|
87
|
+
PidFile.pidfile.write_text(f"{self.pid}:{self.netloc}:{self.port}")
|
|
83
88
|
|
|
84
89
|
@property
|
|
85
90
|
def running(self):
|
|
@@ -163,7 +168,7 @@ def start_server(*, server, force):
|
|
|
163
168
|
def _start_server(*, server, force):
|
|
164
169
|
pid = PidFile.read()
|
|
165
170
|
if pid:
|
|
166
|
-
if force:
|
|
171
|
+
if pid.netloc != server or force:
|
|
167
172
|
_kill_server()
|
|
168
173
|
else:
|
|
169
174
|
return
|
|
@@ -182,7 +187,7 @@ def _start_server(*, server, force):
|
|
|
182
187
|
proc = Popen(make_ssh_cmd(server=server, flags=[f"-NL{port}:{k8s_server_parsed.netloc}"]), start_new_session=True)
|
|
183
188
|
try:
|
|
184
189
|
wait_for_port(port)
|
|
185
|
-
PidFile(pid=proc.pid, port=port).write()
|
|
190
|
+
PidFile(netloc=server, pid=proc.pid, port=port).write()
|
|
186
191
|
except RuntimeError as e:
|
|
187
192
|
proc.kill()
|
|
188
193
|
raise click.UsageError('Proxy server failed to start..') from e
|
|
@@ -212,11 +217,9 @@ def _init(*, server):
|
|
|
212
217
|
'''
|
|
213
218
|
Usage: eval "$(sshkube init)"
|
|
214
219
|
'''
|
|
220
|
+
_start_server(server=server, force=False)
|
|
215
221
|
pid = PidFile.read()
|
|
216
|
-
|
|
217
|
-
_start_server(server=server, force=False)
|
|
218
|
-
pid = PidFile.read()
|
|
219
|
-
assert pid is not None
|
|
222
|
+
assert pid is not None
|
|
220
223
|
#
|
|
221
224
|
if sys.platform == 'win32':
|
|
222
225
|
print(
|
|
@@ -243,10 +246,9 @@ def _run(*, server, args):
|
|
|
243
246
|
Usage: sshkube run kubectl help
|
|
244
247
|
'''
|
|
245
248
|
pid = PidFile.read()
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
assert pid is not None
|
|
249
|
+
_start_server(server=server, force=False)
|
|
250
|
+
pid = PidFile.read()
|
|
251
|
+
assert pid is not None
|
|
250
252
|
#
|
|
251
253
|
subprocess.run(args, env=dict(
|
|
252
254
|
os.environ,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|