105 lines
3.9 KiB
Python
105 lines
3.9 KiB
Python
import ruamel.yaml
|
|
import os
|
|
from tenant.utils.common import calculate_java_settings
|
|
from OpenSSL import crypto
|
|
|
|
TYPE_RSA = crypto.TYPE_RSA
|
|
TYPE_DSA = crypto.TYPE_DSA
|
|
key = crypto.PKey()
|
|
|
|
yaml = ruamel.yaml.YAML()
|
|
|
|
|
|
def recursively_sort_dict(input_dict):
|
|
sorted_dict = dict(sorted(input_dict.items()))
|
|
for key, value in sorted_dict.items():
|
|
if isinstance(value, dict):
|
|
sorted_dict[key] = recursively_sort_dict(value)
|
|
return sorted_dict
|
|
|
|
|
|
def template_values(tenant_name, tenant_size, flavor, ingress, values_file):
|
|
print(os.getcwd())
|
|
with open("./helm/template-values.yaml", "r", encoding="utf-8") as file:
|
|
existing_values = yaml.load(file)
|
|
|
|
with open("./helm/mapping-values.yaml", "r") as file:
|
|
mapping = yaml.load(file)
|
|
|
|
if tenant_size in mapping:
|
|
if flavor not in ["laas", "daas"]:
|
|
print("Invalid flavor")
|
|
else:
|
|
# map "selected_values" to "mapping" in reference to the tenant size
|
|
mapped_values = mapping[tenant_size]
|
|
|
|
# setting default values from defaults block
|
|
existing_values["oauthProxy"]["clientId"] = tenant_name + "-logging-client"
|
|
existing_values["oauthProxy"]["issuerUrl"]["realmPath"] = (
|
|
"/realms/" + tenant_name
|
|
)
|
|
existing_values["elasticsearch"]["image"]["version"] = mapping["defaults"][
|
|
"elasticsearch"
|
|
]["version"]
|
|
|
|
# configure resource sizing of elasticsearch components
|
|
existing_values["elasticsearch"]["config"]["flavor"] = flavor
|
|
|
|
existing_values["elasticsearch"]["data"] = mapped_values["elasticsearch"][
|
|
"data"
|
|
]
|
|
existing_values["elasticsearch"]["coordinator"] = mapped_values[
|
|
"elasticsearch"
|
|
]["coordinator"]
|
|
existing_values["elasticsearch"]["master"] = mapped_values["elasticsearch"][
|
|
"master"
|
|
]
|
|
# configure kibana
|
|
existing_values["kibana"]["image"]["version"] = mapping["defaults"][
|
|
"kibana"
|
|
]["version"]
|
|
|
|
# configure resource sizing of kafka components
|
|
existing_values["kafka"]["resources"] = mapped_values["kafka"]["resources"]
|
|
existing_values["kafka"]["javaOpts"]["heap"] = calculate_java_settings(
|
|
mapped_values["kafka"]["resources"]["requests"]["memory"]
|
|
)
|
|
|
|
# explicitly set ingress domain
|
|
existing_values["ingress"]["domain"] = ingress
|
|
|
|
# template tls configuration
|
|
existing_values["tls"]["issuer"]["name"] = tenant_name + "-issuer"
|
|
existing_values["tls"]["issuer"]["auth"]["path"] = (
|
|
"/v1/auth/bn-" + tenant_name + "-cert-manager"
|
|
)
|
|
existing_values["tls"]["issuer"]["auth"]["role"] = (
|
|
"bn-" + tenant_name + "-pki-INT-cert-signers"
|
|
)
|
|
existing_values["tls"]["issuer"]["secret"]["role"] = (
|
|
"bn-" + tenant_name + "-pki-INT-cert-signers"
|
|
)
|
|
|
|
existing_values["logstash"]["pipeline"]["pipelines"][0][
|
|
"workers"
|
|
] = mapped_values["pipelines"]["logging"]["workers"]
|
|
|
|
existing_values["logstash"]["pipeline"]["replicas"] = mapped_values[
|
|
"pipelines"
|
|
]["replicas"]
|
|
|
|
existing_values["kafka"]["topics"]["logging"]["partitions"] = (
|
|
mapped_values["pipelines"]["replicas"]
|
|
* mapped_values["pipelines"]["logging"]["workers"]
|
|
)
|
|
|
|
# order the values in the "existing_values" dictionary alphabetically
|
|
existing_values = recursively_sort_dict(existing_values)
|
|
|
|
# write ordered values to instance-new.yaml
|
|
with open(values_file, "w", encoding="utf-8") as new_file:
|
|
yaml.dump(existing_values, new_file)
|
|
|
|
else:
|
|
print("Invalid tenant sizing")
|