|
|
@@ -1,5 +1,6 @@
|
|
|
package seecoder.devcloud.core.pipeline.handler;
|
|
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.HttpStatus;
|
|
|
import seecoder.devcloud.api.ApplicationProperties;
|
|
|
@@ -16,6 +17,7 @@ import seecoder.devcloud.core.pipeline.Context;
|
|
|
import seecoder.devcloud.core.pipeline.PipelineException;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author PuHong Weng
|
|
|
@@ -43,6 +45,40 @@ public class K8sDeploymentHandler extends AbstractHandler {
|
|
|
deploymentApi = SpringUtil.getBean(DeploymentApi.class);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 环境变量配置
|
|
|
+ */
|
|
|
+ @JsonProperty("envs")
|
|
|
+ private Map<String, String> envs;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启动参数配置 CMD space split
|
|
|
+ */
|
|
|
+ @JsonProperty("runArgs")
|
|
|
+ private String runArgs;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行命令配置 ENTRYPOINT space split
|
|
|
+ */
|
|
|
+ @JsonProperty("runCommands")
|
|
|
+ private String runCommands;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 挂载文件配置
|
|
|
+ */
|
|
|
+ @JsonProperty("mounts")
|
|
|
+ private Map<String, String> mounts;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * key:pvcName
|
|
|
+ * value:pvcValue
|
|
|
+ */
|
|
|
+ @JsonProperty("pvcPaths")
|
|
|
+ private Map<String, String> pvcPaths;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 部署一个java项目
|
|
|
* 以小组名称作为namespace
|
|
|
@@ -57,7 +93,7 @@ public class K8sDeploymentHandler extends AbstractHandler {
|
|
|
int port = Integer.parseInt(context.getConfigs().get("port"));
|
|
|
int replicas = 1;
|
|
|
String namespace = context.getNamespace();
|
|
|
- String projectName = context.getProjectName();
|
|
|
+ String deployName = context.getDeployName();
|
|
|
|
|
|
//1. 配置容器暴露端口
|
|
|
ContainerPort containerPort = ContainerPort.builder()
|
|
|
@@ -67,7 +103,7 @@ public class K8sDeploymentHandler extends AbstractHandler {
|
|
|
//2. 配置容器
|
|
|
Container container = Container.builder()
|
|
|
.image(applicationProperties.getDocker().getRegistry()+"/"+imageName+":"+imageTag)
|
|
|
- .name(projectName + K8sConstants.CONTAINER_SUFFIX)
|
|
|
+ .name(deployName + K8sConstants.CONTAINER_SUFFIX)
|
|
|
.ports(Collections.singleton(containerPort))
|
|
|
.build();
|
|
|
|
|
|
@@ -76,9 +112,12 @@ public class K8sDeploymentHandler extends AbstractHandler {
|
|
|
.replicas(replicas)
|
|
|
.containers(Collections.singletonList(container))
|
|
|
.build();
|
|
|
- deployment.setName(projectName + K8sConstants.DEPLOYMENT_SUFFIX);
|
|
|
+ deployment.setName(deployName + K8sConstants.DEPLOYMENT_SUFFIX);
|
|
|
deployment.setNamespace(namespace);
|
|
|
- deployment.setLabel(K8sConstants.APPLICATION_LABEL, projectName);
|
|
|
+ deployment.setLabel(K8sConstants.APPLICATION_LABEL, deployName);
|
|
|
+
|
|
|
+ //4. 检测是否需要挂载配置文件
|
|
|
+ //deployment.setVolumes();
|
|
|
|
|
|
|
|
|
//3. 检查镜像仓库secret是否存在,没有则创建。
|
|
|
@@ -93,6 +132,10 @@ public class K8sDeploymentHandler extends AbstractHandler {
|
|
|
);
|
|
|
}
|
|
|
deployment.setImagePullSecrets(Collections.singletonList(DEFAULT_IMAGE_PULL_SECRET_NAME));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//4. 创建Deployment。
|
|
|
try {
|
|
|
deploymentApi.create(deployment);
|