|
|
|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson2.JSON; |
|
|
|
import com.ruoyi.platform.constant.Constant; |
|
|
|
import com.ruoyi.platform.domain.DevEnvironment; |
|
|
|
import com.ruoyi.platform.mapper.ComputingResourceDao; |
|
|
|
import io.fabric8.kubernetes.api.model.SecurityContext; |
|
|
|
import io.fabric8.kubernetes.api.model.SecurityContextBuilder; |
|
|
|
import io.kubernetes.client.Exec; |
|
|
|
import io.kubernetes.client.custom.IntOrString; |
|
|
|
import io.kubernetes.client.custom.Quantity; |
|
|
|
@@ -12,7 +14,9 @@ import io.kubernetes.client.openapi.ApiException; |
|
|
|
import io.kubernetes.client.openapi.apis.AppsV1Api; |
|
|
|
import io.kubernetes.client.openapi.apis.CoreV1Api; |
|
|
|
import io.kubernetes.client.openapi.models.*; |
|
|
|
import io.kubernetes.client.util.ClientBuilder; |
|
|
|
import io.kubernetes.client.util.Config; |
|
|
|
import io.kubernetes.client.util.credentials.AccessTokenAuthentication; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.json.JSONObject; |
|
|
|
@@ -356,14 +360,14 @@ public class K8sClientUtil { |
|
|
|
.withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) |
|
|
|
.withVolumeMounts(new V1VolumeMount().name("workspace").mountPath(mountPath).subPath(subPath)) |
|
|
|
.withNewSecurityContext().withNewPrivileged(true).endSecurityContext() |
|
|
|
.addNewEnv() |
|
|
|
.withName("HTTP_PROXY") |
|
|
|
.withValue("http://172.20.32.253:3128") |
|
|
|
.endEnv() |
|
|
|
.addNewEnv() |
|
|
|
.withName("HTTPS_PROXY") |
|
|
|
.withValue("http://172.20.32.253:3128") |
|
|
|
.endEnv() |
|
|
|
// .addNewEnv() |
|
|
|
// .withName("HTTP_PROXY") |
|
|
|
// .withValue("http://172.20.32.253:3128") |
|
|
|
// .endEnv() |
|
|
|
// .addNewEnv() |
|
|
|
// .withName("HTTPS_PROXY") |
|
|
|
// .withValue("http://172.20.32.253:3128") |
|
|
|
// .endEnv() |
|
|
|
.addNewEnv() |
|
|
|
.withName("NO_PROXY") |
|
|
|
.withValue("localhost,kubernetes.default.svc") |
|
|
|
@@ -493,7 +497,7 @@ public class K8sClientUtil { |
|
|
|
.endContainer() |
|
|
|
.withVolumes(volumes) |
|
|
|
.withNodeSelector(nodeSelector) |
|
|
|
.withAffinity(v1Affinity) |
|
|
|
// .withAffinity(v1Affinity) |
|
|
|
.endSpec() |
|
|
|
.build(); |
|
|
|
|
|
|
|
@@ -625,8 +629,8 @@ public class K8sClientUtil { |
|
|
|
public V1Pod createPodWithEnv(String podName, String namespace, String proxyUrl, String mountPath, String pvcName, String image) { |
|
|
|
CoreV1Api api = new CoreV1Api(apiClient); |
|
|
|
|
|
|
|
V1SecurityContext v1SecurityContext = new V1SecurityContext(); |
|
|
|
v1SecurityContext.setPrivileged(true); |
|
|
|
// V1SecurityContext v1SecurityContext = new V1SecurityContext(); |
|
|
|
// v1SecurityContext.setPrivileged(true); |
|
|
|
|
|
|
|
// 配置卷和卷挂载 |
|
|
|
List<V1VolumeMount> volumeMounts = new ArrayList<>(); |
|
|
|
@@ -643,18 +647,18 @@ public class K8sClientUtil { |
|
|
|
.addNewContainer() |
|
|
|
.withName(podName) |
|
|
|
.withImage(image) // 替换为您实际要使用的镜像名称 |
|
|
|
.withSecurityContext(v1SecurityContext) |
|
|
|
// .withSecurityContext(v1SecurityContext) |
|
|
|
// .withVolumeMounts(new V1VolumeMount().name("workspace").mountPath(mountPath)) |
|
|
|
.withVolumeMounts(volumeMounts) |
|
|
|
.withNewSecurityContext().withNewPrivileged(true).endSecurityContext() |
|
|
|
.addNewEnv() |
|
|
|
.withName("HTTP_PROXY") |
|
|
|
.withValue(proxyUrl) |
|
|
|
.endEnv() |
|
|
|
.addNewEnv() |
|
|
|
.withName("HTTPS_PROXY") |
|
|
|
.withValue(proxyUrl) |
|
|
|
.endEnv() |
|
|
|
// .addNewEnv() |
|
|
|
// .withName("HTTP_PROXY") |
|
|
|
// .withValue(proxyUrl) |
|
|
|
// .endEnv() |
|
|
|
// .addNewEnv() |
|
|
|
// .withName("HTTPS_PROXY") |
|
|
|
// .withValue(proxyUrl) |
|
|
|
// .endEnv() |
|
|
|
.addNewEnv() |
|
|
|
.withName("NO_PROXY") |
|
|
|
.withValue("localhost,kubernetes.default.svc") |
|
|
|
|