From 9b899ffb50fdc25141543c0d1908573c7cdddc55 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 14 Oct 2024 10:10:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20Kubernetes=20client=20=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/api/engine/KubernetesProvider.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/engine/KubernetesProvider.java b/backend/services/api-test/src/main/java/io/metersphere/api/engine/KubernetesProvider.java index d97e4ab79c..9c4661b5b8 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/engine/KubernetesProvider.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/engine/KubernetesProvider.java @@ -30,12 +30,15 @@ public class KubernetesProvider { private static final String RUNNING_PHASE = "Running"; private static final String SHELL_COMMAND = "sh"; private static final String LOCAL_URL = "http://127.0.0.1:8000"; + private static final int TIMEOUT = 120000; public static KubernetesClient getKubernetesClient(TestResourceDTO credential) { ConfigBuilder configBuilder = new ConfigBuilder() .withMasterUrl(credential.getIp()) .withOauthToken(credential.getToken()) .withTrustCerts(true) + .withConnectionTimeout(TIMEOUT) // 120秒连接超时 + .withRequestTimeout(TIMEOUT) // 120秒请求超时 .withNamespace(credential.getNamespace()); return new KubernetesClientBuilder() @@ -223,12 +226,14 @@ public class KubernetesProvider { "-X POST -d '%s' " + "--connect-timeout %d " + "--max-time %d " + + "--retry-max-time %d" + "--retry %d " + "%s%s", optToken, // otp-token JSON.toFormatJSONString(request), // 请求体 30, // 连接超时(秒) 120, // 最大时间(秒) + 3, // 最大重试时间(秒) 3, // 重试次数 LOCAL_URL, // 本地 URL path // 具体 API 路径