This repository has been archived by the owner on Feb 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
zmon-k8s.py
executable file
·108 lines (72 loc) · 3.19 KB
/
zmon-k8s.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
import jinja2
import json
import yaml
from collections import defaultdict
from collections import OrderedDict
import uuid
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('zmon-k8s', 'templates'))
stream = open('config.yaml', 'r')
__CONFIG = yaml.load(stream)
def render_template(file_name, config={}):
template = env.get_template(file_name)
return template.render(config)
def auto_fill(application, file_name=None, config=None):
if not file_name:
file_name = application + ".yaml"
if not config:
config = __CONFIG.get(application, None)
if not config:
pprint ("Config not found")
exit(-1)
return render_template(file_name, config)
def main():
token_scheduler = str(uuid.uuid4()).replace("-","").upper()
token_boot_strap = str(uuid.uuid4()).replace("-","").upper()
postgresql_password = str(uuid.uuid4())
postgresql_admin_password = str(uuid.uuid4())
print("Scheduler Token: {}".format(token_scheduler));
print("Bootstrap Token: {}".format(token_boot_strap));
print("PostgreSQL admin user password: {}".format(postgresql_admin_password));
print("PostgreSQL zmon user password: {}".format(postgresql_password));
env_add = defaultdict(dict)
env_add["zmon-controller"]["PRESHARED_TOKENS_" +token_scheduler+"_UID"] = "zmon-scheduler"
env_add["zmon-controller"]["PRESHARED_TOKENS_" +token_scheduler+"_EXPIRES_AT"] = 1758021422
env_add["zmon-controller"]["POSTGRES_USERNAME"] = "postgres"
env_add["zmon-controller"]["POSTGRES_PASSWORD"] = postgresql_admin_password
# set unprivileged user for zmon worker accese as example
env_add["zmon-worker"]["WORKER_PLUGIN_SQL_PASS"] = postgresql_password
env_add["zmon-eventlog-service"]["POSTGRESQL_PASSWORD"] = postgresql_admin_password
env_add["zmon-scheduler"]["SCHEDULER_OAUTH2_STATIC_TOKEN"] = token_scheduler
print("updating config variables")
for k in __CONFIG:
if not "env_vars" in __CONFIG[k]:
continue
__CONFIG[k]["env_vars"].update(env_add.get(k, {}))
for k in __CONFIG:
if not "env_vars" in __CONFIG[k]:
continue
__CONFIG[k]["env_vars"] = OrderedDict(sorted(__CONFIG[k].get("env_vars", {}).items()))
print("generating postgrsql deployment")
postgresql_config = __CONFIG.get('postgresql')
postgresql_config.update({"postgresql_password": postgresql_admin_password})
f = open("dependencies/postgresql/deployment.yaml", "w")
f.write(render_template("postgresql-deployment.yaml", postgresql_config))
f.close()
print("generating templates for zmon components...")
for k in __CONFIG:
if not k.startswith("zmon-"):
continue
print("\t for {}".format(k))
f = open("deployments/" + k + ".yaml", 'w')
f.write(auto_fill(k))
f.close()
print("")
print(render_template("create-dependencies.sh"))
print("")
print(render_template("inject-database.sh", {"admin_password": postgresql_admin_password, "postgresql_password": postgresql_password}))
print("")
print(render_template("create-zmon-components.sh"))
if __name__ == '__main__':
main()