Commit f2382c1f authored by 黎博's avatar 黎博

新增服务指向接口

parent 1a176db3
......@@ -522,4 +522,16 @@ public class K8sController {
tkeService.clearRubbish(env);
return JsonResult.buildSuccessResult(true);
}
/**
* 修改service指向
* @param namespace 环境
* @param sourceServiceName 源Service
* @param targetServiceName 目标Service
* @return
*/
@PostMapping("/service/redirect")
public JsonResult modifyServiceDirect(String namespace, String sourceServiceName, String targetServiceName) {
return JsonResult.buildSuccessResult(tkeService.modifyServicePointing(namespace, sourceServiceName, targetServiceName));
}
}
......@@ -844,4 +844,19 @@ public class TkeService {
return resultMap;
}
/**
* 修改服务指向
* @param namespace
* @param sourceServiceName
* @param targetServiceName
* @return
*/
public boolean modifyServicePointing(String namespace, String sourceServiceName, String targetServiceName) {
Service service = kubernetesClient.services().inNamespace(namespace).withName(sourceServiceName).get();
service.getSpec().setClusterIP(null);
service.getSpec().getPorts().forEach(servicePort -> servicePort.setTargetPort(null));
service.getSpec().getSelector().put("qcloud-app", targetServiceName);
return kubernetesClient.services().inNamespace(namespace).createOrReplace(service) != 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