Commit 47cc78c8 authored by 黎博's avatar 黎博

修复/k8s/listEnvVars接口

parent f74fb0f1
......@@ -2290,6 +2290,10 @@ public class K8sService {
String serviceName = pod.getMetadata().getLabels().get("qcloud-app");
serviceName = serviceName.replace("-", "_").toUpperCase();
envMap.put(serviceName + "_SERVICE_HOST", pod.getStatus().getHostIP());
// MYSQL需要额外加个参数
if (serviceName.equals("MYSQL")) {
envMap.put("DB_SERVICE_HOST", pod.getStatus().getHostIP());
}
}
// 遍历Service列表
for (Service service: serviceList) {
......@@ -2297,15 +2301,17 @@ public class K8sService {
List<ServicePort> servicePortList = service.getSpec().getPorts();
if (service.getMetadata().getLabels().get("type").equals("base")) {
if (servicePortList.get(0).getPort() != null) {
envMap.put(serviceName + "_SERVICE_PORT", servicePortList.get(0).getPort());
envMap.put(serviceName + "_SERVICE_PORT", servicePortList.get(0).getNodePort());
// MYSQL需要额外加个参数
if (serviceName.equals("MYSQL")) {
envMap.put("DB_SERVICE_PORT", servicePortList.get(0).getPort());
envMap.put("DB_SERVICE_PORT", servicePortList.get(0).getNodePort());
}
}
for (ServicePort servicePort: servicePortList) {
envMap.put(serviceName + "_SERVICE_PORT_" + servicePort.getPort(), servicePort.getPort());
envMap.put(serviceName + "_SERVICE_PORT_" + servicePort.getPort(), servicePort.getNodePort());
// MYSQL需要额外加个参数
if (serviceName.equals("MYSQL")) {
envMap.put("DB_SERVICE_PORT_" + servicePort.getPort(), servicePort.getPort());
envMap.put("DB_SERVICE_PORT_" + servicePort.getPort(), servicePort.getNodePort());
}
}
} else {
......@@ -2313,11 +2319,10 @@ public class K8sService {
envMap.put(serviceName + "_SERVICE_PORT", servicePortList.get(0).getNodePort());
}
for (ServicePort servicePort: servicePortList) {
if (servicePort.getNodePort() != null) {
if (service.getSpec().getType().equals("NodePort")) {
envMap.put(serviceName + "_SERVICE_PORT_" + servicePort.getPort(), servicePort.getNodePort());
}
if (servicePort.getPort() != null) {
envMap.put(serviceName + "_SERVICE_PORT_" + servicePort.getPort(), servicePort.getPort());
} else if (service.getSpec().getType().equals("ClusterIP")) {
envMap.put(serviceName + "_SERVICE_PORT_" + servicePort.getName(), servicePort.getPort());
}
}
}
......
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