Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add idle_count_min and idle_scale_factor` to Docker Machine autoscaling options #711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
848a00b
feat\!: switch to free-from scaling configurations
tmeijn Feb 25, 2023
669e944
add some validation
tmeijn Feb 25, 2023
2d87d68
Merge branch 'main' of github.com:tmeijn/terraform-aws-gitlab-runner …
tmeijn Feb 26, 2023
1bbbea3
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
159e29e
Merge branch 'refactor-variables' of github.com:cattle-ops/terraform-…
tmeijn Mar 13, 2023
6bfba05
type variable and use generic for-in conversion
tmeijn Mar 13, 2023
0122aa8
remove testing variable
tmeijn Mar 13, 2023
2890ca4
set correct tf version and variable
tmeijn Mar 13, 2023
cf4f794
fmt and input fix
tmeijn Mar 13, 2023
607c499
rename output
tmeijn Mar 13, 2023
89e6d84
fmt...
tmeijn Mar 13, 2023
3cde0f1
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
c3cf08c
convert snake_case to PascalCase and easy convert value
tmeijn Mar 16, 2023
3fdd3c5
chore!: remove deprecated variables (#738)
kayman-mk Mar 16, 2023
4ca78d5
Merge branch 'refactor-variables' of github.com:cattle-ops/terraform-…
tmeijn Mar 17, 2023
56fc8cc
Add some validation
tmeijn Mar 17, 2023
51b0d64
fix examples
tmeijn Mar 17, 2023
1d1549f
add cspell words and migration sed
tmeijn Mar 23, 2023
ec4c534
addtional cspell out of nowhere?
tmeijn Mar 23, 2023
4f73a44
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
c78907a
chore!: remove deprecated variables (#738)
kayman-mk Mar 16, 2023
8b3e7ad
Merge branch 'refactor-variables' into feat/switch-to-free-form-scali…
tmeijn Mar 24, 2023
90dcbcc
Merge branch 'refactor-variables' into feat/switch-to-free-form-scali…
kayman-mk Apr 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": "0.2",
"language": "en",
"words": [
"alltrue",
"amazonec",
"amannn",
"amazonec",
Expand All @@ -22,9 +23,7 @@
"endfor",
"formatlist",
"gitter",
"godotenv",
"golangci",
"gruntwork",
"glrunners",
"instancelifecycle",
"kics",
"joho",
Expand All @@ -39,10 +38,12 @@
"pylint",
"pylintrc",
"pyright",
"setsubtract",
"shuf",
"signoff",
"signum",
"stretchr",
"subkey",
"substr",
"templatefile",
"terrascan",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
terraform: [ 1.0.11, 1.3.9, latest ]
terraform: [1.3.9, latest]
example:
[
"runner-default",
Expand Down
2 changes: 1 addition & 1 deletion .terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.8
1.3.0
4 changes: 2 additions & 2 deletions examples/runner-default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ module "runner" {
]

# working 9 to 5 :)
runners_machine_autoscaling = [
runners_machine_autoscaling_options = [
{
periods = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]
periods = ["* * 0-9,17-23 * * mon-fri *", "* * * * * sat,sun *"]
idle_count = 0
idle_time = 60
timezone = var.timezone
Expand Down
4 changes: 2 additions & 2 deletions examples/runner-pre-registered/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ module "runner" {
runners_token = var.runner_token

# working 9 to 5 :)
runners_machine_autoscaling = [
runners_machine_autoscaling_options = [
{
periods = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]
periods = ["* * 0-9,17-23 * * mon-fri *", "* * * * * sat,sun *"]
idle_count = 0
idle_time = 60
timezone = var.timezone
Expand Down
5 changes: 0 additions & 5 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ locals {
%{~if var.runners_add_dind_volumes~},"/certs/client", "/builds", "/var/run/docker.sock:/var/run/docker.sock"%{endif~}%{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~}
EOT

runners_machine_autoscaling = templatefile("${path.module}/template/runners_machine_autoscaling.tftpl", {
runners_machine_autoscaling = var.runners_machine_autoscaling
}
)

runners_docker_services = templatefile("${path.module}/template/runners_docker_services.tftpl", {
runners_docker_services = var.runners_docker_services
}
Expand Down
7 changes: 6 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ locals {

template_runner_config = templatefile("${path.module}/template/runner-config.tftpl",
{
runners_machine_autoscaling = [for config in var.runners_machine_autoscaling_options : {
for key, value in config :
# Convert key from snake_case to PascalCase which is the casing for this section.
join("", [for subkey in split("_", key) : title(subkey)]) => jsonencode(value) if value != null
}]

aws_region = var.aws_region
gitlab_url = var.runners_gitlab_url
gitlab_clone_url = var.runners_clone_url
Expand Down Expand Up @@ -116,7 +122,6 @@ locals {
runners_idle_count = var.runners_idle_count
runners_idle_time = var.runners_idle_time
runners_max_builds = local.runners_max_builds_string
runners_machine_autoscaling = local.runners_machine_autoscaling
runners_root_size = var.runners_root_size
runners_volume_type = var.runners_volume_type
runners_iam_instance_profile_name = var.runners_iam_instance_profile_name
Expand Down
5 changes: 5 additions & 0 deletions migrations/migrate-to-7-0-0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ sed -i '/asg_terminate_lifecycle_hook_heartbeat_timeout/d' "$converted_file"
sed -i '/asg_terminate_lifecycle_lambda_memory_size/d' "$converted_file"
sed -i '/asg_terminate_lifecycle_lambda_runtime/d' "$converted_file"
sed -i '/asg_terminate_lifecycle_lambda_timeout/d' "$converted_file"

#
# PR #711 feat!: refactor Docker Machine autoscaling options
#
sed -i 's/runners_machine_autoscaling/runners_machine_autoscaling_options/g' "$converted_file"
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ output "runner_user_data" {
description = "The user data of the Gitlab Runner Agent's launch template."
value = local.template_user_data
}

output "runner_config_toml_rendered" {
description = "The rendered config.toml given to the Runner Manager."
value = local.template_runner_config
}
8 changes: 7 additions & 1 deletion template/runner-config.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ listen_address = "${prometheus_listen_address}"
${docker_machine_options}
]

${runners_machine_autoscaling}
%{~ for config in runners_machine_autoscaling ~}
[[runners.machine.autoscaling]]
%{~ for key, value in config ~}
${key} = ${value}
%{~ endfor ~}
%{~ endfor ~}

7 changes: 0 additions & 7 deletions template/runners_machine_autoscaling.tftpl

This file was deleted.

23 changes: 18 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,27 @@ variable "runners_ebs_optimized" {
default = true
}

variable "runners_machine_autoscaling" {
variable "runners_machine_autoscaling_options" {
description = "Set autoscaling parameters based on periods, see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersmachine-section"
type = list(object({
periods = list(string)
idle_count = number
idle_time = number
timezone = string
periods = list(string)
idle_count = optional(number)
idle_scale_factor = optional(number)
idle_count_min = optional(number)
idle_time = optional(number)
timezone = optional(string, "UTC")
}))

validation {
condition = alltrue([
for options in var.runners_machine_autoscaling_options :
length(
setsubtract([for key, value in options : key if value != null], ["periods", "timezone"])
) > 0
])

error_message = "Please specify an attribute that affects Autoscaling."
}
default = []
}

Expand Down