Shuffle files around and add a mkCronJob

This commit is contained in:
Fabrizio Ferrai 2018-12-10 17:27:44 +02:00
parent 3662a01c5b
commit 9db1943042
18 changed files with 223 additions and 33 deletions

1
Prelude Normal file
View File

@ -0,0 +1 @@
https://raw.githubusercontent.com/dhall-lang/Prelude/v3.0.0/package.dhall sha256:990c936c6dba21bc516c5d91a69afd908dce8c8698d6c0912798aa4ad1b978f3

View File

@ -4,10 +4,10 @@
, imagePullPolicy : Text
, minCPU : Natural
, maxCPU : Natural
, mounts : List ./Mount
, mounts : List (../common/types).Mount
, envVars : List { mapKey : Text, mapValue : Text }
, port : Optional Natural
, command : Optional (List Text)
, livenessProbe : Optional ./Probe
, readinessProbe : Optional ./Probe
, ports : List Natural
, command : List Text
, livenessProbe : Optional (../common/types).Probe
, readinessProbe : Optional (../common/types).Probe
}

13
api/Container/default Normal file
View File

@ -0,0 +1,13 @@
{ name = "CHANGEME"
, imageName = "SOME_IMAGE"
, imageTag = "0.1"
, imagePullPolicy = "Always"
, minCPU = 10
, maxCPU = 500
, mounts = [] : List (../common/types).Mount
, envVars = [] : List { mapKey : Text, mapValue : Text }
, ports = [] : List Natural
, command = [] : List Text
, livenessProbe = [] : Optional (../common/types).Probe
, readinessProbe = [] : Optional (../common/types).Probe
} : ./Container

74
api/Container/mkContainer Normal file
View File

@ -0,0 +1,74 @@
let Prelude = ../../Prelude
in let map = Prelude.`List`.map
in let Opt/map = Prelude.`Optional`.map
in let kv = Prelude.JSON.keyText
in let types = ../common/types
in let defaults = ../common/defaults
in let mkEnvVar : types.KV → types.EnvVar =
λ(var : types.KV) →
defaults.envVar
{ name = var.mapKey } //
{ value = Some var.mapValue }
in let mkMount : types.Mount → types.MountRaw =
λ(mount : types.Mount) →
defaults.mount
{ mountPath = mount.mountPath
, name = mount.name
} //
{ readOnly = mount.readOnly }
in let mkContainerPort : Natural → types.ContainerPort =
λ(port : Natural) →
defaults.containerPort
{ containerPort = port }
in let mkProbe : types.Probe → types.ProbeRaw =
λ(probe : types.Probe) →
defaults.probe //
{ initialDelaySeconds = Some probe.initial
, periodSeconds = Some probe.period
, httpGet = Some
(defaults.httpGet
{ port = defaults.Int probe.port } //
{ path = Some probe.path })
}
in let mkContainer : ./Container → types.Container =
λ(container : ./Container) →
defaults.container
{ name = container.name } //
{ image = Some "${container.imageName}:${container.imageTag}"
, imagePullPolicy = Some container.imagePullPolicy
, ports = Some
(map Natural types.ContainerPort mkContainerPort container.ports)
, resources = Some
{ limits = Some [kv "cpu" "${Natural/show container.maxCPU}m"]
, requests = Some [kv "cpu" "${Natural/show container.minCPU}m"]
}
, command = Some container.command
, env = Some (map types.KV types.EnvVar mkEnvVar container.envVars)
, volumeMounts = Some (map types.Mount types.MountRaw mkMount container.mounts)
-- Poll the container to see if the it's alive or we should restart it
, livenessProbe = (Opt/map types.Probe types.ProbeRaw mkProbe container.livenessProbe)
-- Poll the container to see that it's ready for requests
, readinessProbe = (Opt/map types.Probe types.ProbeRaw mkProbe container.readinessProbe)
}
in mkContainer

4
api/CronJob/CronJob Normal file
View File

@ -0,0 +1,4 @@
{ name : Text
, schedule : Text
, containers : List ../Container/Container
}

View File

@ -2,7 +2,5 @@
, spec = ../../default/io.k8s.api.batch.v1beta1.CronJobSpec.dhall
, jobSpec = ../../default/io.k8s.api.batch.v1.JobSpec.dhall
, podSpec = ../../default/io.k8s.api.core.v1.PodSpec.dhall
, container = ../../default/io.k8s.api.core.v1.Container.dhall
, envVar = ../../default/io.k8s.api.core.v1.EnvVar.dhall
, meta = ../../default/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
}
} // ../common/defaults

View File

@ -1,6 +1,5 @@
{ CronJob = ../../types/io.k8s.api.batch.v1beta1.CronJob.dhall
, Spec = ../../types/io.k8s.api.batch.v1beta1.CronJobSpec.dhall
, JobSpec = ../../types/io.k8s.api.batch.v1.JobSpec.dhall
, PodSpec = ../../types/io.k8s.api.core.v1.PodSpec.dhall
, EnvVar = ../../types/io.k8s.api.core.v1.EnvVar.dhall
}
{ CronJob = ../../types/io.k8s.api.batch.v1beta1.CronJob.dhall
, Spec = ../../types/io.k8s.api.batch.v1beta1.CronJobSpec.dhall
, JobSpec = ../../types/io.k8s.api.batch.v1.JobSpec.dhall
, PodSpec = ../../types/io.k8s.api.core.v1.PodSpec.dhall
} // ../common/types

37
api/CronJob/mkCronJob Normal file
View File

@ -0,0 +1,37 @@
let map = (../../Prelude).`List`.map
-- Kubernetes types and defaults
in let Types = ./RawTypes
in let default = ./RawDefaults
in let mkCronJob : ./CronJob → Types.CronJob =
λ(cronjob : ./CronJob) →
let spec = default.spec
{ schedule = cronjob.schedule
, jobTemplate =
{ metadata = default.meta { name = cronjob.name }
, spec = Some (default.jobSpec
{ template =
{ metadata = default.meta { name = cronjob.name }
, spec = Some (default.podSpec
{ containers = map
../Container/Container
Types.Container
../Container/mkContainer
cronjob.containers
} // { restartPolicy = Some "OnFailure" })
}
} // { backoffLimit = Some 2 })
}
}
in default.cronjob
{ metadata = default.meta { name = cronjob.name }
} //
{ spec = Some spec } : Types.CronJob
in mkCronJob

View File

@ -1,6 +1,6 @@
let intOrString = ../../default/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
in
let IntOrString = ../../types/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
in
{ deployment = ../../default/io.k8s.api.apps.v1.Deployment.dhall
, container = ../../default/io.k8s.api.core.v1.Container.dhall
, containerPort = ../../default/io.k8s.api.core.v1.ContainerPort.dhall
@ -17,7 +17,6 @@ in
, pathVolume = ../../default/io.k8s.api.core.v1.HostPathVolumeSource.dhall
, meta = ../../default/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
, selector = ../../default/io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.dhall
, intOrString = intOrString
, Int = intOrString.Int
, String = intOrString.String
}
, Int = IntOrString.Int
, String = IntOrString.String
}

View File

@ -1,3 +1,5 @@
../common/types
//
{ Deployment = ../../types/io.k8s.api.apps.v1.Deployment.dhall
, Container = ../../types/io.k8s.api.core.v1.Container.dhall
, ContainerPort = ../../types/io.k8s.api.core.v1.ContainerPort.dhall

View File

@ -1,13 +0,0 @@
{ name = "CHANGEME"
, imageName = "SOME_IMAGE"
, imageTag = "0.1"
, imagePullPolicy = "Always"
, minCPU = 10
, maxCPU = 500
, mounts = [] : List ./Mount
, envVars = [] : List { mapKey : Text, mapValue : Text }
, port = [] : Optional Natural
, command = [] : Optional (List Text)
, livenessProbe = [] : Optional ./Probe
, readinessProbe = [] : Optional ./Probe
} : ./Container

1
api/common/KV Normal file
View File

@ -0,0 +1 @@
{ mapKey : Text, mapValue : Text }

12
api/common/defaults Normal file
View File

@ -0,0 +1,12 @@
let IntOrString = ../../types/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
in
{ container = ../../default/io.k8s.api.core.v1.Container.dhall
, containerPort = ../../default/io.k8s.api.core.v1.ContainerPort.dhall
, probe = ../../default/io.k8s.api.core.v1.Probe.dhall
, httpGet = ../../default/io.k8s.api.core.v1.HTTPGetAction.dhall
, envVar = ../../default/io.k8s.api.core.v1.EnvVar.dhall
, mount = ../../default/io.k8s.api.core.v1.VolumeMount.dhall
, Int = IntOrString.Int
, String = IntOrString.String
}

11
api/common/types Normal file
View File

@ -0,0 +1,11 @@
{ HttpGet = ../../types/io.k8s.api.core.v1.HTTPGetAction.dhall
, Container = ../../types/io.k8s.api.core.v1.Container.dhall
, ContainerPort = ../../types/io.k8s.api.core.v1.ContainerPort.dhall
, EnvVar = ../../types/io.k8s.api.core.v1.EnvVar.dhall
, IntOrString = ../../types/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
, MountRaw = ../../types/io.k8s.api.core.v1.VolumeMount.dhall
, ProbeRaw = ../../types/io.k8s.api.core.v1.Probe.dhall
, Mount = ./Mount
, Probe = ./Probe
, KV = ./KV
}

28
api/defaults.dhall Normal file
View File

@ -0,0 +1,28 @@
-- This first chunks is in sync with the types.dhall file
{ container = ../default/io.k8s.api.core.v1.Container.dhall
, containerPort = ../default/io.k8s.api.core.v1.ContainerPort.dhall
, cronJob = ../default/io.k8s.api.batch.v1beta1.CronJob.dhall
, cronJobSpec = ../default/io.k8s.api.batch.v1beta1.CronJobSpec.dhall
, deployment = ../default/io.k8s.api.apps.v1.Deployment.dhall
, deploymentSpec = ../default/io.k8s.api.apps.v1.DeploymentSpec.dhall
, deploymentStrategy = ../default/io.k8s.api.apps.v1.DeploymentStrategy.dhall
, emptyVolume = ../default/io.k8s.api.core.v1.EmptyDirVolumeSource.dhall
, envVar = ../default/io.k8s.api.core.v1.EnvVar.dhall
, httpGet = ../default/io.k8s.api.core.v1.HTTPGetAction.dhall
, int = (../default/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall).Int
, jobSpec = ../default/io.k8s.api.batch.v1.JobSpec.dhall
, pathVolume = ../default/io.k8s.api.core.v1.HostPathVolumeSource.dhall
, podSpec = ../default/io.k8s.api.core.v1.PodSpec.dhall
, probe = ../default/io.k8s.api.core.v1.Probe.dhall
, resources = ../default/io.k8s.api.core.v1.ResourceRequirements.dhall
, rollingUpdate = ../default/io.k8s.api.apps.v1.RollingUpdateDeployment.dhall
, secretVolume = ../default/io.k8s.api.core.v1.SecretVolumeSource.dhall
, service = ../default/io.k8s.api.core.v1.Service.dhall
, servicePort = ../default/io.k8s.api.core.v1.ServicePort.dhall
, serviceSpec = ../default/io.k8s.api.core.v1.ServiceSpec.dhall
, string = (../default/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall).String
, volume = ../default/io.k8s.api.core.v1.Volume.dhall
, volumeMount = ../default/io.k8s.api.core.v1.VolumeMount.dhall
, meta = ../default/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
}

24
api/types.dhall Normal file
View File

@ -0,0 +1,24 @@
{ Container = ../types/io.k8s.api.core.v1.Container.dhall
, ContainerPort = ../types/io.k8s.api.core.v1.ContainerPort.dhall
, CronJob = ../types/io.k8s.api.batch.v1beta1.CronJob.dhall
, CronJobSpec = ../types/io.k8s.api.batch.v1beta1.CronJobSpec.dhall
, Deployment = ../types/io.k8s.api.apps.v1.Deployment.dhall
, DeploymentSpec = ../types/io.k8s.api.apps.v1.DeploymentSpec.dhall
, DeploymentStrategy = ../types/io.k8s.api.apps.v1.DeploymentStrategy.dhall
, EmptyVolume = ../types/io.k8s.api.core.v1.EmptyDirVolumeSource.dhall
, EnvVar = ../types/io.k8s.api.core.v1.EnvVar.dhall
, HttpGet = ../types/io.k8s.api.core.v1.HTTPGetAction.dhall
, IntOrString = ../types/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
, JobSpec = ../types/io.k8s.api.batch.v1.JobSpec.dhall
, PathVolume = ../types/io.k8s.api.core.v1.HostPathVolumeSource.dhall
, PodSpec = ../types/io.k8s.api.core.v1.PodSpec.dhall
, Probe = ../types/io.k8s.api.core.v1.Probe.dhall
, Resources = ../types/io.k8s.api.core.v1.ResourceRequirements.dhall
, RollingUpdate = ../types/io.k8s.api.apps.v1.RollingUpdateDeployment.dhall
, SecretVolume = ../types/io.k8s.api.core.v1.SecretVolumeSource.dhall
, Service = ../types/io.k8s.api.core.v1.Service.dhall
, ServicePort = ../types/io.k8s.api.core.v1.ServicePort.dhall
, ServiceSpec = ../types/io.k8s.api.core.v1.ServiceSpec.dhall
, Volume = ../types/io.k8s.api.core.v1.Volume.dhall
, VolumeMount = ../types/io.k8s.api.core.v1.VolumeMount.dhall
}