-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_values.py
executable file
·65 lines (41 loc) · 1.55 KB
/
gen_values.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import os
import yaml
from jinja2 import Environment, FileSystemLoader
REPONAME = "cluster-role"
def parse_args():
p = argparse.ArgumentParser(description="Helm chart gen")
p.add_argument("-r", "--reponame", default=REPONAME, help="reponame")
return p.parse_args()
def gen_repos(args):
os.makedirs("build", exist_ok=True)
os.makedirs("charts", exist_ok=True)
template_path = "charts/{}/values-template.yaml".format(args.reponame)
if os.path.exists(template_path):
print("# gen_values", template_path)
e = Environment(loader=FileSystemLoader("charts/{}/".format(args.reponame)))
t = e.get_template("values-template.yaml")
gen_values(t, args.reponame)
def gen_values(t, reponame):
for env_file in os.listdir("env"):
if env_file.endswith(".yaml"):
# print("")
env_path = "env/{}".format(env_file)
# print("# env ", env_path)
save_root = "charts/{}/demo".format(reponame)
save_path = "{}/values-{}".format(save_root, env_file)
with open(env_path, "r") as vars:
v = yaml.safe_load(vars)
d = t.render(v)
if d != None:
os.makedirs(save_root, exist_ok=True)
with open(save_path, "w") as file:
print("# save", save_path)
file.write(d)
def main():
args = parse_args()
gen_repos(args)
if __name__ == "__main__":
main()