From e84beac4c62b5eb92b768ebb0a12bcbf4932e414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Fri, 7 Jun 2024 11:39:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=A8=A1=E5=9E=8B=E5=8F=AF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=80=E9=98=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/service/impl/JupyterServiceImpl.java | 12 ++++++------ .../java/com/ruoyi/platform/utils/K8sClientUtil.java | 8 ++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java index 01a41535..e7fcf857 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/JupyterServiceImpl.java @@ -12,6 +12,7 @@ import com.ruoyi.platform.utils.MinioUtil; import com.ruoyi.platform.utils.MlflowUtil; import com.ruoyi.system.api.model.LoginUser; import io.kubernetes.client.openapi.models.V1PersistentVolumeClaim; +import io.kubernetes.client.openapi.models.V1Pod; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -103,15 +104,14 @@ public class JupyterServiceImpl implements JupyterService { LoginUser loginUser = SecurityUtils.getLoginUser(); String podName = loginUser.getUsername().toLowerCase() + "-editor-pod"; - + //得到pod + V1Pod pod = k8sClientUtil.getNSPodList(namespace, podName); + if(pod == null){ + return "pod不存在!"; + } // 使用 Kubernetes API 删除 Pod String deleteResult = k8sClientUtil.deletePod(podName, namespace); - // 检查 Pod 是否存在 - boolean exists = k8sClientUtil.checkPodExists(podName, namespace); - if (exists) { - throw new Exception("Pod " + podName + " 删除失败"); - } return deleteResult + ",编辑器已停止"; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java index 9a5a2ab4..febb449e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java @@ -573,12 +573,8 @@ public class K8sClientUtil { V1Pod pod = api.deleteNamespacedPod(podName, namespace, null, null, null, null, null, null); return "Pod " + podName + " 删除请求已发送"; } catch (ApiException e) { - if (e.getCode() == 404) { - return "Pod " + podName + " 不存在"; - } else { - log.error("删除pod异常:" + e.getResponseBody(), e); - throw e; - } + log.error("删除pod异常:" + e.getResponseBody(), e); + throw e; } }