|
| 1 | +let k8s = |
| 2 | + https://raw.githubusercontent.com/EarnestResearch/dhall-packages/master/kubernetes/k8s/1.14.dhall |
| 3 | + |
| 4 | +let cert-manager = |
| 5 | + https://raw.githubusercontent.com/EarnestResearch/dhall-packages/master/kubernetes/cert-manager/package.dhall |
| 6 | + |
| 7 | +let certsPath = "/certs" |
| 8 | + |
| 9 | +let Config = ./Config.dhall |
| 10 | + |
| 11 | +let labels = \(config : Config) -> toMap { app = config.name } |
| 12 | + |
| 13 | +let deployment = |
| 14 | + \(config : Config) |
| 15 | + -> k8s.Deployment::{ |
| 16 | + , metadata = k8s.ObjectMeta::{ name = config.name } |
| 17 | + , spec = |
| 18 | + Some |
| 19 | + k8s.DeploymentSpec::{ |
| 20 | + , selector = k8s.LabelSelector::{ matchLabels = labels config } |
| 21 | + , template = |
| 22 | + k8s.PodTemplateSpec::{ |
| 23 | + , metadata = |
| 24 | + k8s.ObjectMeta::{ |
| 25 | + , name = config.name |
| 26 | + , labels = labels config |
| 27 | + } |
| 28 | + , spec = |
| 29 | + Some |
| 30 | + k8s.PodSpec::{ |
| 31 | + , containers = |
| 32 | + [ k8s.Container::{ |
| 33 | + , name = config.name |
| 34 | + , image = Some config.imageName |
| 35 | + , ports = |
| 36 | + [ k8s.ContainerPort::{ |
| 37 | + , containerPort = config.port |
| 38 | + } |
| 39 | + ] |
| 40 | + , env = |
| 41 | + [ k8s.EnvVar::{ |
| 42 | + , name = "CERTIFICATE_FILE" |
| 43 | + , value = Some "${certsPath}/tls.crt" |
| 44 | + } |
| 45 | + , k8s.EnvVar::{ |
| 46 | + , name = "KEY_FILE" |
| 47 | + , value = Some "${certsPath}/tls.key" |
| 48 | + } |
| 49 | + ] |
| 50 | + , volumeMounts = |
| 51 | + [ k8s.VolumeMount::{ |
| 52 | + , name = "certs" |
| 53 | + , mountPath = certsPath |
| 54 | + , readOnly = Some True |
| 55 | + } |
| 56 | + ] |
| 57 | + } |
| 58 | + ] |
| 59 | + , volumes = |
| 60 | + [ k8s.Volume::{ |
| 61 | + , name = "certs" |
| 62 | + , secret = |
| 63 | + Some |
| 64 | + k8s.SecretVolumeSource::{ |
| 65 | + , secretName = Some config.name |
| 66 | + } |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | +let service = |
| 75 | + \(config : Config) |
| 76 | + -> k8s.Service::{ |
| 77 | + , metadata = k8s.ObjectMeta::{ name = config.name } |
| 78 | + , spec = |
| 79 | + Some |
| 80 | + k8s.ServiceSpec::{ |
| 81 | + , selector = labels config |
| 82 | + , ports = |
| 83 | + [ k8s.ServicePort::{ |
| 84 | + , targetPort = Some (k8s.IntOrString.Int config.port) |
| 85 | + , port = 443 |
| 86 | + } |
| 87 | + ] |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | +let issuer = |
| 92 | + \(config : Config) |
| 93 | + -> cert-manager.Issuer::{ |
| 94 | + , metadata = k8s.ObjectMeta::{ name = config.name } |
| 95 | + , spec = |
| 96 | + cert-manager.IssuerSpec.SelfSigned |
| 97 | + cert-manager.SelfSignedIssuerSpec::{=} |
| 98 | + } |
| 99 | + |
| 100 | +let certificate = |
| 101 | + \(config : Config) |
| 102 | + -> cert-manager.Certificate::{ |
| 103 | + , metadata = k8s.ObjectMeta::{ name = config.name } |
| 104 | + , spec = |
| 105 | + cert-manager.CertificateSpec::{ |
| 106 | + , secretName = config.name |
| 107 | + , issuerRef = { name = config.name, kind = (issuer config).kind } |
| 108 | + , commonName = Some "${config.name}.${config.namespace}.svc" |
| 109 | + , dnsNames = |
| 110 | + Some |
| 111 | + [ config.name |
| 112 | + , "${config.name}.${config.namespace}" |
| 113 | + , "${config.name}.${config.namespace}.svc" |
| 114 | + , "${config.name}.${config.namespace}.svc.cluster.local" |
| 115 | + , "${config.name}:443" |
| 116 | + , "${config.name}.${config.namespace}:443" |
| 117 | + , "${config.name}.${config.namespace}.svc:443" |
| 118 | + , "${config.name}.${config.namespace}.svc.cluster.local:443" |
| 119 | + , "localhost:8080" |
| 120 | + ] |
| 121 | + , usages = Some [ "any" ] |
| 122 | + , isCA = Some False |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | +let mutatingWebhookConfiguration = |
| 127 | + \(config : Config) |
| 128 | + -> k8s.MutatingWebhookConfiguration::{ |
| 129 | + , metadata = |
| 130 | + k8s.ObjectMeta::{ |
| 131 | + , name = config.name |
| 132 | + , labels = labels config |
| 133 | + , annotations = |
| 134 | + toMap |
| 135 | + { `cert-manager.io/inject-ca-from` = |
| 136 | + "${config.namespace}/${config.name}" |
| 137 | + } |
| 138 | + } |
| 139 | + , webhooks = |
| 140 | + [ k8s.Webhook::{ |
| 141 | + , name = "${config.name}.${config.namespace}.svc" |
| 142 | + , clientConfig = |
| 143 | + k8s.WebhookClientConfig::{ |
| 144 | + , service = |
| 145 | + Some |
| 146 | + { name = config.name |
| 147 | + , namespace = config.namespace |
| 148 | + , path = Some config.path |
| 149 | + } |
| 150 | + } |
| 151 | + , failurePolicy = config.failurePolicy |
| 152 | + , admissionReviewVersions = [ "v1beta1" ] |
| 153 | + , rules = config.rules |
| 154 | + , namespaceSelector = config.namespaceSelector |
| 155 | + } |
| 156 | + ] |
| 157 | + } |
| 158 | + |
| 159 | +let union = |
| 160 | + < Deployment : k8s.Deployment.Type |
| 161 | + | Service : k8s.Service.Type |
| 162 | + | MWH : k8s.MutatingWebhookConfiguration.Type |
| 163 | + | Certificate : cert-manager.Certificate.Type |
| 164 | + | ClusterIssuer : cert-manager.ClusterIssuer.Type |
| 165 | + > |
| 166 | + |
| 167 | +in \(config : Config) |
| 168 | + -> { apiVersion = "v1" |
| 169 | + , kind = "List" |
| 170 | + , items = |
| 171 | + [ union.Deployment (deployment config) |
| 172 | + , union.Service (service config) |
| 173 | + , union.MWH (mutatingWebhookConfiguration config) |
| 174 | + , union.Certificate (certificate config) |
| 175 | + , union.ClusterIssuer (issuer config) |
| 176 | + ] |
| 177 | + } |
0 commit comments