From f75f52fa8dde0aff2f431ccc3393189a72ff475e Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 14 Apr 2020 16:04:06 +0000 Subject: [PATCH] Refactor Zuul services This change refactors the Zuul component to dedicated file for easier maintainance. Change-Id: I3815abb698b2e42f24289436a718d95cec7be607 --- conf/zuul/components/Executor.dhall | 66 +++++++ conf/zuul/components/Merger.dhall | 29 +++ conf/zuul/components/Registry.dhall | 72 +++++++ conf/zuul/components/Scheduler.dhall | 37 ++++ conf/zuul/components/Web.dhall | 36 ++++ conf/zuul/resources.dhall | 269 ++++----------------------- 6 files changed, 275 insertions(+), 234 deletions(-) create mode 100644 conf/zuul/components/Executor.dhall create mode 100644 conf/zuul/components/Merger.dhall create mode 100644 conf/zuul/components/Registry.dhall create mode 100644 conf/zuul/components/Scheduler.dhall create mode 100644 conf/zuul/components/Web.dhall diff --git a/conf/zuul/components/Executor.dhall b/conf/zuul/components/Executor.dhall new file mode 100644 index 0000000..c701b53 --- /dev/null +++ b/conf/zuul/components/Executor.dhall @@ -0,0 +1,66 @@ +let Kubernetes = ../../Kubernetes.dhall + +let F = ../functions.dhall + +let JobVolume = (../input.dhall).JobVolume.Type + +in \(app-name : Text) + -> \(image-name : Optional Text) + -> \(data-dir : List F.Volume.Type) + -> \(volumes : List F.Volume.Type) + -> \(env : List Kubernetes.EnvVar.Type) + -> \(jobVolumes : Optional (List JobVolume)) + -> F.KubernetesComponent::{ + , Service = Some (F.mkService app-name "executor" "finger" 7900) + , StatefulSet = Some + ( F.mkStatefulSet + app-name + F.Component::{ + , name = "executor" + , count = 1 + , data-dir = data-dir + , volumes = volumes + , extra-volumes = + let job-volumes = + F.mkJobVolume + Kubernetes.Volume.Type + (\(job-volume : JobVolume) -> job-volume.volume) + jobVolumes + + in job-volumes + , claim-size = 0 + , container = Kubernetes.Container::{ + , name = "executor" + , image = image-name + , args = Some [ "zuul-executor", "-d" ] + , imagePullPolicy = Some "IfNotPresent" + , ports = Some + [ Kubernetes.ContainerPort::{ + , name = Some "finger" + , containerPort = 7900 + } + ] + , env = Some env + , volumeMounts = + let job-volumes-mount = + F.mkJobVolume + F.Volume.Type + ( \(job-volume : JobVolume) + -> F.Volume::{ + , name = job-volume.volume.name + , dir = job-volume.dir + } + ) + jobVolumes + + in Some + ( F.mkVolumeMount + (data-dir # volumes # job-volumes-mount) + ) + , securityContext = Some Kubernetes.SecurityContext::{ + , privileged = Some True + } + } + } + ) + } diff --git a/conf/zuul/components/Merger.dhall b/conf/zuul/components/Merger.dhall new file mode 100644 index 0000000..01ac55a --- /dev/null +++ b/conf/zuul/components/Merger.dhall @@ -0,0 +1,29 @@ +let Kubernetes = ../../Kubernetes.dhall + +let F = ../functions.dhall + +in \(app-name : Text) + -> \(image-name : Optional Text) + -> \(data-dir : List F.Volume.Type) + -> \(volumes : List F.Volume.Type) + -> \(env : List Kubernetes.EnvVar.Type) + -> F.KubernetesComponent::{ + , Deployment = Some + ( F.mkDeployment + app-name + F.Component::{ + , name = "merger" + , count = 1 + , data-dir = data-dir + , volumes = volumes + , container = Kubernetes.Container::{ + , name = "merger" + , image = image-name + , args = Some [ "zuul-merger", "-d" ] + , imagePullPolicy = Some "IfNotPresent" + , env = Some env + , volumeMounts = Some (F.mkVolumeMount (data-dir # volumes)) + } + } + ) + } diff --git a/conf/zuul/components/Registry.dhall b/conf/zuul/components/Registry.dhall new file mode 100644 index 0000000..ba15e62 --- /dev/null +++ b/conf/zuul/components/Registry.dhall @@ -0,0 +1,72 @@ +let Prelude = ../../Prelude.dhall + +let Kubernetes = ../../Kubernetes.dhall + +let F = ../functions.dhall + +let InputRegistry = (../input.dhall).Registry.Type + +let registry-volumes = + \(app-name : Text) + -> [ F.Volume::{ + , name = app-name ++ "-registry-tls" + , dir = "/etc/zuul-registry" + } + ] + +let registry-env = + \(app-name : Text) + -> F.mkEnvVarSecret + ( Prelude.List.map + Text + F.EnvSecret + ( \(key : Text) + -> { name = "ZUUL_REGISTRY_${key}" + , key = key + , secret = app-name ++ "-registry-tls" + } + ) + [ "secret", "username", "password" ] + ) + +in \(app-name : Text) + -> \(image-name : Optional Text) + -> \(data-dir : List F.Volume.Type) + -> \(volumes : List F.Volume.Type) + -> \(input-registry : InputRegistry) + -> F.KubernetesComponent::{ + , Service = Some (F.mkService app-name "registry" "registry" 9000) + , StatefulSet = Some + ( F.mkStatefulSet + app-name + F.Component::{ + , name = "registry" + , count = F.defaultNat input-registry.count 0 + , data-dir = data-dir + , volumes = volumes # registry-volumes app-name + , claim-size = F.defaultNat input-registry.storage-size 20 + , container = Kubernetes.Container::{ + , name = "registry" + , image = image-name + , args = Some + [ "zuul-registry" + , "-c" + , "/etc/zuul/registry.yaml" + , "serve" + ] + , imagePullPolicy = Some "IfNotPresent" + , ports = Some + [ Kubernetes.ContainerPort::{ + , name = Some "registry" + , containerPort = 9000 + } + ] + , env = Some (registry-env app-name) + , volumeMounts = Some + ( F.mkVolumeMount + (data-dir # volumes # registry-volumes app-name) + ) + } + } + ) + } diff --git a/conf/zuul/components/Scheduler.dhall b/conf/zuul/components/Scheduler.dhall new file mode 100644 index 0000000..32f1f7a --- /dev/null +++ b/conf/zuul/components/Scheduler.dhall @@ -0,0 +1,37 @@ +let Kubernetes = ../../Kubernetes.dhall + +let F = ../functions.dhall + +in \(app-name : Text) + -> \(image-name : Optional Text) + -> \(data-dir : List F.Volume.Type) + -> \(volumes : List F.Volume.Type) + -> \(env : List Kubernetes.EnvVar.Type) + -> F.KubernetesComponent::{ + , Service = Some (F.mkService app-name "scheduler" "gearman" 4730) + , StatefulSet = Some + ( F.mkStatefulSet + app-name + F.Component::{ + , name = "scheduler" + , count = 1 + , data-dir = data-dir + , volumes = volumes + , claim-size = 5 + , container = Kubernetes.Container::{ + , name = "scheduler" + , image = image-name + , args = Some [ "zuul-scheduler", "-d" ] + , imagePullPolicy = Some "IfNotPresent" + , ports = Some + [ Kubernetes.ContainerPort::{ + , name = Some "gearman" + , containerPort = 4730 + } + ] + , env = Some env + , volumeMounts = Some (F.mkVolumeMount (data-dir # volumes)) + } + } + ) + } diff --git a/conf/zuul/components/Web.dhall b/conf/zuul/components/Web.dhall new file mode 100644 index 0000000..72c8a59 --- /dev/null +++ b/conf/zuul/components/Web.dhall @@ -0,0 +1,36 @@ +let Kubernetes = ../../Kubernetes.dhall + +let F = ../functions.dhall + +in \(app-name : Text) + -> \(image-name : Optional Text) + -> \(data-dir : List F.Volume.Type) + -> \(volumes : List F.Volume.Type) + -> \(env : List Kubernetes.EnvVar.Type) + -> F.KubernetesComponent::{ + , Service = Some (F.mkService app-name "web" "api" 9000) + , Deployment = Some + ( F.mkDeployment + app-name + F.Component::{ + , name = "web" + , count = 1 + , data-dir = data-dir + , volumes = volumes + , container = Kubernetes.Container::{ + , name = "web" + , image = image-name + , args = Some [ "zuul-web", "-d" ] + , imagePullPolicy = Some "IfNotPresent" + , ports = Some + [ Kubernetes.ContainerPort::{ + , name = Some "api" + , containerPort = 9000 + } + ] + , env = Some env + , volumeMounts = Some (F.mkVolumeMount (data-dir # volumes)) + } + } + ) + } diff --git a/conf/zuul/resources.dhall b/conf/zuul/resources.dhall index 0c147e1..f45f6f3 100644 --- a/conf/zuul/resources.dhall +++ b/conf/zuul/resources.dhall @@ -251,241 +251,42 @@ in \(input : Input) let zuul-volumes = [ etc-zuul, gearman-config ] # zk-client-conf - let web-volumes = zuul-volumes - - let merger-volumes = zuul-volumes - - let scheduler-volumes = zuul-volumes # [ sched-config ] - - let executor-volumes = zuul-volumes # [ executor-ssh-key ] - - in { Scheduler = F.KubernetesComponent::{ - , Service = Some - (F.mkService input.name "scheduler" "gearman" 4730) - , StatefulSet = Some - ( F.mkStatefulSet - input.name - F.Component::{ - , name = "scheduler" - , count = 1 - , data-dir = zuul-data-dir - , volumes = scheduler-volumes - , claim-size = 5 - , container = Kubernetes.Container::{ - , name = "scheduler" - , image = zuul-image "scheduler" - , args = Some [ "zuul-scheduler", "-d" ] - , imagePullPolicy = Some "IfNotPresent" - , ports = Some - [ Kubernetes.ContainerPort::{ - , name = Some "gearman" - , containerPort = 4730 - } - ] - , env = Some - ( zuul-env - # db-secret-env - # zk-hosts-secret-env - ) - , volumeMounts = Some - ( F.mkVolumeMount - (scheduler-volumes # zuul-data-dir) - ) - } - } - ) - } - , Executor = F.KubernetesComponent::{ - , Service = Some - (F.mkService input.name "executor" "finger" 7900) - , StatefulSet = Some - ( F.mkStatefulSet - input.name - F.Component::{ - , name = "executor" - , count = 1 - , data-dir = zuul-data-dir - , volumes = executor-volumes - , extra-volumes = - let job-volumes = - F.mkJobVolume - Kubernetes.Volume.Type - ( \(job-volume : JobVolume) - -> job-volume.volume - ) - input.jobVolumes - - in job-volumes - , claim-size = 0 - , container = Kubernetes.Container::{ - , name = "executor" - , image = zuul-image "executor" - , args = Some [ "zuul-executor", "-d" ] - , imagePullPolicy = Some "IfNotPresent" - , ports = Some - [ Kubernetes.ContainerPort::{ - , name = Some "finger" - , containerPort = 7900 - } - ] - , env = Some (zuul-env # db-nosecret-env) - , volumeMounts = - let job-volumes-mount = - F.mkJobVolume - Volume.Type - ( \(job-volume : JobVolume) - -> Volume::{ - , name = - job-volume.volume.name - , dir = job-volume.dir - } - ) - input.jobVolumes - - in Some - ( F.mkVolumeMount - ( executor-volumes - # zuul-data-dir - # job-volumes-mount - ) - ) - , securityContext = Some Kubernetes.SecurityContext::{ - , privileged = Some True - } - } - } - ) - } - , Web = F.KubernetesComponent::{ - , Service = Some - (F.mkService input.name "web" "api" 9000) - , Deployment = Some - ( F.mkDeployment - input.name - F.Component::{ - , name = "web" - , count = 1 - , data-dir = zuul-data-dir - , volumes = web-volumes - , container = Kubernetes.Container::{ - , name = "web" - , image = zuul-image "web" - , args = Some [ "zuul-web", "-d" ] - , imagePullPolicy = Some "IfNotPresent" - , ports = Some - [ Kubernetes.ContainerPort::{ - , name = Some "api" - , containerPort = 9000 - } - ] - , env = Some - ( zuul-env - # db-secret-env - # zk-hosts-secret-env - ) - , volumeMounts = Some - ( F.mkVolumeMount - (web-volumes # zuul-data-dir) - ) - } - } - ) - } - , Merger = F.KubernetesComponent::{ - , Deployment = Some - ( F.mkDeployment - input.name - F.Component::{ - , name = "merger" - , count = 1 - , data-dir = zuul-data-dir - , volumes = merger-volumes - , container = Kubernetes.Container::{ - , name = "merger" - , image = zuul-image "merger" - , args = Some [ "zuul-merger", "-d" ] - , imagePullPolicy = Some "IfNotPresent" - , env = Some (zuul-env # db-nosecret-env) - , volumeMounts = Some - ( F.mkVolumeMount - (merger-volumes # zuul-data-dir) - ) - } - } - ) - } + in { Scheduler = + ./components/Scheduler.dhall + input.name + (zuul-image "scheduler") + zuul-data-dir + (zuul-volumes # [ sched-config ]) + (zuul-env # db-secret-env # zk-hosts-secret-env) + , Executor = + ./components/Executor.dhall + input.name + (zuul-image "executor") + zuul-data-dir + (zuul-volumes # [ executor-ssh-key ]) + (zuul-env # db-nosecret-env) + input.jobVolumes + , Web = + ./components/Web.dhall + input.name + (zuul-image "web") + zuul-data-dir + zuul-volumes + (zuul-env # db-secret-env # zk-hosts-secret-env) + , Merger = + ./components/Merger.dhall + input.name + (zuul-image "merger") + zuul-data-dir + zuul-volumes + (zuul-env # db-nosecret-env) , Registry = - let registry-volumes = - [ etc-zuul-registry - , Volume::{ - , name = input.name ++ "-registry-tls" - , dir = "/etc/zuul-registry" - } - ] - - let registry-env = - F.mkEnvVarSecret - ( Prelude.List.map - Text - F.EnvSecret - ( \(key : Text) - -> { name = "ZUUL_REGISTRY_${key}" - , key = key - , secret = - input.name ++ "-registry-tls" - } - ) - [ "secret", "username", "password" ] - ) - - in F.KubernetesComponent::{ - , Service = Some - ( F.mkService - input.name - "registry" - "registry" - 9000 - ) - , StatefulSet = Some - ( F.mkStatefulSet - input.name - F.Component::{ - , name = "registry" - , count = - F.defaultNat input.registry.count 0 - , data-dir = zuul-data-dir - , volumes = registry-volumes - , claim-size = - F.defaultNat - input.registry.storage-size - 20 - , container = Kubernetes.Container::{ - , name = "registry" - , image = zuul-image "registry" - , args = Some - [ "zuul-registry" - , "-c" - , "/etc/zuul/registry.yaml" - , "serve" - ] - , imagePullPolicy = Some "IfNotPresent" - , ports = Some - [ Kubernetes.ContainerPort::{ - , name = Some "registry" - , containerPort = 9000 - } - ] - , env = Some registry-env - , volumeMounts = Some - ( F.mkVolumeMount - ( registry-volumes - # zuul-data-dir - ) - ) - } - } - ) - } + ./components/Registry.dhall + input.name + (zuul-image "registry") + zuul-data-dir + [ etc-zuul-registry ] + input.registry } , Nodepool = let nodepool-image =