Commit a9be479e authored by 黎博's avatar 黎博

获取namespace列表时,兼容mysql有多个pod的情况

parent a2223d20
......@@ -141,9 +141,17 @@ public class K8sService {
if (service != null) {
port = service.getSpec().getPorts().get(0).getNodePort();
}
if (podList.size() > 0) {
if (podList.size() == 1) {
host = podList.get(0).getStatus().getHostIP();
}
if (podList.size() >= 2) {
for (Pod pod: podList) {
if (pod.getStatus().getHostIP() != null) {
host = pod.getStatus().getHostIP();
break;
}
}
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......@@ -176,9 +184,17 @@ public class K8sService {
if (service != null) {
port = service.getSpec().getPorts().get(0).getNodePort();
}
if (podList.size() > 0) {
if (podList.size() == 1) {
host = podList.get(0).getStatus().getHostIP();
}
if (podList.size() >= 2) {
for (Pod pod: podList) {
if (pod.getStatus().getHostIP() != null) {
host = pod.getStatus().getHostIP();
break;
}
}
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......@@ -2303,14 +2319,22 @@ public class K8sService {
Map<String, String> labels = new HashMap<>();
labels.put("qcloud-app", "mysql");
labels.put("type", "base");
Pod pod = kubernetesClient.pods().inNamespace("k8s").withLabels(labels).list().getItems().get(0);
System.out.println(pod);
List<Pod> podList = kubernetesClient.pods().inNamespace("vcc").withLabels(labels).list().getItems();
String host = null;
for (Pod pod: podList) {
if (pod.getStatus().getHostIP() != null) {
host = pod.getStatus().getHostIP();
break;
}
}
System.out.println(podList.size());
System.out.println(host);
}
public static void main(String[] args) {
K8sService k8sService = new K8sService();
k8sService.createNewNamespace("test6", "dev", "黎博");
// k8sService.podTest();
// k8sService.createNewNamespace("test6", "dev", "黎博");
k8sService.podTest();
// k8sService.getPodList("k8s");
// System.out.println(JSON.toJSONString(k8sService.getPodListNew("fe")));
// 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