From e82cce1f25a0b274b2ad7a912984475d01ed683f Mon Sep 17 00:00:00 2001 From: DaphneyI <80155089+DaphneyI@users.noreply.github.com> Date: Thu, 5 May 2022 10:49:25 +0100 Subject: [PATCH] Feat: Consolidate cache variable and set helm chart defaults (#8) Co-authored-by: daphney Igwe --- README.md | 18 +++---- config.tf | 24 +++++---- examples/main.tf | 30 ++++++++---- examples/variables.tf | 1 + local.tf | 16 ++++++ main.tf | 24 ++++++--- variables.tf | 111 ++++++++++++++++++++++++++++-------------- 7 files changed, 148 insertions(+), 76 deletions(-) create mode 100644 local.tf diff --git a/README.md b/README.md index 0c6051a..10fc74d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Full contributing guidelines are covered [here](CONTRIBUTING.md). | Name | Version | |------|---------| -| [helm](#provider\_helm) | 2.4.1 | +| [helm](#provider\_helm) | 2.5.1 | ## Modules @@ -68,7 +68,8 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [azure\_cache\_conf](#input\_azure\_cache\_conf) | Cache parameters define using Azure Blob Storage for caching as seen https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscacheazure-section. Only used when var.use\_local\_cache is false | `map` | `{}` | no | +| [additional\_secrets](#input\_additional\_secrets) | additional secrets to mount into the manager pods | `list(map(string))` | `[]` | no | +| [atomic](#input\_atomic) | whether to deploy the entire module as a unit | `bool` | `true` | no | | [build\_dir](#input\_build\_dir) | Path on nodes for caching | `string` | `null` | no | | [build\_job\_default\_container\_image](#input\_build\_job\_default\_container\_image) | Default container image to use for builds when none is specified | `string` | `"ubuntu:18.04"` | no | | [build\_job\_mount\_docker\_socket](#input\_build\_job\_mount\_docker\_socket) | Path on nodes for caching | `bool` | `false` | no | @@ -76,18 +77,15 @@ No modules. | [build\_job\_node\_tolerations](#input\_build\_job\_node\_tolerations) | A map of node tolerations to apply to the pods as defined https://docs.gitlab.com/runner/executors/kubernetes.html#other-configtoml-settings | `map` | `{}` | no | | [build\_job\_pod\_annotations](#input\_build\_job\_pod\_annotations) | A map of annotations to be added to each build pod created by the Runner. The value of these can include environment variables for expansion. Pod annotations can be overwritten in each build. | `map` | `{}` | no | | [build\_job\_pod\_labels](#input\_build\_job\_pod\_labels) | A map of labels to be added to each build pod created by the runner. The value of these can include environment variables for expansion. | `map` | `{}` | no | -| [build\_job\_priviledged](#input\_build\_job\_priviledged) | Run all containers with the privileged flag enabled. This will allow the docker:dind image to run if you need to run Docker | `bool` | `false` | no | +| [build\_job\_privileged](#input\_build\_job\_privileged) | Run all containers with the privileged flag enabled. This will allow the docker:dind image to run if you need to run Docker | `bool` | `false` | no | | [build\_job\_run\_container\_as\_user](#input\_build\_job\_run\_container\_as\_user) | SecurityContext: runAsUser for all running job pods | `string` | `null` | no | | [build\_job\_secret\_volumes](#input\_build\_job\_secret\_volumes) | Secret volume configuration instructs Kubernetes to use a secret that is defined in Kubernetes cluster and mount it inside of the containes as defined https://docs.gitlab.com/runner/executors/kubernetes.html#secret-volumes |
object({
name = string
mount_path = string
read_only = string
items = map(string)
})
|
{
"items": {},
"mount_path": null,
"name": null,
"read_only": null
}
| no | -| [cache\_path](#input\_cache\_path) | Name of the path to prepend to the cache URL. Only used when var.use\_local\_cache is false | `string` | `null` | no | -| [cache\_shared](#input\_cache\_shared) | Enables cache sharing between runners. Only used when var.use\_local\_cache is false | `bool` | `false` | no | -| [cache\_type](#input\_cache\_type) | One of: s3, gcs, azure. Only used when var.use\_local\_cache is false | `string` | `null` | no | +| [cache](#input\_cache) | Describes the properties of the cache. type can be either of ['local', 'gcs', 's3', 'azure'], path defines a path to append to the bucket url, shared specifies whether the cache can be shared between runners. you also specify the individual properties of the particular cache type you select. see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscache-section |
object({
type = string
path = string
shared = bool
gcs = map(any)
s3 = map(any)
azure = map(any)
})
|
{
"azure": {},
"gcs": {},
"path": "",
"s3": {},
"shared": false,
"type": "local"
}
| no | | [chart\_version](#input\_chart\_version) | The version of the chart | `string` | `"0.36.0"` | no | | [concurrent](#input\_concurrent) | Configure the maximum number of concurrent jobs | `number` | `10` | no | | [create\_namespace](#input\_create\_namespace) | (Optional) Create the namespace if it does not yet exist. Defaults to false. | `bool` | `true` | no | | [create\_service\_account](#input\_create\_service\_account) | If true, the service account, it's role and rolebinding will be created, else, the service account is assumed to already be created | `bool` | `true` | no | | [docker\_fs\_group](#input\_docker\_fs\_group) | The fsGroup to use for docker. This is added to security context when mount\_docker\_socket is enabled | `number` | `412` | no | -| [gcs\_cache\_conf](#input\_gcs\_cache\_conf) | Cache parameters define using Azure Blob Storage for caching as seen https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscachegcs-section. Only used when var.use\_local\_cache is false | `map` | `{}` | no | | [gitlab\_url](#input\_gitlab\_url) | The GitLab Server URL (with protocol) that want to register the runner against | `string` | `"https://gitlab.com/"` | no | | [image\_pull\_secrets](#input\_image\_pull\_secrets) | A array of secrets that are used to authenticate Docker image pulling. | `list(string)` | `[]` | no | | [local\_cache\_dir](#input\_local\_cache\_dir) | Path on nodes for caching | `string` | `"/tmp/gitlab/cache"` | no | @@ -97,16 +95,18 @@ No modules. | [manager\_pod\_labels](#input\_manager\_pod\_labels) | A map of labels to be added to each build pod created by the runner. The value of these can include environment variables for expansion. | `map` | `{}` | no | | [namespace](#input\_namespace) | n/a | `string` | `"gitlab-runner"` | no | | [release\_name](#input\_release\_name) | The helm release name | `string` | `"gitlab-runner"` | no | +| [replicas](#input\_replicas) | the number of manager pods to create | `number` | `1` | no | | [run\_untagged\_jobs](#input\_run\_untagged\_jobs) | Specify if jobs without tags should be run. https://docs.gitlab.com/ce/ci/runners/#runner-is-allowed-to-run-untagged-jobs | `bool` | `false` | no | | [runner\_image](#input\_runner\_image) | The docker gitlab runner version. https://hub.docker.com/r/gitlab/gitlab-runner/tags/ | `string` | `null` | no | | [runner\_locked](#input\_runner\_locked) | Specify whether the runner should be locked to a specific project/group | `string` | `true` | no | +| [runner\_name](#input\_runner\_name) | name of the runner | `string` | n/a | yes | | [runner\_registration\_token](#input\_runner\_registration\_token) | runner registration token | `string` | n/a | yes | | [runner\_tags](#input\_runner\_tags) | Specify the tags associated with the runner. Comma-separated list of tags. | `string` | n/a | yes | -| [s3\_cache\_conf](#input\_s3\_cache\_conf) | Cache parameters define using S3 for caching as seen https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscaches3-section. Only used when var.use\_local\_cache is false | `map` | `{}` | no | +| [runner\_token](#input\_runner\_token) | token of already registered runer. to use this var.runner\_registration\_token must be set to null | `string` | `null` | no | | [service\_account](#input\_service\_account) | The name of the Service account to create | `string` | `"gitlab-runner"` | no | | [service\_account\_annotations](#input\_service\_account\_annotations) | The annotations to add to the service account | `map` | `{}` | no | | [service\_account\_clusterwide\_access](#input\_service\_account\_clusterwide\_access) | Run the gitlab-bastion container with the ability to deploy/manage containers of jobs cluster-wide or only within namespace | `bool` | `false` | no | -| [use\_local\_cache](#input\_use\_local\_cache) | Use path on nodes for caching | `bool` | `false` | no | +| [unregister\_runners](#input\_unregister\_runners) | whether runners should be unregistered when pool is deprovisioned | `bool` | `true` | no | | [values](#input\_values) | Additional values to be passed to the gitlab-runner helm chart | `map` | `{}` | no | | [values\_file](#input\_values\_file) | Path to Values file to be passed to gitlab-runner helm chart | `string` | `null` | no | diff --git a/config.tf b/config.tf index 3cd5846..e1f1424 100644 --- a/config.tf +++ b/config.tf @@ -1,27 +1,25 @@ locals { config = < 0 : true + error_message = "To use the azure cache type you must set var.cache.azure. see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscache-section for config details." + } + validation { + condition = var.cache.type == "s3" ? length(var.cache.azure) > 0 : true + error_message = "To use the s3 cache type you must set var.cache.s3 see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscache-section for config details." + } + + validation { + condition = var.cache.type == "gcs" || var.cache.type == "s3" || var.cache.type == "local" || var.cache.type == "azure" ? true : false + error_message = "Cache type must be one of 's3', 'gcs', 'azure', or 'local'." + } + + default = { + type = "local" + path = "" + shared = false + gcs = {} + s3 = {} + azure = {} + } +}