From 4c2890c672baa4e7d02a9162c5e53e4e85032ea8 Mon Sep 17 00:00:00 2001 From: Vegard Hagen Date: Sun, 23 Mar 2025 20:51:16 +0100 Subject: [PATCH] feat(tofu): better way of using inlineManifests for bootstrapping Cilium This solves #145 --- tofu/kubernetes/main.tf | 1 - tofu/kubernetes/talos/config.tf | 26 +++++++++++++++++-- .../machine-config/control-plane.yaml.tftpl | 16 +----------- tofu/kubernetes/talos/variables.tf | 12 +++------ tofu/kubernetes/talos_cluster.auto.tfvars | 9 +++---- tofu/kubernetes/variables.tf | 12 +++------ 6 files changed, 37 insertions(+), 39 deletions(-) diff --git a/tofu/kubernetes/main.tf b/tofu/kubernetes/main.tf index 9c8ae31..703bb4b 100644 --- a/tofu/kubernetes/main.tf +++ b/tofu/kubernetes/main.tf @@ -7,7 +7,6 @@ module "talos" { image = var.talos_image cluster = var.talos_cluster_config - cilium = var.cilium_config nodes = var.talos_nodes } diff --git a/tofu/kubernetes/talos/config.tf b/tofu/kubernetes/talos/config.tf index 05ee8d6..c9cdb59 100644 --- a/tofu/kubernetes/talos/config.tf +++ b/tofu/kubernetes/talos/config.tf @@ -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) }) : "" ] } diff --git a/tofu/kubernetes/talos/machine-config/control-plane.yaml.tftpl b/tofu/kubernetes/talos/machine-config/control-plane.yaml.tftpl index 568367b..7ce67d0 100644 --- a/tofu/kubernetes/talos/machine-config/control-plane.yaml.tftpl +++ b/tofu/kubernetes/talos/machine-config/control-plane.yaml.tftpl @@ -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} diff --git a/tofu/kubernetes/talos/variables.tf b/tofu/kubernetes/talos/variables.tf index b461a17..deb868f 100644 --- a/tofu/kubernetes/talos/variables.tf +++ b/tofu/kubernetes/talos/variables.tf @@ -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 - }) -} diff --git a/tofu/kubernetes/talos_cluster.auto.tfvars b/tofu/kubernetes/talos_cluster.auto.tfvars index daf9cb5..85c7d88 100644 --- a/tofu/kubernetes/talos_cluster.auto.tfvars +++ b/tofu/kubernetes/talos_cluster.auto.tfvars @@ -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" -} diff --git a/tofu/kubernetes/variables.tf b/tofu/kubernetes/variables.tf index c72ae75..750f651 100644 --- a/tofu/kubernetes/variables.tf +++ b/tofu/kubernetes/variables.tf @@ -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 + }) }) }