From 087757b1a98afd382a26ee3c83f5357da8643c48 Mon Sep 17 00:00:00 2001 From: Vahan Terzibashian Date: Fri, 13 Dec 2024 16:56:21 +0400 Subject: [PATCH 1/3] Fix: Cron syntax not correct for scaledobject --- scaledobject.tf | 10 +++++++++- variables.tf | 9 +++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scaledobject.tf b/scaledobject.tf index 13273be..b9cdc0a 100644 --- a/scaledobject.tf +++ b/scaledobject.tf @@ -31,7 +31,15 @@ resource "kubernetes_manifest" "scaledobject_cron" { "type" = "cron" "metadata" = { "timeZone" = lookup(each.value, "timeZone", "UTC") - "schedule" = lookup(each.value, "non_working_hours", "0 0-5 * * 1-5, 0-23 * * 6, 0-23 * * 7") + "schedule" = lookup(each.value, "non_working_hours_weekdays", "0 0-5,23 * * 1-5") + "desiredReplicas" = "0" + } + }, + { + "type" = "cron" + "metadata" = { + "timeZone" = lookup(each.value, "timeZone", "UTC") + "schedule" = lookup(each.value, "non_working_days", "0 0-23 * * 6-7") "desiredReplicas" = "0" } } diff --git a/variables.tf b/variables.tf index 36ae42c..1b74a8d 100644 --- a/variables.tf +++ b/variables.tf @@ -26,10 +26,11 @@ variable "bitbucket_runners" { memory = optional(string) })) })) - cron_scaling_enabled = optional(bool, false) - timeZone = optional(string, "UTC") - working_hours = optional(string, "0 6-23 * * 1-5") - non_working_hours = optional(string, "0 0-5 * * 1-5,0-23 * * 6,0-23 * * 7") + cron_scaling_enabled = optional(bool, false) + timeZone = optional(string, "UTC") + working_hours = optional(string, "0 6-23 * * 1-5") + non_working_hours_weekdays = optional(string, "0 0-5,23 * * 1-5") + non_working_days = optional(string, "0 0-23 * * 6-7") })) description = "Map of Bitbucket runner definitions" } From 46c06b7f1b3e10e0ce7d769397da5de54db921f5 Mon Sep 17 00:00:00 2001 From: Vahan Terzibashian Date: Fri, 13 Dec 2024 17:38:36 +0400 Subject: [PATCH 2/3] refactor cron triggers into for loop --- scaledobject.tf | 26 +++++--------------------- variables.tf | 11 ++++++----- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/scaledobject.tf b/scaledobject.tf index b9cdc0a..c1efad7 100644 --- a/scaledobject.tf +++ b/scaledobject.tf @@ -19,28 +19,12 @@ resource "kubernetes_manifest" "scaledobject_cron" { "minReplicaCount" = 0 "maxReplicaCount" = 1 "triggers" = [ - { - "type" = "cron" + for trigger in lookup(each.value, "triggers", []) : { + "type" = "cron" "metadata" = { - "timeZone" = lookup(each.value, "timeZone", "UTC") - "schedule" = lookup(each.value, "working_hours", "0 6-23 * * 1-5") - "desiredReplicas" = "1" - } - }, - { - "type" = "cron" - "metadata" = { - "timeZone" = lookup(each.value, "timeZone", "UTC") - "schedule" = lookup(each.value, "non_working_hours_weekdays", "0 0-5,23 * * 1-5") - "desiredReplicas" = "0" - } - }, - { - "type" = "cron" - "metadata" = { - "timeZone" = lookup(each.value, "timeZone", "UTC") - "schedule" = lookup(each.value, "non_working_days", "0 0-23 * * 6-7") - "desiredReplicas" = "0" + "schedule" = trigger.cronSyntax + "timeZone" = trigger.timeZone + "desiredReplicas" = tostring(trigger.desiredReplicas) } } ] diff --git a/variables.tf b/variables.tf index 1b74a8d..40ff7cc 100644 --- a/variables.tf +++ b/variables.tf @@ -26,11 +26,12 @@ variable "bitbucket_runners" { memory = optional(string) })) })) - cron_scaling_enabled = optional(bool, false) - timeZone = optional(string, "UTC") - working_hours = optional(string, "0 6-23 * * 1-5") - non_working_hours_weekdays = optional(string, "0 0-5,23 * * 1-5") - non_working_days = optional(string, "0 0-23 * * 6-7") + cron_scaling_enabled = optional(bool, false) + triggers = optional(list(object({ + cronSyntax = string + timeZone = string + desiredReplicas = number + }))) })) description = "Map of Bitbucket runner definitions" } From 5b20c1db514e215e6b7bccc212dc36928c767fee Mon Sep 17 00:00:00 2001 From: Vahan Terzibashian Date: Fri, 13 Dec 2024 17:40:27 +0400 Subject: [PATCH 3/3] Add default empty list for triggers variable --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 40ff7cc..9022786 100644 --- a/variables.tf +++ b/variables.tf @@ -31,7 +31,7 @@ variable "bitbucket_runners" { cronSyntax = string timeZone = string desiredReplicas = number - }))) + })), []) })) description = "Map of Bitbucket runner definitions" }