feat: Added provision to provide a VIP for talos cluster

refactor: Seperated machine configs

refactor: Made subnet configurable

refactor: Made domain name for oidc configurable

docs: Detailed comments in the code about VIP, endpoints, etc

Signed-off-by: Karteek <[email protected]>
This commit is contained in:
Karteek
2025-03-23 12:19:17 +01:00
committed by Vegard Hagen
parent 2e77f47aec
commit 47142aad99
9 changed files with 97 additions and 32 deletions
+36 -19
View File
@@ -6,31 +6,46 @@ data "talos_client_configuration" "this" {
cluster_name = var.cluster.name
client_configuration = talos_machine_secrets.this.client_configuration
nodes = [for k, v in var.nodes : v.ip]
# Don't use vip in talosconfig endpoints
# ref - https://www.talos.dev/v1.9/talos-guides/network/vip/#caveats
endpoints = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"]
}
data "talos_machine_configuration" "this" {
for_each = var.nodes
cluster_name = var.cluster.name
# This is the Kubernetes API Server endpoint.
# ref - https://www.talos.dev/v1.9/introduction/prodnotes/#decide-the-kubernetes-endpoint
cluster_endpoint = "https://${var.cluster.endpoint}:6443"
talos_version = var.cluster.talos_version
machine_type = each.value.machine_type
machine_secrets = talos_machine_secrets.this.machine_secrets
kubernetes_version = var.cluster.kubernetes_version
config_patches = each.value.machine_type == "controlplane" ? [
templatefile("${path.module}/machine-config/control-plane.yaml.tftpl", {
hostname = each.key
config_patches = [
templatefile("${path.module}/machine-config/common.yaml.tftpl", {
node_name = each.value.host_node
cluster_name = var.cluster.proxmox_cluster
cilium_values = var.cilium.values
cilium_install = var.cilium.install
})
] : [
templatefile("${path.module}/machine-config/worker.yaml.tftpl", {
hostname = each.key
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
})
]
}
@@ -47,11 +62,10 @@ resource "talos_machine_configuration_apply" "this" {
}
resource "talos_machine_bootstrap" "this" {
depends_on = [talos_machine_configuration_apply.this]
//for_each = var.nodes
//node = each.value.ip
node = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"][2]
endpoint = var.cluster.endpoint
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]
client_configuration = talos_machine_secrets.this.client_configuration
}
@@ -75,8 +89,11 @@ resource "talos_cluster_kubeconfig" "this" {
talos_machine_bootstrap.this,
data.talos_cluster_health.this
]
node = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"][2]
endpoint = var.cluster.endpoint
# If using VIP, it should be up by now, but to be safer retrive from one of the nodes
# As mentioned don't use talosctl on vip
# ref - https://www.talos.dev/v1.9/talos-guides/network/vip/#caveats
# In kubeconfig endpoint will be polulated by cluster_endpoint from machine-config
node = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"][0]
client_configuration = talos_machine_secrets.this.client_configuration
timeouts = {
read = "1m"