Skip to content

Commit

Permalink
Merge pull request #10 from pbcccBeatBoard/main
Browse files Browse the repository at this point in the history
file arrange, dockercompose edit
  • Loading branch information
pbcccbeatboard-strato authored Aug 28, 2024
2 parents 63eaa03 + 726e1ca commit ba84ed2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 55 additions & 23 deletions src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<K8SPodDTO.Container> dtoContainers = podDto.getContainers();

// for in for 바꿔야하나 실제 시간복잡도가 높지 않아 걍 씀
List<V1Container> containers = new ArrayList<>();
for(K8SPodDTO.Container cont: dtoContainers){
V1Container podContainer = new V1Container();
podContainer.setImage(cont.getImage());
podContainer.setImage(cont.getName());
List<V1ContainerPort> 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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}



Expand Down
45 changes: 45 additions & 0 deletions src/main/java/kr/co/mcmp/manifest/K8SPodDTO.java
Original file line number Diff line number Diff line change
@@ -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<Container> containers;
public Map<String, String> labels;
public String restartPolicy;

@Getter
@Setter
public class Container{
public String image;
public String name;
public List<Port> ports;
public Map<String, Quantity> 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;
}

}
6 changes: 6 additions & 0 deletions src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


}
24 changes: 24 additions & 0 deletions src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
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
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 "";
}


}

0 comments on commit ba84ed2

Please sign in to comment.