feat(tofu): better way of using inlineManifests for bootstrapping Cilium

This solves #145
This commit is contained in:
Vegard Hagen
2025-03-23 20:51:16 +01:00
parent e747d74097
commit 4c2890c672
6 changed files with 37 additions and 39 deletions
-1
View File
@@ -7,7 +7,6 @@ module "talos" {
image = var.talos_image
cluster = var.talos_cluster_config
cilium = var.cilium_config
nodes = var.talos_nodes
}
+24 -2
View File
@@ -11,6 +11,29 @@ data "talos_client_configuration" "this" {
endpoints = [for k, v in var.nodes : v.ip if v.machine_type == "controlplane"]
}
resource "terraform_data" "cilium_bootstrap_inline_manifests" {
input = [
{
name = "cilium-bootstrap"
contents = file("${path.root}/${var.cluster.cilium.bootstrap_manifest_path}")
},
{
name = "cilium-values"
contents = yamlencode({
apiVersion = "v1"
kind = "ConfigMap"
metadata = {
name = "cilium-values"
namespace = "kube-system"
}
data = {
"values.yaml" = file("${path.root}/${var.cluster.cilium.values_file_path}")
}
})
}
]
}
data "talos_machine_configuration" "this" {
for_each = var.nodes
cluster_name = var.cluster.name
@@ -34,9 +57,8 @@ data "talos_machine_configuration" "this" {
vip = var.cluster.vip
}), each.value.machine_type == "controlplane" ?
templatefile("${path.module}/machine-config/control-plane.yaml.tftpl", {
cilium_values = file("${path.root}/${var.cilium.values_path}")
cilium_install = file("${path.root}/${var.cilium.install_manifest_path}")
api_server = var.cluster.api_server
inline_manifests = jsonencode(terraform_data.cilium_bootstrap_inline_manifests.output)
}) : ""
]
}
@@ -21,18 +21,4 @@ cluster:
extraManifests:
- https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.1/standard-install.yaml
- https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/v1.2.1/config/crd/experimental/gateway.networking.k8s.io_tlsroutes.yaml
inlineManifests:
- name: cilium-values
contents: |
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cilium-values
namespace: kube-system
data:
values.yaml: |-
${indent(10, cilium_values)}
- name: cilium-bootstrap
contents: |
${indent(6, cilium_install)}
inlineManifests: ${inline_manifests}
+4 -8
View File
@@ -24,6 +24,10 @@ variable "cluster" {
proxmox_cluster = string
kubernetes_version = string
api_server = optional(string)
cilium = object({
bootstrap_manifest_path = string
values_file_path = string
})
})
}
@@ -43,11 +47,3 @@ variable "nodes" {
igpu = optional(bool, false)
}))
}
variable "cilium" {
description = "Cilium configuration"
type = object({
install_manifest_path = string
values_path = string
})
}
+4 -5
View File
@@ -13,6 +13,10 @@ talos_cluster_config = {
talos_machine_config_version = "v1.9.2"
proxmox_cluster = "homelab"
kubernetes_version = "1.32.0" # renovate: github-releases=kubernetes/kubernetes
cilium = {
bootstrap_manifest_path = "talos/inline-manifests/cilium-install.yaml"
values_file_path = "../../k8s/infra/network/cilium/values.yaml"
}
api_server = <<-EOT
extraArgs:
oidc-issuer-url: "https://authelia.stonegarden.dev"
@@ -23,8 +27,3 @@ talos_cluster_config = {
oidc-groups-prefix: "authelia:"
EOT
}
cilium_config = {
values_path = "../../k8s/infra/network/cilium/values.yaml"
install_manifest_path = "talos/inline-manifests/cilium-install.yaml"
}
+4 -8
View File
@@ -40,14 +40,10 @@ variable "talos_cluster_config" {
proxmox_cluster = string
kubernetes_version = string
api_server = optional(string)
})
}
variable "cilium_config" {
description = "Path to Cilium installation manifest and configuration values"
type = object({
install_manifest_path = string
values_path = string
cilium = object({
bootstrap_manifest_path = string
values_file_path = string
})
})
}