mirror of
https://github.com/katanemo/plano.git
synced 2026-04-25 16:56:24 +02:00
Add ability to define clusters in config (#61)
This commit is contained in:
parent
215d276acf
commit
a91fbdbf1c
7 changed files with 59 additions and 32 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
import yaml
|
||||
|
||||
ENVOY_CONFIG_TEMPLATE_FILE = os.getenv('ENVOY_CONFIG_TEMPLATE_FILE', 'envoy.template.yaml')
|
||||
BOLT_CONFIG_FILE = os.getenv('BOLT_CONFIG_FILE', 'bolt_config.yaml')
|
||||
|
|
@ -11,8 +12,36 @@ template = env.get_template('envoy.template.yaml')
|
|||
with open(BOLT_CONFIG_FILE, 'r') as file:
|
||||
katanemo_config = file.read()
|
||||
|
||||
config_yaml = yaml.safe_load(katanemo_config)
|
||||
|
||||
inferred_clusters = {}
|
||||
|
||||
for prompt_target in config_yaml["prompt_targets"]:
|
||||
cluster = prompt_target.get("endpoint", {}).get("cluster", "")
|
||||
if cluster not in inferred_clusters:
|
||||
inferred_clusters[cluster] = {
|
||||
"name": cluster,
|
||||
"address": cluster,
|
||||
"port": 80, # default port
|
||||
}
|
||||
|
||||
print(inferred_clusters)
|
||||
|
||||
clusters = config_yaml.get("clusters", {})
|
||||
|
||||
# override the inferred clusters with the ones defined in the config
|
||||
for name, cluster in clusters.items():
|
||||
if name in inferred_clusters:
|
||||
print("updating cluster", cluster)
|
||||
inferred_clusters[name].update(cluster)
|
||||
else:
|
||||
inferred_clusters[name] = cluster
|
||||
|
||||
print("updated clusters", inferred_clusters)
|
||||
|
||||
data = {
|
||||
'katanemo_config': katanemo_config
|
||||
'katanemo_config': katanemo_config,
|
||||
'arch_clusters': inferred_clusters
|
||||
}
|
||||
|
||||
rendered = template.render(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue