Files
metal/templates/generate_configs.sh
2025-11-12 05:46:48 +01:00

73 lines
2.3 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
CONFIGS={{ root }}/configs
function create_inline_manifest() {
# Add indentation
CONTENT=$(echo "$3" | sed 's/^/ /')
# Create inline manifest patch
cat > $2 << EOF
cluster:
inlineManifests:
- name: ${1}
contents: |
${CONTENT}
EOF
}
helm repo add cilium https://helm.cilium.io/
helm repo update
{% for cluster in clusters -%}
{% if "cilium" in cluster -%}
# Generate manifests
CONTENT=$(helm template \
cilium \
cilium/cilium \
--version {{ cluster.cilium.version }} \
--namespace kube-system \
--values {{ cluster.cilium.valuesFile }})
create_inline_manifest cilium ${CONFIGS}/{{cluster.name}}/cilium.yaml "${CONTENT}"
{% endif %}
{%- endfor %}
# Generate the configuration for each node
{% for node in nodes -%}
talosctl gen config {{ node.cluster.name }} https://{{ node.cluster.controlPlaneIp }}:6443 -f \
--with-secrets {{ node.cluster.secretsFile }} \
--talos-version {{ node.talosVersion }} \
--kubernetes-version {{ node.kubernesVersion }} \
--output-types {{ node.type }} \
--install-image factory.talos.dev/metal-installer/{{ node.schematicId }}:{{ node.talosVersion }} \
{% for patch in node.patches -%}
{# The double call to tojson is needed to properly escape the patch (object -> json -> string) -#}
--config-patch {{ patch|tojson|tojson }} \
{% endfor -%}
{% for patch in node.patchesControlPlane -%}
--config-patch-control-plane {{ patch|tojson|tojson }} \
{% endfor -%}
{% if "cilium" in node.cluster -%}
--config-patch-control-plane "@${CONFIGS}/{{node.cluster.name}}/cilium.yaml" \
{%- endif %}
--with-docs=false \
--with-examples=false \
-o ${CONFIGS}/{{ node.filename }}.yaml
{% endfor %}
# Generate the talosconfig file for each cluster
{% for cluster in clusters -%}
talosctl gen config {{ cluster.name }} https://{{ cluster.controlPlaneIp }}:6443 -f \
--with-secrets {{ cluster.secretsFile }} \
--output-types talosconfig \
-o ${CONFIGS}/{{ cluster.name }}/talosconfig
{% endfor %}
# Create merged talosconfig
TALOSCONFIG=${CONFIGS}/talosconfig
rm -f ${TALOSCONFIG}
{% for cluster in clusters -%}
talosctl config --talosconfig=${CONFIGS}/{{ cluster.name }}/talosconfig endpoint {{ cluster.controlPlaneIp }}
talosctl config --talosconfig=${TALOSCONFIG} merge ${CONFIGS}/{{ cluster.name }}/talosconfig
{% endfor %}