Skip to content

Commit

Permalink
Support creating multiple affinit groups (#96)
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 authored Sep 13, 2024
1 parent e5d45c0 commit a9d8c53
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions control_plane.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions infra.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions modules/node-group/main.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 = count.index > 0 ? "${var.cluster_id}_${var.role}_${count.index}" : "${var.cluster_id}_${var.role}"
description = "${var.cluster_id} ${var.role} nodes"
}

Expand All @@ -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
)

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)"
}
1 change: 1 addition & 0 deletions storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
2 changes: 2 additions & 0 deletions worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a9d8c53

Please sign in to comment.