From 857e0db170b381e0bbe48edba330482eb5eebaf5 Mon Sep 17 00:00:00 2001 From: ysh Date: Fri, 18 Jul 2025 15:03:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=BC=82=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/k8sManager/multiple_clusters.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/k8sManager/multiple_clusters.py b/app/k8sManager/multiple_clusters.py index 39378f4..21f08a1 100644 --- a/app/k8sManager/multiple_clusters.py +++ b/app/k8sManager/multiple_clusters.py @@ -82,10 +82,10 @@ async def node_label_opt(params): get_cluster_node_cmd = [f"kubectl label nodes {worker_node} {label} --overwrite"] debug(f'绑定标签命令: {get_cluster_node_cmd}') if username != "root": - results = ssh_utils.ssh_execute_command_noroot(host, port, username, password, + results = await ssh_utils.ssh_execute_command_noroot(host, port, username, password, get_cluster_node_cmd, sudo_timeout=10) # 设置标签可能需要一些时间 else: - results = ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_node_cmd) + results = await ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_node_cmd) overwrite_info = results[0][0].strip() if "not labeled" in overwrite_info: raise f"{worker_node} 绑定标签 {label} 失败,请检查集群节点状态或标签是否已绑定?" @@ -95,10 +95,10 @@ async def node_label_opt(params): get_cluster_node_cmd = [f"kubectl label nodes %s %s-" % (worker_node,label.split('=')[0])] debug(f'解绑标签命令: {get_cluster_node_cmd}') if username != "root": - results = ssh_utils.ssh_execute_command_noroot(host, port, username, password, + results = await ssh_utils.ssh_execute_command_noroot(host, port, username, password, get_cluster_node_cmd, sudo_timeout=10) # 取消标签可能需要一些时间 else: - results = ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_node_cmd) + results = await ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_node_cmd) # debug(f'解绑标签结果: {results}') overwrite_info = results[0][0].strip() if "unlabeled" in overwrite_info or overwrite_info == "": @@ -128,10 +128,10 @@ async def get_cluster_nodes_by_server(params): password = params.get("password") get_cluster_node_cmd = ["kubectl get nodes -o wide --show-labels"] if username != "root": - results = ssh_utils.ssh_execute_command_noroot(host, port, username, password, + results = await ssh_utils.ssh_execute_command_noroot(host, port, username, password, get_cluster_node_cmd, sudo_timeout=10) else: - results = ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_node_cmd) + results = await ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_node_cmd) parse_k8s_nodes_result = results[0][0].strip() parse_k8s_nodes_result = parse_k8s_params.parse_k8s_nodes(parse_k8s_nodes_result) # debug(f'集群 {host=} 所有节点信息如下{results=} => 转换后:\n{parse_k8s_nodes_result=}') @@ -173,10 +173,10 @@ async def get_cluster_pods_by_server(params): # get_cluster_node_cmd = ["kubectl get pods --all-namespaces -o wide"] get_cluster_pod_cmd = ["kubectl get pods --all-namespaces -o wide | grep -Ev 'kube-flannel|kube-system'"] if username != "root": - results = ssh_utils.ssh_execute_command_noroot(host, port, username, password, + results = await ssh_utils.ssh_execute_command_noroot(host, port, username, password, get_cluster_pod_cmd, sudo_timeout=10) else: - results = ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_pod_cmd) + results = await ssh_utils.ssh_execute_command(host, port, username, password, get_cluster_pod_cmd) parse_k8s_pods_result = results[0][0].strip() parse_k8s_pods_result = parse_k8s_params.parse_k8s_pods(parse_k8s_pods_result) # debug(f'集群 {host=} 所有Pod信息如下{results=} => 转换后:\n{parse_k8s_pods_result=}') -- 2.34.1