Commit 5908c9ae authored by 黎博's avatar 黎博

fix some bug

parent 47240c7f
......@@ -45,7 +45,7 @@ public class K8sController {
* @param namespace 环境
* @return
*/
@GetMapping("/pod/list")
@GetMapping("/service/list")
public JsonResult getServiceList(@RequestParam String namespace) {
List<Map<String, Object>> podList = tkeService.getPodList(namespace);
return JsonResult.buildSuccessResult(podList);
......@@ -53,29 +53,30 @@ public class K8sController {
/**
* 根据服务名称获取镜像列表
* @param serviceName 服务名称
* @param repoName 服务名称
* @return
*/
@GetMapping("/image/list")
public JsonResult getImageListByServiceName(@RequestParam String serviceName) {
return JsonResult.buildSuccessResult(imageService.getImageListByService(serviceName));
public JsonResult getImageListByServiceName(@RequestParam String repoName) {
return JsonResult.buildSuccessResult(imageService.getImageListByService(repoName));
}
/**
* 新增pod
* 新增deployment, 如果service和pvc没有,也会同时创建
* @param serviceCreateVo 创建实体类
* @return
*/
@PostMapping("/pod/create")
@PostMapping("/service/create")
public JsonResult createPod(@RequestBody ServiceCreateVo serviceCreateVo) {
try {
String serviceName = serviceCreateVo.getServiceName();
String type = serviceCreateVo.getType();
String label = serviceCreateVo.getLabel();
String namespace = serviceCreateVo.getNamespace();
String image = serviceCreateVo.getImage();
QueryWrapper<DockerProject> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("project_name", serviceName);
if (type.equals("base")) {
if (label.equals("base")) {
// Service
if (!tkeService.queryIfServiceExistByName(namespace, serviceName)) {
if (serviceName.equals("mysql")) {
......@@ -99,9 +100,10 @@ public class K8sController {
if (serviceName.equals("mysql")) {
tkeService.createMysqlPvc(namespace);
}
if (serviceName.equals("redis")) {
tkeService.createRedisPvc(namespace);
}
// redis不需要pvc
// if (serviceName.equals("redis")) {
// tkeService.createRedisPvc(namespace);
// }
if (serviceName.equals("mongodb")) {
tkeService.createMongodbPvc(namespace);
}
......@@ -130,7 +132,7 @@ public class K8sController {
tkeService.createRabbitmqDeployment(namespace, image);
}
}
} else if (type.equals("java")) {
} else if (label.equals("java")) {
DockerProject dockerProject = dockerProjectService.getOne(queryWrapper);
if (!tkeService.queryIfServiceExistByName(namespace, serviceName)) {
tkeService.createJavaService(namespace, serviceName);
......@@ -138,9 +140,8 @@ public class K8sController {
if (!tkeService.queryIfDeploymentExistByName(namespace, serviceName)) {
tkeService.createJavaDeployment(serviceCreateVo, dockerProject);
}
} else if (type.equals("ui") || type.equals("node")) {
} else if (label.equals("ui") || label.equals("node")) {
DockerProject dockerProject = dockerProjectService.getOne(queryWrapper);
String label = serviceCreateVo.getLabel();
if (!tkeService.queryIfServiceExistByName(namespace, serviceName)) {
tkeService.createUIAndNodeService(namespace, serviceName, type, label);
}
......@@ -163,19 +164,19 @@ public class K8sController {
* @param podName podName
* @return
*/
@PostMapping("/pod/redeploy")
@PostMapping("/service/redeploy")
public JsonResult resetPodByName(String namespace, String podName) {
return JsonResult.buildSuccessResult(tkeService.resetPod(namespace, podName));
}
/**
* 更新部署
* 实际上是更新pod
* @param namespace 环境
* @param serviceName 服务名
* @param image 镜像名
* @return
*/
@PostMapping("/pod/modify")
@PostMapping("/service/modify")
public JsonResult modifyPod(String namespace, String serviceName, String image) {
return JsonResult.buildSuccessResult(tkeService.updateDeployment(namespace, serviceName, image));
}
......@@ -186,7 +187,7 @@ public class K8sController {
* @param serviceName 服务名称
* @return
*/
@PostMapping("/pod/delete")
@PostMapping("/service/delete")
public JsonResult deletePodByName(String namespace, String serviceName) {
return JsonResult.buildSuccessResult(tkeService.deleteDeployment(namespace, serviceName));
}
......
package cn.qg.holmes.service.k8s;
import com.alibaba.fastjson.JSON;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.tcr.v20190924.TcrClient;
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalRequest;
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalResponse;
import com.tencentcloudapi.tcr.v20190924.models.TagInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 镜像仓库相关服务
* @author libo 2021
......@@ -34,16 +40,15 @@ public class ImageService {
/**
* 根据服务名获取镜像列表
* @param serviceName 服务名
* @param repoName 服务名
* @return
*/
public String getImageListByService(String serviceName) {
public Map<String, Object> getImageListByService(String repoName) {
try {
String repoName = "qa-test/" + serviceName;
DescribeImagePersonalRequest request = new DescribeImagePersonalRequest();
request.setRepoName(repoName);
DescribeImagePersonalResponse response = tcrClient.DescribeImagePersonal(request);
return DescribeImagePersonalResponse.toJsonString(response);
return JSON.parseObject(DescribeImagePersonalResponse.toJsonString(response.getData()), Map.class);
} catch (Exception e) {
e.printStackTrace();
return null;
......
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