diff --git a/modules/runner/README.md b/modules/runner/README.md index ba2b250..9f0a110 100644 --- a/modules/runner/README.md +++ b/modules/runner/README.md @@ -21,7 +21,7 @@ No modules. | Name | Type | |------|------| -| [kubernetes_job.runner](https://registry.terraform.io/providers/hashicorp/kubernetes/2.23.0/docs/resources/job) | resource | +| [kubernetes_deployment.runner](https://registry.terraform.io/providers/hashicorp/kubernetes/2.23.0/docs/resources/deployment) | resource | | [kubernetes_namespace_v1.runner](https://registry.terraform.io/providers/hashicorp/kubernetes/2.23.0/docs/resources/namespace_v1) | resource | | [kubernetes_secret.runner](https://registry.terraform.io/providers/hashicorp/kubernetes/2.23.0/docs/resources/secret) | resource | @@ -34,6 +34,7 @@ No modules. | [namespace](#input\_namespace) | Namespace name | `string` | `"runner"` | no | | [oauthClientId](#input\_oauthClientId) | Oauth Client | `string` | n/a | yes | | [oauthClientSecret](#input\_oauthClientSecret) | Oauth Client Secret | `string` | n/a | yes | +| [replica\_count](#input\_replica\_count) | Deployment replica count | `number` | `2` | no | | [runnerUuid](#input\_runnerUuid) | Runner Uuid | `string` | n/a | yes | ## Outputs diff --git a/modules/runner/job.tf b/modules/runner/deployment.tf similarity index 90% rename from modules/runner/job.tf rename to modules/runner/deployment.tf index 4139466..764b37b 100644 --- a/modules/runner/job.tf +++ b/modules/runner/deployment.tf @@ -1,11 +1,20 @@ -resource "kubernetes_job" "runner" { +resource "kubernetes_deployment" "runner" { metadata { name = "runner" namespace = var.namespace } - spec { + replicas = var.replica_count + + selector { + match_labels = { + accountUuid = var.accountUuid + runnerUuid = var.runnerUuid + } + } + + template { metadata { labels = { @@ -13,6 +22,7 @@ resource "kubernetes_job" "runner" { runnerUuid = var.runnerUuid } } + spec { container { name = "bitbucket-k8s-runner" @@ -92,7 +102,7 @@ resource "kubernetes_job" "runner" { mount_path = "/var/run" } } - restart_policy = "OnFailure" + restart_policy = "Always" volume { name = "tmp" } @@ -106,14 +116,8 @@ resource "kubernetes_job" "runner" { } } } - - backoff_limit = 6 - completions = 1 - parallelism = 1 } - wait_for_completion = false - depends_on = [ kubernetes_secret.runner ] diff --git a/modules/runner/variables.tf b/modules/runner/variables.tf index 52f7f62..300bc07 100644 --- a/modules/runner/variables.tf +++ b/modules/runner/variables.tf @@ -29,3 +29,9 @@ variable "create_namespace" { description = "Create namespace or use existing one" default = true } + +variable "replica_count" { + type = number + default = 2 + description = "Deployment replica count" +}