Compare commits
2 Commits
b0e146241b
...
dac2864b2d
| Author | SHA1 | Date | |
|---|---|---|---|
|
dac2864b2d
|
|||
|
85368a3126
|
42
templates/generate_configs.sh
Normal file
42
templates/generate_configs.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
ROOT=$(git rev-parse --show-toplevel)
|
||||
CONFIGS=${ROOT}/configs
|
||||
|
||||
# Generate the configuration for each node
|
||||
{% set clusters = [] %}
|
||||
{%- for node in nodes -%}
|
||||
talosctl gen config {{ node.clusterName }} https://{{ node.controlplaneIp }}:6443 -f \
|
||||
--with-secrets ${ROOT}/secrets.yaml \
|
||||
--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 -%}
|
||||
--with-docs=false \
|
||||
--with-examples=false \
|
||||
-o ${CONFIGS}/{{ node.filename }}.yaml
|
||||
|
||||
{%- do clusters.append((node.clusterName, node.controlplaneIp)) %}
|
||||
{% endfor %}
|
||||
|
||||
# Generate the talosconfig file for each cluster
|
||||
{% for cluster in clusters|unique -%}
|
||||
talosctl gen config {{ cluster[0] }} https://{{ cluster[1] }}:6443 -f \
|
||||
--with-secrets ${ROOT}/secrets.yaml \
|
||||
--output-types talosconfig \
|
||||
-o ${CONFIGS}/{{ cluster[0] }}/talosconfig
|
||||
{% endfor %}
|
||||
|
||||
# Create merged talosconfig
|
||||
export TALOSCONFIG=${CONFIGS}/talosconfig
|
||||
rm -f ${TALOSCONFIG}
|
||||
{% for cluster in clusters|unique -%}
|
||||
talosctl config merge ${CONFIGS}/{{ cluster[0] }}/talosconfig
|
||||
{% endfor %}
|
||||
@@ -124,10 +124,10 @@ def main():
|
||||
yml_data["filename"] = filename
|
||||
nodes.append(yml_data)
|
||||
|
||||
final_nodes = []
|
||||
for node in nodes:
|
||||
# Quick and dirty way to resolve all the templates using a custom encoder
|
||||
final_nodes.append(json.loads(json.dumps(node, cls=node_encoder(node))))
|
||||
nodes = list(
|
||||
map(lambda node: json.loads(json.dumps(node, cls=node_encoder(node))), nodes)
|
||||
)
|
||||
|
||||
with open(ROOT.joinpath("config.yaml")) as fyaml:
|
||||
config = yaml.safe_load(fyaml)
|
||||
@@ -136,7 +136,7 @@ def main():
|
||||
for template_name in TEMPLATES.list_templates():
|
||||
template = TEMPLATES.get_template(template_name)
|
||||
|
||||
rendered = template.render(nodes=final_nodes, config=config)
|
||||
rendered = template.render(nodes=nodes, config=config)
|
||||
with open(RENDERED.joinpath(template_name), "w") as f:
|
||||
f.write(rendered)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user