Skip to content

Commit

Permalink
Merge pull request #5 from skyscrapers/feature/add-keda-cron-scaledob…
Browse files Browse the repository at this point in the history
…ject

Feature: Add a scaledjob cron trigger for bitbucket
  • Loading branch information
simonrondelez authored Dec 13, 2024
2 parents 2af6cc0 + 6324c6d commit 60631ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions scaledobject.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "kubernetes_manifest" "scaledobject_cron" {
for_each = {
for runner_name, runner_config in var.bitbucket_runners : runner_name => runner_config
if lookup(runner_config, "cron_scaling_enabled", false)
}

manifest = {
"apiVersion" = "keda.sh/v1alpha1"
"kind" = "ScaledObject"
"metadata" = {
"name" = "bitbucket-${each.key}"
"namespace" = var.k8s_namespace
}

"spec" = {
"scaleTargetRef" = {
"name" = "bitbucket-${each.key}"
}
"minReplicaCount" = 0
"maxReplicaCount" = 1
"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", "0 0-5 * * 1-5, 0-23 * * 6, 0-23 * * 7")
"desiredReplicas" = "0"
}
}
]
}
}
}
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ 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")
}))
description = "Map of Bitbucket runner definitions"
}
Expand Down

0 comments on commit 60631ef

Please sign in to comment.