|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from transpire.resources import Deployment, Secret, Service |
| 4 | +from transpire.types import Image, ContainerRegistry |
| 5 | +from transpire.utils import get_image_tag |
| 6 | + |
| 7 | +name = "create" |
| 8 | +auto_sync = True |
| 9 | + |
| 10 | + |
| 11 | +def images(): |
| 12 | + yield Image(name="create", path=Path("/"), registry=ContainerRegistry("ghcr")) |
| 13 | + |
| 14 | + |
| 15 | +def add_probes(dep): |
| 16 | + dep.obj.spec.template.spec.containers[0].readiness_probe = { |
| 17 | + "exec": { |
| 18 | + "command": ["python", "-m", "create.healthcheck"], |
| 19 | + }, |
| 20 | + "initialDelaySeconds": 15, |
| 21 | + "periodSeconds": 15, |
| 22 | + } |
| 23 | + |
| 24 | + dep.obj.spec.template.spec.containers[0].liveness_probe = { |
| 25 | + "exec": { |
| 26 | + "command": ["python", "-m", "create.healthcheck"], |
| 27 | + }, |
| 28 | + "initialDelaySeconds": 15, |
| 29 | + "periodSeconds": 15, |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | +def add_volumes(dep): |
| 34 | + dep.obj.spec.template.spec.volumes = [ |
| 35 | + {"name": "nfs-export-home", "nfs": {"path": "/opt/homes/home", "server": "homes"}}, |
| 36 | + {"name": "nfs-export-services", "nfs": {"path": "/opt/homes/services", "server": "services"}}, |
| 37 | + {"name": "secrets", "secret": {"secretName": "create"}}, |
| 38 | + ] |
| 39 | + |
| 40 | + dep.obj.spec.template.spec.containers[0].volume_mounts = [ |
| 41 | + {"name": "nfs-export-home", "mountPath": "/home"}, |
| 42 | + {"name": "nfs-export-services", "mountPath": "/services"}, |
| 43 | + {"name": "secrets", "mountPath": "/etc/ocf-create", "readOnly": True}, |
| 44 | + ] |
| 45 | + |
| 46 | + |
| 47 | +def objects(): |
| 48 | + dep = Deployment( |
| 49 | + name="create", |
| 50 | + image=get_image_tag("create"), |
| 51 | + ports=[6378], |
| 52 | + ) |
| 53 | + |
| 54 | + dep.obj.spec.template.spec.dns_policy = "ClusterFirst" |
| 55 | + dep.obj.spec.template.spec.dns_config = {"searches": ["ocf.berkeley.edu"]} |
| 56 | + |
| 57 | + add_probes(dep) |
| 58 | + add_volumes(dep) |
| 59 | + |
| 60 | + svc = Service( |
| 61 | + name="create", |
| 62 | + selector=dep.get_selector(), |
| 63 | + port_on_pod=6378, |
| 64 | + port_on_svc=6378, |
| 65 | + ) |
| 66 | + |
| 67 | + sec = Secret( |
| 68 | + name="create", |
| 69 | + string_data={ |
| 70 | + "create.key": "", |
| 71 | + "create.keytab": "", |
| 72 | + "create.pub": "", |
| 73 | + "create-redis.key": "", |
| 74 | + "ocf-create.conf": "", |
| 75 | + }, |
| 76 | + ) |
| 77 | + |
| 78 | + yield dep.build() |
| 79 | + yield svc.build() |
| 80 | + yield sec.build() |
0 commit comments