sparse-intern-71089
07/26/2022, 1:51 AMicy-pilot-31118
07/26/2022, 1:52 AMfrom typing import Literal, Optional, Sequence, Union
import pulumi_aws as aws
import pulumi_awsx as awsx
import pulumi_eks as eks
import pulumi_kubernetes as k8s
from config.pulumi_secrets import get_pulumi_secrets
from utils.constants import S3_BUCKET
import pulumi
THEIA = "theia"
vpc = awsx.ec2.Vpc(f"{THEIA}-vpc")
# Create an EKS cluster with the default configuration.
cluster = eks.Cluster(
    f"{THEIA}-prod",
    fargate=True,
    vpc_id=vpc.vpc_id,
    private_subnet_ids=vpc.private_subnet_ids,
)
app_name = THEIA
app_labels = {"app": app_name}
repo = awsx.ecr.Repository(THEIA)
image = awsx.ecr.Image(
    THEIA,
    repository_url=repo.url,
    path="..",
)
config = pulumi.Config()
ENVVARS = [
    k8s.core.v1.EnvVarArgs(name=env, value=value)
    for env, value in (tuple(get_pulumi_secrets().items()) + (("ENV", "prod"),))
]
def _get_pod_spec_args(
    *,
    command: Sequence[str],
    restart_policy: Union[
        Literal["Always"], Literal["OnFailure"], Literal["Never"]
    ] = "Always",
    liveness_probe: Optional[pulumi.Input[k8s.core.v1.ProbeArgs]] = None,
) -> k8s.core.v1.PodSpecArgs:
    return k8s.core.v1.PodSpecArgs(
        containers=[
            k8s.core.v1.ContainerArgs(
                name=app_name,
                image=image.image_uri,
                env=ENVVARS,
                command=command,
                liveness_probe=liveness_probe,
                resources=k8s.core.v1.ResourceRequirementsArgs(
                    requests={
                        "cpu": "1",
                        "memory": "4Gi",
                    }
                ),
            )
        ],
        restart_policy=restart_policy,
    )
monitoring_server_deployment = k8s.apps.v1.Deployment(
    f"{app_name}-monitoring-server",
    spec=k8s.apps.v1.DeploymentSpecArgs(
        selector=k8s.meta.v1.LabelSelectorArgs(match_labels=app_labels),
        replicas=1,
        template=k8s.core.v1.PodTemplateSpecArgs(
            metadata=k8s.meta.v1.ObjectMetaArgs(labels=app_labels),
            spec=_get_pod_spec_args(
                command=["python", "monitoring/server.py"],
            ),
        ),
    ),
)
monitoring_service = k8s.core.v1.Service(
    f"{app_name}-monitoring-service",
    spec=k8s.core.v1.ServiceSpecArgs(
        type="LoadBalancer",
        selector=app_labels,
        ports=[k8s.core.v1.ServicePortArgs(port=80)],
    ),
)
# Export the URL for the load balanced service.
pulumi.export(
    "url",
    monitoring_service.status.load_balancer.ingress[0].hostname,
)
# Export the cluster's kubeconfig.
pulumi.export(
    "kubeconfig",
    cluster.kubeconfig,
)billowy-army-68599
billowy-army-68599
icy-pilot-31118
07/26/2022, 1:00 PMicy-pilot-31118
07/26/2022, 1:00 PMicy-pilot-31118
07/26/2022, 1:02 PMicy-pilot-31118
07/26/2022, 1:05 PMicy-pilot-31118
07/26/2022, 1:06 PMicy-pilot-31118
07/26/2022, 1:06 PMbillowy-army-68599
icy-pilot-31118
07/26/2022, 1:08 PMicy-pilot-31118
07/26/2022, 1:08 PMicy-pilot-31118
07/26/2022, 1:38 PMicy-pilot-31118
07/26/2022, 1:38 PMbillowy-army-68599
icy-pilot-31118
07/26/2022, 1:50 PMbillowy-army-68599
icy-pilot-31118
07/26/2022, 1:54 PMicy-pilot-31118
07/26/2022, 1:54 PMbillowy-army-68599
billowy-army-68599
billowy-army-68599
billowy-army-68599
billowy-army-68599
icy-pilot-31118
07/26/2022, 1:59 PMmonitoring_service = k8s.core.v1.Service(
    f"{app_name}-monitoring-service",
    spec=k8s.core.v1.ServiceSpecArgs(
        type="LoadBalancer",
        selector=app_labels,
        ports=[k8s.core.v1.ServicePortArgs(port=80)],
    ),
)icy-pilot-31118
07/26/2022, 1:59 PMicy-pilot-31118
07/26/2022, 2:01 PMicy-pilot-31118
07/26/2022, 2:01 PMicy-pilot-31118
07/26/2022, 2:06 PMicy-pilot-31118
07/26/2022, 2:11 PMicy-pilot-31118
07/26/2022, 2:27 PMicy-pilot-31118
07/26/2022, 2:27 PMbillowy-army-68599
billowy-army-68599
icy-pilot-31118
07/26/2022, 3:04 PMbillowy-army-68599