Skip to content

Commit

Permalink
Support creating multiple affinit groups
Browse files Browse the repository at this point in the history
A new variable affinity_group_capacity defines the capacity of an affinity group.
  • Loading branch information
DebakelOrakel committed Sep 13, 2024
1 parent e5d45c0 commit 35302de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/node-group/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
locals {
disk_size = var.root_disk_size + var.data_disk_size + var.storage_disk_size

anti_affinity_group_count = var.affinity_group_capacity > 0 ? (var.affinity_group_capacity / var.node_count): 1

ignition_source = {
"bootstrap" = "${trimsuffix(var.bootstrap_bucket, "/")}/bootstrap.ign"
"master" = "https://${var.api_int}:22623/config/master"
Expand Down Expand Up @@ -161,7 +163,7 @@ resource "random_id" "node_id" {
}

resource "exoscale_anti_affinity_group" "anti_affinity_group" {
count = var.node_count > 0 ? 1 : 0
count = var.node_count != 0 ? local.anti_affinity_group_count : 0
name = "${var.cluster_id}_${var.role}"
description = "${var.cluster_id} ${var.role} nodes"
}
Expand All @@ -181,7 +183,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_capacity)].id],
var.additional_affinity_group_ids
)

Expand Down
6 changes: 6 additions & 0 deletions modules/node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 35302de

Please sign in to comment.