Commit 5906dbaa authored by 黎博's avatar 黎博

merge

parents 5f0c8005 9c7ad798
...@@ -9,6 +9,7 @@ import cn.qg.holmes.service.auth.TokenService; ...@@ -9,6 +9,7 @@ import cn.qg.holmes.service.auth.TokenService;
import cn.qg.holmes.service.k8s.*; import cn.qg.holmes.service.k8s.*;
import cn.qg.holmes.utils.MongoUtils; import cn.qg.holmes.utils.MongoUtils;
import cn.qg.holmes.utils.RedisUtils; import cn.qg.holmes.utils.RedisUtils;
import cn.qg.holmes.utils.YamlUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tencentcloudapi.tcr.v20190924.models.RepoInfo; import com.tencentcloudapi.tcr.v20190924.models.RepoInfo;
...@@ -121,7 +122,10 @@ public class K8sController { ...@@ -121,7 +122,10 @@ public class K8sController {
tkeService.createIngressByYaml(serviceCreateVo); tkeService.createIngressByYaml(serviceCreateVo);
} }
// 新增Service // 新增Service
tkeService.createServiceByYaml(serviceCreateVo); Service service = tkeService.createServiceByYaml(serviceCreateVo);
// 休眠3秒,防止创建服务的时候获取不到Service暴露的端口
Thread.sleep(3000);
log.info("/service/create创建Deployment前,Service状态:{}", YamlUtils.JsonToYamlStr(JSON.toJSONString(service)));
// 新增Deployment // 新增Deployment
tkeService.createDeploymentByYaml(serviceCreateVo); tkeService.createDeploymentByYaml(serviceCreateVo);
} catch (Exception e) { } catch (Exception e) {
...@@ -182,14 +186,17 @@ public class K8sController { ...@@ -182,14 +186,17 @@ public class K8sController {
Service service = tkeService.getServiceDetail(namespace, serviceName); Service service = tkeService.getServiceDetail(namespace, serviceName);
if (service == null) { if (service == null) {
// 创建或替换Service // 创建或替换Service
tkeService.createServiceByYaml(serviceCreateVo); service = tkeService.createServiceByYaml(serviceCreateVo);
try { }
Thread.sleep(3000);
} catch (InterruptedException e) { // 休眠5秒,防止服务启动时获取不到Service暴露出来的端口
e.printStackTrace(); try {
} Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} }
log.info("/service/modify创建Deployment前,Service状态:{}", YamlUtils.JsonToYamlStr(JSON.toJSONString(service)));
// 创建或替换Deployment // 创建或替换Deployment
tkeService.createDeploymentByYaml(serviceCreateVo); tkeService.createDeploymentByYaml(serviceCreateVo);
// 创建或替换Ingress // 创建或替换Ingress
...@@ -503,7 +510,10 @@ public class K8sController { ...@@ -503,7 +510,10 @@ public class K8sController {
@RequestParam String serviceType, @RequestParam String serviceType,
@RequestParam String serviceName, @RequestParam String serviceName,
@RequestParam String key) { @RequestParam String key) {
List<ServicePort> servicePortList = tkeService.getServiceDetail(namespace, serviceName).getSpec().getPorts(); log.info("开始调取/k8s/dubbo/port接口,namespace:{}, serviceName: {}, key: {}", namespace, serviceName, key);
Service service = tkeService.getServiceDetail(namespace, serviceName);
log.info("获取到的Service信息:{}", JSON.toJSONString(service));
List<ServicePort> servicePortList = service.getSpec().getPorts();
Map<String, Object> serviceMap = new HashMap<>(); Map<String, Object> serviceMap = new HashMap<>();
List<Map<String, Object>> portMappingList = new ArrayList<>(); List<Map<String, Object>> portMappingList = new ArrayList<>();
if (servicePortList.size() > 0) { if (servicePortList.size() > 0) {
......
...@@ -672,7 +672,7 @@ public class TkeService { ...@@ -672,7 +672,7 @@ public class TkeService {
if (serviceCreateVo.getDebug() == 1) { if (serviceCreateVo.getDebug() == 1) {
service.getSpec().setType("NodePort"); service.getSpec().setType("NodePort");
} }
log.info("开始在{}环境创建{}服务的k8s Service: \n{}", namespace, serviceName, serviceYaml); log.info("开始在{}环境创建{}服务的k8s Service: \n{}", namespace, serviceName, YamlUtils.JsonToYamlStr(JSON.toJSONString(service)));
return kubernetesClient.services().inNamespace(namespace).createOrReplace(service); return kubernetesClient.services().inNamespace(namespace).createOrReplace(service);
} catch (IOException e) { } catch (IOException e) {
log.info("Service创建失败."); log.info("Service创建失败.");
......
...@@ -55,7 +55,7 @@ spec: ...@@ -55,7 +55,7 @@ spec:
# 数据持久化 # 数据持久化
volumeMounts: volumeMounts:
- name: rabbitmq - name: rabbitmq
mountPath: "/var/lib/rabbitmq" mountPath: /var/lib/rabbitmq
volumes: volumes:
- name: rabbitmq - name: rabbitmq
persistentVolumeClaim: persistentVolumeClaim:
......
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