From e9a4b1c5c68012a99ac6d2b85c581b55bbace3a4 Mon Sep 17 00:00:00 2001 From: Stephan Feurer Date: Fri, 13 Sep 2024 14:29:51 +0200 Subject: [PATCH] Support creating multiple affinit groups A new variable affinity_group_capacity defines the capacity of an affinity group. --- control_plane.tf | 1 + infra.tf | 1 + modules/node-group/main.tf | 9 ++++++--- modules/node-group/variables.tf | 6 ++++++ storage.tf | 1 + variables.tf | 6 ++++++ worker.tf | 2 ++ 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/control_plane.tf b/control_plane.tf index ae4f210..a9837b0 100644 --- a/control_plane.tf +++ b/control_plane.tf @@ -26,6 +26,7 @@ module "master" { exoscale_security_group.control_plane.id, ] + affinity_group_capacity = var.affinity_group_capacity additional_affinity_group_ids = var.additional_affinity_group_ids deploy_target_id = var.deploy_target_id diff --git a/infra.tf b/infra.tf index 656098d..17df122 100644 --- a/infra.tf +++ b/infra.tf @@ -27,6 +27,7 @@ module "infra" { exoscale_security_group.infra.id, ] + affinity_group_capacity = var.affinity_group_capacity additional_affinity_group_ids = var.additional_affinity_group_ids deploy_target_id = var.deploy_target_id diff --git a/modules/node-group/main.tf b/modules/node-group/main.tf index ff5f7bc..bf897c4 100644 --- a/modules/node-group/main.tf +++ b/modules/node-group/main.tf @@ -1,6 +1,9 @@ locals { disk_size = var.root_disk_size + var.data_disk_size + var.storage_disk_size + anti_affinity_group_capacity = var.affinity_group_capacity > 0 ? var.affinity_group_capacity : 999999 + anti_affinity_group_count = var.affinity_group_capacity > 0 ? ceil(var.node_count / var.affinity_group_capacity) : 1 + ignition_source = { "bootstrap" = "${trimsuffix(var.bootstrap_bucket, "/")}/bootstrap.ign" "master" = "https://${var.api_int}:22623/config/master" @@ -161,8 +164,8 @@ resource "random_id" "node_id" { } resource "exoscale_anti_affinity_group" "anti_affinity_group" { - count = var.node_count > 0 ? 1 : 0 - name = "${var.cluster_id}_${var.role}" + count = var.node_count != 0 ? local.anti_affinity_group_count : 0 + name = "${var.cluster_id}_${var.role}_${count.index}" description = "${var.cluster_id} ${var.role} nodes" } @@ -181,7 +184,7 @@ resource "exoscale_compute_instance" "nodes" { security_group_ids = var.security_group_ids anti_affinity_group_ids = concat( - [exoscale_anti_affinity_group.anti_affinity_group[0].id], + [exoscale_anti_affinity_group.anti_affinity_group[floor(count.index / local.anti_affinity_group_capacity)].id], var.additional_affinity_group_ids ) diff --git a/modules/node-group/variables.tf b/modules/node-group/variables.tf index 041a9ec..d87695b 100644 --- a/modules/node-group/variables.tf +++ b/modules/node-group/variables.tf @@ -120,3 +120,9 @@ variable "deploy_target_id" { default = "" description = "ID of special deployment target, e.g. dedicated hypervisors" } + +variable "affinity_group_capacity" { + type = number + default = 0 + description = "Capacity of the affinity group, e.g. when using dedicated hypervisors, default: 0 (unlimited)" +} diff --git a/storage.tf b/storage.tf index e13c4ba..30aadf9 100644 --- a/storage.tf +++ b/storage.tf @@ -31,6 +31,7 @@ module "storage" { exoscale_security_group.storage.id, ] + affinity_group_capacity = var.affinity_group_capacity additional_affinity_group_ids = var.additional_affinity_group_ids deploy_target_id = var.deploy_target_id diff --git a/variables.tf b/variables.tf index 241be83..a436ec8 100644 --- a/variables.tf +++ b/variables.tf @@ -193,6 +193,12 @@ variable "deploy_target_id" { description = "ID of special deployment target, e.g. dedicated hypervisors" } +variable "affinity_group_capacity" { + type = number + default = 0 + description = "Capacity of the affinity group, e.g. when using dedicated hypervisors, default: 0 (unlimited)" +} + variable "ignition_ca" { type = string } diff --git a/worker.tf b/worker.tf index 9dc1c98..11d1bcc 100644 --- a/worker.tf +++ b/worker.tf @@ -29,6 +29,7 @@ module "worker" { [exoscale_security_group.all_machines.id] ) + affinity_group_capacity = var.affinity_group_capacity additional_affinity_group_ids = var.additional_affinity_group_ids deploy_target_id = var.deploy_target_id @@ -73,6 +74,7 @@ module "additional_worker" { [exoscale_security_group.all_machines.id] ) + affinity_group_capacity = var.affinity_group_capacity additional_affinity_group_ids = concat( each.value.affinity_group_ids != null ? each.value.affinity_group_ids : [], var.additional_affinity_group_ids