refactor(talos): condensate machine config into two files

Signed-off-by: Vegard Hagen <[email protected]>
This commit is contained in:
Vegard Hagen
2025-03-23 12:38:47 +01:00
parent 47142aad99
commit 83e1c95b06
6 changed files with 47 additions and 68 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ module "talos" {
# Not sure how it works if connected to the same router via ethernet (does it act as a switch then???)
# Ref: https://www.talos.dev/v1.9/talos-guides/network/vip/#requirements
# Note This is Kubernetes API endpoint. Different from all mentions of Talos endpoints.
endpoint = "192.168.1.102"
endpoint = "192.168.1.102"
# Omit this if devices are not connected on layer 2
vip = "192.168.1.99"
gateway = "192.168.1.1"
+20 -30
View File
@@ -20,32 +20,22 @@ data "talos_machine_configuration" "this" {
talos_version = var.cluster.talos_version
machine_type = each.value.machine_type
machine_secrets = talos_machine_secrets.this.machine_secrets
config_patches = [
config_patches = [
templatefile("${path.module}/machine-config/common.yaml.tftpl", {
node_name = each.value.host_node
cluster_name = var.cluster.proxmox_cluster
})
, each.value.machine_type == "controlplane" ?
templatefile("${path.module}/machine-config/control-plane.yaml.tftpl", {
cilium_values = var.cilium.values
cilium_install = var.cilium.install
base_domain = var.cluster.base_domain
}) : ""
, (each.value.machine_type == "controlplane" && var.cluster.vip != null)
? templatefile("${path.module}/machine-config/network-vip.yaml.tftpl", {
hostname = each.key
ip = each.value.ip
mac_address = lower(each.value.mac_address)
gateway = var.cluster.gateway
subnet_mask = var.cluster.subnet_mask
vip = var.cluster.vip
}) : templatefile("${path.module}/machine-config/network-no-vip.yaml.tftpl", {
hostname = each.key
ip = each.value.ip
mac_address = lower(each.value.mac_address)
gateway = var.cluster.gateway
subnet_mask = var.cluster.subnet_mask
})
node_name = each.value.host_node
cluster_name = var.cluster.proxmox_cluster
hostname = each.key
ip = each.value.ip
mac_address = lower(each.value.mac_address)
gateway = var.cluster.gateway
subnet_mask = var.cluster.subnet_mask
vip = var.cluster.vip
}), each.value.machine_type == "controlplane" ?
templatefile("${path.module}/machine-config/control-plane.yaml.tftpl", {
cilium_values = var.cilium.values
cilium_install = var.cilium.install
base_domain = var.cluster.base_domain
}) : ""
]
}
@@ -62,7 +52,7 @@ resource "talos_machine_configuration_apply" "this" {
}
resource "talos_machine_bootstrap" "this" {
depends_on = [talos_machine_configuration_apply.this]
depends_on = [talos_machine_configuration_apply.this]
# Bootstrap with the first node. VIP not yet available at this stage, so cant use var.cluster.endpoint as it may be set to VIP
# ref - https://www.talos.dev/v1.9/talos-guides/network/vip/#caveats
node = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"][0]
@@ -75,10 +65,10 @@ data "talos_cluster_health" "this" {
talos_machine_bootstrap.this
]
skip_kubernetes_checks = false
client_configuration = data.talos_client_configuration.this.client_configuration
control_plane_nodes = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"]
worker_nodes = [for k, v in var.nodes : v.ip if v.machine_type == "worker"]
endpoints = data.talos_client_configuration.this.endpoints
client_configuration = data.talos_client_configuration.this.client_configuration
control_plane_nodes = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"]
worker_nodes = [for k, v in var.nodes : v.ip if v.machine_type == "worker"]
endpoints = data.talos_client_configuration.this.endpoints
timeouts = {
read = "10m"
}
@@ -1,4 +1,22 @@
machine:
nodeLabels:
topology.kubernetes.io/region: ${cluster_name}
topology.kubernetes.io/zone: ${node_name}
network:
hostname: ${hostname}
interfaces:
- deviceSelector:
hardwareAddr: ${mac_address}
addresses:
- ${ip}/${subnet_mask}
routes:
- network: 0.0.0.0/0
gateway: ${gateway}
dhcp: false
%{ if vip != null }
vip:
ip: ${vip}
%{ endif }
sysctls:
fs.inotify.max_user_watches: 1048576 # Watchdog
fs.inotify.max_user_instances: 8192 # Watchdog
@@ -12,6 +30,3 @@ machine:
net.ipv4.tcp_wmem: 4096 65536 33554432 # 10Gb/s
net.ipv4.tcp_window_scaling: 1 # 10Gb/s
vm.nr_hugepages: 1024 # PostgreSQL
nodeLabels:
topology.kubernetes.io/region: ${cluster_name}
topology.kubernetes.io/zone: ${node_name}
@@ -1,12 +0,0 @@
machine:
network:
hostname: ${hostname}
interfaces:
- deviceSelector:
hardwareAddr: ${mac_address}
addresses:
- ${ip}/${subnet_mask}
routes:
- network: 0.0.0.0/0
gateway: ${gateway}
dhcp: false
@@ -1,14 +0,0 @@
machine:
network:
hostname: ${hostname}
interfaces:
- deviceSelector:
hardwareAddr: ${mac_address}
addresses:
- ${ip}/${subnet_mask}
routes:
- network: 0.0.0.0/0
gateway: ${gateway}
dhcp: false
vip:
ip: ${vip}
+8 -8
View File
@@ -15,15 +15,15 @@ variable "image" {
variable "cluster" {
description = "Cluster configuration"
type = object({
name = string
endpoint = string
vip = optional(string)
gateway = string
subnet_mask = optional(string, "24")
talos_version = string
proxmox_cluster = string
name = string
endpoint = string
vip = optional(string)
gateway = string
subnet_mask = optional(string, "24")
talos_version = string
proxmox_cluster = string
kubernetes_version = string
base_domain = string
base_domain = string
})
}