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 243f4d9..be55468 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 @@ -101,7 +101,6 @@ public class JupyterServiceImpl implements JupyterService { // 调用修改后的 createPod 方法,传入额外的参数 Integer podPort = k8sClientUtil.createConfiguredPod(podName, namespace, port, mountPath, pvc, image, minioPvcName, datasetPath, modelPath); - String url = masterIp + ":" + podPort; redisService.setCacheObject(podName,masterIp + ":" + podPort); devEnvironment.setStatus("Pending"); @@ -119,8 +118,9 @@ public class JupyterServiceImpl implements JupyterService { throw new Exception("开发环境配置不存在"); } LoginUser loginUser = SecurityUtils.getLoginUser(); - //手动构造pod名称 + //构造pod和svc名称 String podName = loginUser.getUsername().toLowerCase() +"-editor-pod" + "-" + id; + String svcName = loginUser.getUsername().toLowerCase() + "-editor-pod" + "-" + id + "-svc"; //得到pod V1Pod pod = k8sClientUtil.getNSPodList(namespace, podName); if(pod == null){ @@ -128,10 +128,13 @@ public class JupyterServiceImpl implements JupyterService { } // 使用 Kubernetes API 删除 Pod String deleteResult = k8sClientUtil.deletePod(podName, namespace); + // 删除service + k8sClientUtil.deleteService(svcName, namespace); devEnvironment.setStatus("Terminated"); this.devEnvironmentService.update(devEnvironment); return deleteResult + ",编辑器已停止"; + } @Override 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 09e6fb0..23903e2 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 @@ -423,7 +423,6 @@ public class K8sClientUtil { .withVolumeMounts(volumeMounts) .endContainer() .withVolumes(volumes) - .withTerminationGracePeriodSeconds(14400L) .endSpec() .build(); @@ -578,6 +577,26 @@ public class K8sClientUtil { } } + + /** + * 删除 Service + * + * @param svcName Service 名称 + * @param namespace 命名空间 + * @throws ApiException 异常 + */ + public String deleteService(String svcName, String namespace) throws ApiException { + CoreV1Api api = new CoreV1Api(apiClient); + try { + V1Status result = api.deleteNamespacedService(svcName, namespace, null, null, null, null, null, null); + return "Service " + svcName + " 删除请求已发送"; + } catch (ApiException e) { + log.error("删除service异常:" + e.getResponseBody(), e); + throw e; + } + } + + /** * 检查 Pod 是否存在 *