|
|
|
@@ -1,6 +1,8 @@ |
|
|
|
package com.ruoyi.platform.utils; |
|
|
|
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.reflect.TypeToken; |
|
|
|
import com.ruoyi.platform.constant.Constant; |
|
|
|
import com.ruoyi.platform.mapper.ComputingResourceDao; |
|
|
|
import io.kubernetes.client.Exec; |
|
|
|
import io.kubernetes.client.custom.IntOrString; |
|
|
|
import io.kubernetes.client.custom.Quantity; |
|
|
|
@@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.util.*; |
|
|
|
@@ -40,6 +43,8 @@ public class K8sClientUtil { |
|
|
|
*/ |
|
|
|
private static ApiClient apiClient; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ComputingResourceDao computingResourceDao; |
|
|
|
/** |
|
|
|
* 构建集群POD内通过SA访问的客户端 |
|
|
|
* loading the in-cluster config, including: |
|
|
|
@@ -409,8 +414,6 @@ public class K8sClientUtil { |
|
|
|
.namespaces(Collections.singletonList(namespace)) |
|
|
|
.topologyKey("kubernetes.io/hostname"); |
|
|
|
|
|
|
|
// V1WeightedPodAffinityTerm weightedPodAffinityTerm = new V1WeightedPodAffinityTerm().weight(100).podAffinityTerm(podAffinityTerm); |
|
|
|
|
|
|
|
V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() |
|
|
|
.requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); |
|
|
|
|
|
|
|
@@ -469,6 +472,8 @@ public class K8sClientUtil { |
|
|
|
|
|
|
|
try { |
|
|
|
pod = api.createNamespacedPod(namespace, pod, null, null, null); |
|
|
|
String nodeName = getNodeName(podName, namespace); |
|
|
|
computingResourceDao.updateUsedStateByNode(nodeName, Constant.Used_State_used); |
|
|
|
} catch (ApiException e) { |
|
|
|
log.error("创建pod异常:" + e.getResponseBody(), e); |
|
|
|
} catch (Exception e) { |
|
|
|
@@ -569,6 +574,12 @@ public class K8sClientUtil { |
|
|
|
return pod.getStatus().getHostIP(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getNodeName(String podName, String namespace) throws Exception { |
|
|
|
CoreV1Api api = new CoreV1Api(apiClient); |
|
|
|
V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); |
|
|
|
return pod.getSpec().getNodeName(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getPodLogs(String podName,String namespace,String container,int line) { |
|
|
|
CoreV1Api api = new CoreV1Api(apiClient); |
|
|
|
try { |
|
|
|
|