mirror of
https://github.com/optim-enterprises-bv/terraform-talos.git
synced 2025-10-29 09:32:39 +00:00
fix affinity
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Proxmox
|
# Proxmox
|
||||||
|
|
||||||
It was tested on Proxmox version 7.4-3
|
It was tested on Proxmox version 8.2
|
||||||
|
|
||||||
Local utilities
|
Local utilities
|
||||||
|
|
||||||
@@ -94,9 +94,27 @@ machine:
|
|||||||
First we need to define our cluster:
|
First we need to define our cluster:
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
proxmox_host = "node1.example.com"
|
# Proxmox API host
|
||||||
|
proxmox_host = "node1.example.com"
|
||||||
|
|
||||||
vpc_main_cidr = "172.16.0.0/24"
|
# Local proxmox subnets
|
||||||
|
vpc_main_cidr = ["172.16.0.0/24", "fd60:172:16::/64"]
|
||||||
|
|
||||||
|
# Node configuration
|
||||||
|
nodes = {
|
||||||
|
"node1" = {
|
||||||
|
storage = "data",
|
||||||
|
ip4 = "1.1.0.1"
|
||||||
|
ip6 = "2001:1:2:1::/64",
|
||||||
|
gw6 = "2001:1:2:1::64",
|
||||||
|
},
|
||||||
|
"node2" = {
|
||||||
|
storage = "data",
|
||||||
|
ip4 = "1.1.0.2"
|
||||||
|
ip6 = "2001:1:2:2::/64",
|
||||||
|
gw6 = "2001:1:2:2::64",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
# We will create one control-plane node on the Proxmox node `node1` (count = 1)
|
# We will create one control-plane node on the Proxmox node `node1` (count = 1)
|
||||||
controlplane = {
|
controlplane = {
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
|
|
||||||
locals {
|
|
||||||
cpu_numa = {
|
|
||||||
for k, v in var.nodes : k => [for i in lookup(v, "cpu", "") :
|
|
||||||
flatten([for r in split(",", i) : (strcontains(r, "-") ? range(split("-", r)[0], split("-", r)[1] + 1, 1) : [r])])
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
cpus = { for k, v in local.cpu_numa : k =>
|
|
||||||
flatten([for numa in v : flatten([for r in range(length(numa) / 2) : [numa[r], numa[r + length(numa) / 2]]])])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data "proxmox_virtual_environment_node" "node" {
|
data "proxmox_virtual_environment_node" "node" {
|
||||||
for_each = { for inx, zone in local.zones : zone => inx if lookup(try(var.instances[zone], {}), "enabled", false) }
|
for_each = { for inx, zone in local.zones : zone => inx if lookup(try(var.instances[zone], {}), "enabled", false) }
|
||||||
node_name = each.key
|
node_name = each.key
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ locals {
|
|||||||
flatten([flatten([for r in range(length(v) / 2) : [v[r], v[r + length(v) / 2]]])])
|
flatten([flatten([for r in range(length(v) / 2) : [v[r], v[r + length(v) / 2]]])])
|
||||||
]
|
]
|
||||||
|
|
||||||
shift = var.shift * length(local.cpus[0])
|
shift = var.shift * length(try(local.cpus[0], []))
|
||||||
|
|
||||||
vm_arch = { for k in flatten([
|
vm_arch = { for k in flatten([
|
||||||
for inx in range(var.vms) : {
|
for inx in range(var.vms) : {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module "db_affinity" {
|
|||||||
} if lookup(try(var.instances[zone], {}), "db_count", 0) > 0 }
|
} if lookup(try(var.instances[zone], {}), "db_count", 0) > 0 }
|
||||||
|
|
||||||
source = "./cpuaffinity"
|
source = "./cpuaffinity"
|
||||||
cpu_affinity = var.nodes[each.value.zone].cpu
|
cpu_affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? var.nodes[each.value.zone].cpu : ["0-${2 * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_count * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_sockets - 1}"]
|
||||||
vms = each.value.vms
|
vms = each.value.vms
|
||||||
cpus = lookup(try(var.instances[each.value.zone], {}), "db_cpu", 1)
|
cpus = lookup(try(var.instances[each.value.zone], {}), "db_cpu", 1)
|
||||||
# shift = length(var.nodes[each.value.zone].cpu) - 1
|
# shift = length(var.nodes[each.value.zone].cpu) - 1
|
||||||
@@ -96,7 +96,7 @@ resource "proxmox_virtual_environment_vm" "db" {
|
|||||||
cpu {
|
cpu {
|
||||||
architecture = "x86_64"
|
architecture = "x86_64"
|
||||||
cores = each.value.cpu
|
cores = each.value.cpu
|
||||||
affinity = join(",", module.db_affinity[each.value.zone].arch[each.value.inx].cpus)
|
affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? join(",", module.db_affinity[each.value.zone].arch[each.value.inx].cpus) : null
|
||||||
sockets = 1
|
sockets = 1
|
||||||
numa = true
|
numa = true
|
||||||
type = "host"
|
type = "host"
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module "web_affinity" {
|
|||||||
} if lookup(try(var.instances[zone], {}), "web_count", 0) > 0 }
|
} if lookup(try(var.instances[zone], {}), "web_count", 0) > 0 }
|
||||||
|
|
||||||
source = "./cpuaffinity"
|
source = "./cpuaffinity"
|
||||||
cpu_affinity = var.nodes[each.value.zone].cpu
|
cpu_affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? var.nodes[each.value.zone].cpu : ["0-${2 * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_count * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_sockets - 1}"]
|
||||||
vms = each.value.vms
|
vms = each.value.vms
|
||||||
cpus = lookup(try(var.instances[each.value.zone], {}), "web_cpu", 1)
|
cpus = lookup(try(var.instances[each.value.zone], {}), "web_cpu", 1)
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ resource "proxmox_virtual_environment_vm" "web" {
|
|||||||
cpu {
|
cpu {
|
||||||
architecture = "x86_64"
|
architecture = "x86_64"
|
||||||
cores = each.value.cpu
|
cores = each.value.cpu
|
||||||
affinity = join(",", module.web_affinity[each.value.zone].arch[each.value.inx].cpus)
|
affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? join(",", module.web_affinity[each.value.zone].arch[each.value.inx].cpus) : null
|
||||||
sockets = 1
|
sockets = 1
|
||||||
numa = true
|
numa = true
|
||||||
type = "host"
|
type = "host"
|
||||||
@@ -132,7 +132,7 @@ resource "proxmox_virtual_environment_vm" "web" {
|
|||||||
device = "numa${index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx)}"
|
device = "numa${index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx)}"
|
||||||
cpus = "${index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx) * (each.value.cpu / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa))}-${(index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx) + 1) * (each.value.cpu / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa)) - 1}"
|
cpus = "${index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx) * (each.value.cpu / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa))}-${(index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx) + 1) * (each.value.cpu / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa)) - 1}"
|
||||||
mem = each.value.mem / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa)
|
mem = each.value.mem / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa)
|
||||||
} }
|
} if length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 }
|
||||||
content {
|
content {
|
||||||
device = numa.value.device
|
device = numa.value.device
|
||||||
cpus = numa.value.cpus
|
cpus = numa.value.cpus
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module "worker_affinity" {
|
|||||||
} if lookup(try(var.instances[zone], {}), "worker_count", 0) > 0 }
|
} if lookup(try(var.instances[zone], {}), "worker_count", 0) > 0 }
|
||||||
|
|
||||||
source = "./cpuaffinity"
|
source = "./cpuaffinity"
|
||||||
cpu_affinity = var.nodes[each.value.zone].cpu
|
cpu_affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? var.nodes[each.value.zone].cpu : ["0-${2 * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_count * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_sockets - 1}"]
|
||||||
vms = each.value.vms
|
vms = each.value.vms
|
||||||
cpus = lookup(try(var.instances[each.value.zone], {}), "worker_cpu", 1)
|
cpus = lookup(try(var.instances[each.value.zone], {}), "worker_cpu", 1)
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ resource "proxmox_virtual_environment_vm" "worker" {
|
|||||||
cpu {
|
cpu {
|
||||||
architecture = "x86_64"
|
architecture = "x86_64"
|
||||||
cores = each.value.cpu
|
cores = each.value.cpu
|
||||||
affinity = join(",", module.worker_affinity[each.value.zone].arch[each.value.inx].cpus)
|
affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? join(",", module.worker_affinity[each.value.zone].arch[each.value.inx].cpus) : null
|
||||||
sockets = 1
|
sockets = 1
|
||||||
numa = true
|
numa = true
|
||||||
type = "host"
|
type = "host"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ variable "network_shift" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
variable "vpc_main_cidr" {
|
variable "vpc_main_cidr" {
|
||||||
description = "Local proxmox subnet"
|
description = "Local proxmox subnets"
|
||||||
type = list(string)
|
type = list(string)
|
||||||
default = ["172.16.0.0/24", "fd60:172:16::/64"]
|
default = ["172.16.0.0/24", "fd60:172:16::/64"]
|
||||||
}
|
}
|
||||||
@@ -53,17 +53,17 @@ variable "nodes" {
|
|||||||
default = {
|
default = {
|
||||||
"hvm-1" = {
|
"hvm-1" = {
|
||||||
storage = "data",
|
storage = "data",
|
||||||
cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"],
|
# cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"],
|
||||||
ip4 = "1.1.0.1"
|
ip4 = "1.1.0.1"
|
||||||
ip6 = "2001:1:2:1::/64",
|
ip6 = "2001:1:2:1::/64",
|
||||||
gw6 = "2001:1:2:1::64",
|
gw6 = "2001:1:2:1::64",
|
||||||
},
|
},
|
||||||
"hvm-2" = {
|
"hvm-2" = {
|
||||||
storage = "data",
|
storage = "data",
|
||||||
cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"],
|
# cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"],
|
||||||
ip4 = "1.1.0.2"
|
ip4 = "1.1.0.2"
|
||||||
ip6 = "2001:1:2:2::/64",
|
ip6 = "2001:1:2:2::/64",
|
||||||
gw6 = "2001:1:2:2::64",
|
gw6 = "2001:1:2:2::64",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user