Commit 2bec8ad8 authored by 黎博's avatar 黎博

Merge branch 'master' into pipline

parents 5662bc7c 6e68f512
...@@ -2102,7 +2102,14 @@ public class K8sService { ...@@ -2102,7 +2102,14 @@ public class K8sService {
labelMap.put("type", serviceType); labelMap.put("type", serviceType);
labelMap.put("qcloud-app", serviceName); labelMap.put("qcloud-app", serviceName);
labelSelector.setMatchLabels(labelMap); labelSelector.setMatchLabels(labelMap);
return kubernetesClient.pods().inNamespace(namespace).withLabelSelector(labelSelector).list().getItems().get(0); List<Pod> podList = kubernetesClient.pods().inNamespace(namespace).withLabelSelector(labelSelector).list().getItems();
for (Pod pod: podList) {
// pod可能有多个,返回Running状态的pod
if (pod.getStatus().getPhase().equals("Running")) {
return pod;
}
}
return null;
} }
/** /**
...@@ -2116,7 +2123,7 @@ public class K8sService { ...@@ -2116,7 +2123,7 @@ public class K8sService {
Service service = getServiceDetail(namespace, serviceName); Service service = getServiceDetail(namespace, serviceName);
Pod pod = getPodDetail(namespace, serviceType, serviceName); Pod pod = getPodDetail(namespace, serviceType, serviceName);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
if (pod.getStatus().getPhase().equals("Running")) { if (pod != null && pod.getStatus().getPhase().equals("Running")) {
// 端口映射 // 端口映射
List<Map<String, Object>> portMappingList = new ArrayList<>(); List<Map<String, Object>> portMappingList = new ArrayList<>();
ObjectMeta podMetadata = pod.getMetadata(); ObjectMeta podMetadata = pod.getMetadata();
...@@ -2378,7 +2385,8 @@ public class K8sService { ...@@ -2378,7 +2385,8 @@ public class K8sService {
public static void main(String[] args) { public static void main(String[] args) {
K8sService k8sService = new K8sService(); K8sService k8sService = new K8sService();
// k8sService.createNewNamespace("test6", "dev", "黎博"); // k8sService.createNewNamespace("test6", "dev", "黎博");
k8sService.podTest(); // k8sService.podTest();
System.out.println(k8sService.getPodAndServiceInfo("vcc2", "java", "vcc-quota-service"));
// k8sService.getPodList("k8s"); // k8sService.getPodList("k8s");
// System.out.println(JSON.toJSONString(k8sService.getPodListNew("fe"))); // System.out.println(JSON.toJSONString(k8sService.getPodListNew("fe")));
// if (!k8sService.queryIfServiceExistByName("fe", "lxq-ui")) { // if (!k8sService.queryIfServiceExistByName("fe", "lxq-ui")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment