Skip to content

Commit 8ff205c

Browse files
committed
fix
1 parent 3e38105 commit 8ff205c

File tree

1 file changed

+8
-15
lines changed
  • src/aks-preview/azext_aks_preview/bastion

1 file changed

+8
-15
lines changed

src/aks-preview/azext_aks_preview/bastion/bastion.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ async def _aks_bastion_launch_subshell(kubeconfig_path, port):
246246
# attempt to terminate the subshell process gracefully
247247
if subshell_process is not None:
248248
logger.info("Subshell was cancelled. Terminating...")
249-
if subshell_process.stdin:
250-
subshell_process.stdin.close()
251249
subshell_process.terminate()
252250
try:
253251
await asyncio.wait_for(subshell_process.wait(), timeout=5)
@@ -269,33 +267,28 @@ async def _aks_bastion_launch_tunnel(nrg, bastion, port, mc_id):
269267

270268
tunnel_proces = None
271269
try:
270+
az_cmd_name = _aks_bastion_get_az_cmd_name()
272271
cmd = (
273-
f"az network bastion tunnel --resource-group {nrg} "
272+
f"{az_cmd_name} network bastion tunnel --resource-group {nrg} "
274273
f"--name {bastion} --port {port} --target-resource-id {mc_id} --resource-port 443"
275274
)
276275
logger.debug("Creating bastion tunnel with command: %s", cmd)
277-
tunnel_proces = await asyncio.create_subprocess_shell(
278-
cmd,
276+
tunnel_proces = await asyncio.create_subprocess_exec(
277+
*(cmd.split()),
279278
stdin=asyncio.subprocess.DEVNULL,
280-
stdout=asyncio.subprocess.PIPE,
281-
stderr=asyncio.subprocess.PIPE,
282-
shell=True,
279+
stdout=asyncio.subprocess.DEVNULL,
280+
stderr=asyncio.subprocess.DEVNULL,
281+
shell=False,
283282
)
284283
logger.info("Tunnel launched with PID: %s", tunnel_proces.pid)
285284

286285
# tunnel process must not exit unless it encounters a failure or is deliberately shut down
287-
stdout, stderr = await tunnel_proces.communicate()
286+
await tunnel_proces.wait()
288287
logger.error("Bastion tunnel exited with code %s", tunnel_proces.returncode)
289-
if stdout:
290-
logger.warning("Tunnel process stdout: %s", stdout.decode("utf-8"))
291-
if stderr:
292-
logger.error("Tunnel process stderr: %s", stderr.decode("utf-8"))
293288
except asyncio.CancelledError:
294289
# attempt to terminate the tunnel process gracefully
295290
if tunnel_proces is not None:
296291
logger.info("Tunnel process was cancelled. Terminating...")
297-
if tunnel_proces.stdin:
298-
tunnel_proces.stdin.close()
299292
tunnel_proces.terminate()
300293
try:
301294
await asyncio.wait_for(tunnel_proces.wait(), timeout=5)

0 commit comments

Comments
 (0)