def get_local_kubectl_proxy() -> [str, int]: LOGGER.info("Stop any other process listening on kubectl proxy port") LOCALRUNNER.sudo(f"fuser -v4k {KUBECTL_PROXY_PORT}/tcp", ignore_status=True) LOGGER.info("Start kubectl proxy in detached mode") proxy_port = get_free_port(address='127.0.0.1') LOCALRUNNER.run( f"setsid kubectl proxy --disable-filter --address '127.0.0.1' --port {proxy_port} " "--accept-hosts '.*' > proxy.log 2>&1 < /dev/null & sleep 1") def get_proxy_ip_port(): return LOCALRUNNER.run( "grep -P '^Starting' proxy.log | grep -oP '127.0.0.1:[0-9]+'" ).stdout ip_port = wait_for(get_proxy_ip_port, timeout=15, throw_exc=True) return ip_port.strip().split(':')
def add_hydra_iptables_rules(self, nodes: Optional[list] = None) -> None: add_rules_commands = self.hydra_iptables_redirect_rules(nodes=nodes) del_rules_commands = self.hydra_iptables_redirect_rules(command="D", nodes=nodes) LOCALRUNNER.sudo(shell_script_cmd("\n".join(add_rules_commands))) atexit.register(LOCALRUNNER.sudo, shell_script_cmd("\n".join(del_rules_commands)))