Fix deployment
This commit is contained in:
parent
d5e188c4d2
commit
a304bb16cb
@ -23,6 +23,8 @@ from app.util import get_yaml
|
|||||||
class ClusterInfo:
|
class ClusterInfo:
|
||||||
parsed_pod_yaml_map: Any = {}
|
parsed_pod_yaml_map: Any = {}
|
||||||
image_set: Set[str] = set()
|
image_set: Set[str] = set()
|
||||||
|
app_name: str = "test-app"
|
||||||
|
deployment_name: str = "test-deployment"
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
@ -46,32 +48,37 @@ class ClusterInfo:
|
|||||||
print(f"image_set: {self.image_set}")
|
print(f"image_set: {self.image_set}")
|
||||||
|
|
||||||
def get_deployment(self):
|
def get_deployment(self):
|
||||||
|
containers = []
|
||||||
|
for pod_name in self.parsed_pod_yaml_map:
|
||||||
|
pod = self.parsed_pod_yaml_map[pod_name]
|
||||||
|
services = pod["services"]
|
||||||
|
for service_name in services:
|
||||||
|
container_name = service_name
|
||||||
|
service_info = services[service_name]
|
||||||
|
image = service_info["image"]
|
||||||
container = client.V1Container(
|
container = client.V1Container(
|
||||||
name="container-name",
|
name=container_name,
|
||||||
image="image-tag",
|
image=image,
|
||||||
ports=[client.V1ContainerPort(container_port=80)],
|
ports=[client.V1ContainerPort(container_port=80)],
|
||||||
resources=client.V1ResourceRequirements(
|
resources=client.V1ResourceRequirements(
|
||||||
requests={"cpu": "100m", "memory": "200Mi"},
|
requests={"cpu": "100m", "memory": "200Mi"},
|
||||||
limits={"cpu": "500m", "memory": "500Mi"},
|
limits={"cpu": "500m", "memory": "500Mi"},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
containers.append(container)
|
||||||
template = client.V1PodTemplateSpec(
|
template = client.V1PodTemplateSpec(
|
||||||
metadata=client.V1ObjectMeta(labels={"app": "app-name"}),
|
metadata=client.V1ObjectMeta(labels={"app": self.app_name}),
|
||||||
spec=client.V1PodSpec(containers=[container]),
|
spec=client.V1PodSpec(containers=containers),
|
||||||
)
|
)
|
||||||
|
|
||||||
spec = client.V1DeploymentSpec(
|
spec = client.V1DeploymentSpec(
|
||||||
replicas=3, template=template, selector={
|
replicas=3, template=template, selector={
|
||||||
"matchLabels":
|
"matchLabels":
|
||||||
{"app": "app-name"}})
|
{"app": self.app_name}})
|
||||||
|
|
||||||
deployment = client.V1Deployment(
|
deployment = client.V1Deployment(
|
||||||
api_version="apps/v1",
|
api_version="apps/v1",
|
||||||
kind="Deployment",
|
kind="Deployment",
|
||||||
metadata=client.V1ObjectMeta(name="deployment-name"),
|
metadata=client.V1ObjectMeta(name=self.deployment_name),
|
||||||
spec=spec,
|
spec=spec,
|
||||||
)
|
)
|
||||||
|
|
||||||
return deployment
|
return deployment
|
||||||
|
Loading…
Reference in New Issue
Block a user