diff --git a/docker-compose.yaml b/docker-compose.yaml index 2d9308e..bf80746 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -58,8 +58,8 @@ networks: # application-manager mc-application-manager: - image: pbccc/devops:0.2.5 - container_name: cb-mapui + image: m-cmp/mc-application-manager + container_name: application-manager build: context: ./ dockerfile: Dockerfile diff --git a/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java b/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java index b455c30..8713142 100644 --- a/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java +++ b/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java @@ -20,6 +20,58 @@ @Component public class K8SDeployYamlGenerator { + public String getPod(K8SPodDTO podDto) { + + V1Pod pod = new V1Pod(); + pod.setApiVersion(K8S.Controller.Pod.getApiVersion()); + pod.setKind("Pod"); + + V1ObjectMeta metadata = new V1ObjectMeta(); + metadata.setName(podDto.getPodName()); + metadata.setNamespace(podDto.getNamespace()); + metadata.setLabels(podDto.getLabels()); + pod.setMetadata(metadata); + + V1PodSpec podSpec = new V1PodSpec(); + + List dtoContainers = podDto.getContainers(); + + // for in for 바꿔야하나 실제 시간복잡도가 높지 않아 걍 씀 + List containers = new ArrayList<>(); + for(K8SPodDTO.Container cont: dtoContainers){ + V1Container podContainer = new V1Container(); + podContainer.setImage(cont.getImage()); + podContainer.setImage(cont.getName()); + List podPorts = new ArrayList<>(); + for(K8SPodDTO.Port port: cont.getPorts()) { + V1ContainerPort contPort = new V1ContainerPort(); + contPort.setContainerPort(port.getContainerPort()); + contPort.setHostPort(port.getHostPort()); + contPort.setName(port.getName()); + contPort.setProtocol(port.getProtocol()); + podContainer.addPortsItem(contPort); + } + containers.add(podContainer); + } + + podSpec.setContainers(containers); + podSpec.setRestartPolicy(podDto.getRestartPolicy()); + + pod.setSpec(podSpec); + + StringBuffer buffer = new StringBuffer(); + appendYaml(buffer, pod); + String yaml = buffer.toString(); + + return yaml; + } + + + + + + + public String generateDeployYaml(K8SDeployDTO deploy) { StringBuffer buffer = new StringBuffer(); @@ -51,9 +103,9 @@ public String generateDeployYaml(K8SDeployDTO deploy) { case CronJob: appendYaml(buffer, getCronJob(deploy)); break; - case Pod: - appendYaml(buffer, getPod(deploy)); - break; +// case Pod: +// appendYaml(buffer, getPod(deploy)); +// break; } // service @@ -158,26 +210,6 @@ private V1Deployment getDeployment(K8SDeployDTO deploy) { } - private V1Pod getPod(K8SDeployDTO deploy) { - - V1Pod pod = new V1Pod(); - pod.setApiVersion(K8S.Controller.Pod.getApiVersion()); - pod.setKind(deploy.getController()); - - // metadata - V1ObjectMeta metadata = getControllerMetadata(deploy.getController(), deploy.getName(), deploy.getNamespace(), deploy.getLabels()); - pod.setMetadata(metadata); - - // spec - V1PodSpec podSpec = new V1PodSpec(); - V1Container container = new V1Container(); - container.setName(deploy.getName().replace("KIND", "pod")); - container.setImage(deploy.getImage()); - //pod.setSpec(podSpec); - podSpec.addContainersItem(container); - - return pod; - } diff --git a/src/main/java/kr/co/mcmp/manifest/K8SPodDTO.java b/src/main/java/kr/co/mcmp/manifest/K8SPodDTO.java new file mode 100644 index 0000000..b139227 --- /dev/null +++ b/src/main/java/kr/co/mcmp/manifest/K8SPodDTO.java @@ -0,0 +1,45 @@ +package kr.co.mcmp.manifest; + +import io.kubernetes.client.custom.Quantity; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.Map; + +@Getter +@Setter +public class K8SPodDTO { + + public String podName; + public String namespace; + public List containers; + public Map labels; + public String restartPolicy; + + @Getter + @Setter + public class Container{ + public String image; + public String name; + public List ports; + public Map resource; + /*limits: + cpu: 500m + memory: 1Gi + requests: + cpu: 200m + memory: 256Mi*/ + } + + @Getter + @Setter + public class Port{ + public Integer containerPort; + public Integer hostPort; + public String name; + public String protocol; + } + +} diff --git a/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java b/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java index 01cf456..3e2d972 100644 --- a/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java +++ b/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java @@ -44,5 +44,11 @@ public String generateConfigmapYaml(K8SDeployDTO k8sDto){ return null; } + @Operation(summary = "yaml generate for HPA") + @PostMapping("/hpa") + public String generateHPAYaml(K8SDeployDTO k8sDto){ + return null; + } + } diff --git a/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java b/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java index 31197c7..26f935e 100644 --- a/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java +++ b/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java @@ -1,7 +1,9 @@ package kr.co.mcmp.manifest; +import io.kubernetes.client.openapi.models.V1Pod; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service @@ -9,7 +11,29 @@ public class YamlGenerateService { Logger logger = LoggerFactory.getLogger(YamlGenerateService.class); + @Autowired + K8SDeployYamlGenerator yamlGen; + public String generatePodYaml(K8SPodDTO podContents){ + return yamlGen.getPod(podContents); + } + + public String generateDeploymentYaml(){ + return ""; + } + + public String generateConfigmapYaml(){ + return ""; + } + + public String generateHPAYaml(){ + return ""; + } + + public String generateServiceYaml(){ + return ""; + } + }