Compare commits
4 Commits
3f8389ddd2
...
6edb869cd9
| Author | SHA1 | Date | |
|---|---|---|---|
|
6edb869cd9
|
|||
|
2cca38c860
|
|||
|
d2a1eca146
|
|||
|
0049b5cb46
|
@@ -1,11 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
ROOT=$(git rev-parse --show-toplevel)
|
ROOT={{ root }}
|
||||||
CONFIGS=${ROOT}/configs
|
CONFIGS=${ROOT}/configs
|
||||||
|
|
||||||
# Generate the configuration for each node
|
# Generate the configuration for each node
|
||||||
{% set clusters = [] %}
|
{% for node in nodes -%}
|
||||||
{%- for node in nodes -%}
|
|
||||||
talosctl gen config {{ node.clusterName }} https://{{ node.controlplaneIp }}:6443 -f \
|
talosctl gen config {{ node.clusterName }} https://{{ node.controlplaneIp }}:6443 -f \
|
||||||
--with-secrets ${ROOT}/secrets.yaml \
|
--with-secrets ${ROOT}/secrets.yaml \
|
||||||
--talos-version {{ node.talosVersion }} \
|
--talos-version {{ node.talosVersion }} \
|
||||||
@@ -22,21 +21,20 @@ talosctl gen config {{ node.clusterName }} https://{{ node.controlplaneIp }}:644
|
|||||||
--with-docs=false \
|
--with-docs=false \
|
||||||
--with-examples=false \
|
--with-examples=false \
|
||||||
-o ${CONFIGS}/{{ node.filename }}.yaml
|
-o ${CONFIGS}/{{ node.filename }}.yaml
|
||||||
|
|
||||||
{%- do clusters.append((node.clusterName, node.controlplaneIp)) %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
# Generate the talosconfig file for each cluster
|
# Generate the talosconfig file for each cluster
|
||||||
{% for cluster in clusters|unique -%}
|
{# NOTE: This assumes that each node in a cluster specifies the same controlplane IP -#}
|
||||||
talosctl gen config {{ cluster[0] }} https://{{ cluster[1] }}:6443 -f \
|
{% for cluster in clusters -%}
|
||||||
|
talosctl gen config {{ cluster.name }} https://{{ cluster.controlplaneIp }}:6443 -f \
|
||||||
--with-secrets ${ROOT}/secrets.yaml \
|
--with-secrets ${ROOT}/secrets.yaml \
|
||||||
--output-types talosconfig \
|
--output-types talosconfig \
|
||||||
-o ${CONFIGS}/{{ cluster[0] }}/talosconfig
|
-o ${CONFIGS}/{{ cluster.name }}/talosconfig
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
# Create merged talosconfig
|
# Create merged talosconfig
|
||||||
export TALOSCONFIG=${CONFIGS}/talosconfig
|
export TALOSCONFIG=${CONFIGS}/talosconfig
|
||||||
rm -f ${TALOSCONFIG}
|
rm -f ${TALOSCONFIG}
|
||||||
{% for cluster in clusters|unique -%}
|
{% for cluster in clusters -%}
|
||||||
talosctl config merge ${CONFIGS}/{{ cluster[0] }}/talosconfig
|
talosctl config merge ${CONFIGS}/{{ cluster.name }}/talosconfig
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
6
templates/source.sh
Normal file
6
templates/source.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export TALOSCONFIG={{ root }}/configs/talosconfig
|
||||||
|
{% set paths = [] %}
|
||||||
|
{%- for cluster_name in nodes|map(attribute="clusterName")|unique -%}
|
||||||
|
{%- do paths.append(root ~ "/configs/" ~ cluster_name ~ "/kubeconfig") -%}
|
||||||
|
{% endfor -%}
|
||||||
|
export KUBECTL={{ paths|join(":") }}
|
||||||
17
tools/render
17
tools/render
@@ -5,13 +5,14 @@
|
|||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import sys
|
||||||
|
|
||||||
import git
|
import git
|
||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template
|
from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template
|
||||||
|
|
||||||
REPO = git.Repo(".", search_parent_directories=True)
|
REPO = git.Repo(sys.path[0], search_parent_directories=True)
|
||||||
assert REPO.working_dir is not None
|
assert REPO.working_dir is not None
|
||||||
|
|
||||||
ROOT = pathlib.Path(REPO.working_dir)
|
ROOT = pathlib.Path(REPO.working_dir)
|
||||||
@@ -134,6 +135,16 @@ def main():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Get all clusterName & controlplaneIp pairs
|
||||||
|
clusters = map(
|
||||||
|
lambda node: {
|
||||||
|
"name": node["clusterName"],
|
||||||
|
"controlplaneIp": node["controlplaneIp"],
|
||||||
|
},
|
||||||
|
nodes,
|
||||||
|
)
|
||||||
|
clusters = [dict(s) for s in set(frozenset(d.items()) for d in clusters)]
|
||||||
|
|
||||||
with open(ROOT.joinpath("config.yaml")) as fyaml:
|
with open(ROOT.joinpath("config.yaml")) as fyaml:
|
||||||
config = yaml.safe_load(fyaml)
|
config = yaml.safe_load(fyaml)
|
||||||
|
|
||||||
@@ -141,7 +152,9 @@ def main():
|
|||||||
for template_name in TEMPLATES.list_templates():
|
for template_name in TEMPLATES.list_templates():
|
||||||
template = TEMPLATES.get_template(template_name)
|
template = TEMPLATES.get_template(template_name)
|
||||||
|
|
||||||
rendered = template.render(nodes=nodes, config=config)
|
rendered = template.render(
|
||||||
|
nodes=nodes, clusters=clusters, config=config, root=ROOT
|
||||||
|
)
|
||||||
with open(RENDERED.joinpath(template_name), "w") as f:
|
with open(RENDERED.joinpath(template_name), "w") as f:
|
||||||
f.write(rendered)
|
f.write(rendered)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user