Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating multiple affinity groups #96

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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