-
Notifications
You must be signed in to change notification settings - Fork 3
/
templatemigration.py
executable file
·60 lines (46 loc) · 2.5 KB
/
templatemigration.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
#!/usr/bin/env python3
import os
import yaml
import json
# create a new file called index.yaml
basedir = "kubero/services"
def toJson(obj):
return json.dumps(obj, indent=0).replace("\n", "")
for dirname in os.listdir(basedir):
dir = os.path.join(basedir, dirname)
filepath = os.path.join(dir, "service.yaml")
apppath = os.path.join(dir, "app.yaml")
if os.path.isfile(filepath) and os.path.isfile(apppath):
print (filepath)
with open(apppath, "r") as app_yaml:
app = app_yaml.read()
# convert yaml to json
template = yaml.safe_load(app)
with open(filepath, "r") as service_yaml:
service = service_yaml.read()
# convert yaml to json
service = yaml.safe_load(service)
if template.get("metadata") is None:
template["metadata"] = {}
if template["metadata"].get("annotations") is None:
template["metadata"]["annotations"] = {}
#template["metadata"]["annotations"] = service
template["metadata"]["annotations"]['kubero.dev/template.source'] = service["source"]
template["metadata"]["annotations"]['kubero.dev/template.title'] = service["name"]
template["metadata"]["annotations"]['kubero.dev/template.description'] = service["description"]
template["metadata"]["annotations"]['kubero.dev/template.icon'] = service["icon"]
template["metadata"]["annotations"]['kubero.dev/template.website'] = service["website"]
template["metadata"]["annotations"]['kubero.dev/template.installation'] = service.get("installation", "")
template["metadata"]["annotations"]['kubero.dev/template.architecture'] = toJson(service.get("architecture", []))
template["metadata"]["annotations"]['kubero.dev/template.categories'] = toJson(service.get("tags", []))
template["metadata"]["annotations"]['kubero.dev/template.screenshots'] = toJson(service.get("screenshots", []))
template["metadata"]["annotations"]['kubero.dev/template.links'] = toJson(service.get("documentation", []))
#file = "kubero/templates/"+dirname+".yaml" # ready for dir migration
file = "kubero/services/"+dirname+"/app.yaml"
open(file, "w+")
with open(file, "a+") as templateFile:
templateYaml = yaml.dump(template, default_style=None, default_flow_style=False)
templateFile.write(templateYaml.replace("\n\n", "\n"))
# remove the old service.yaml file
os.remove(filepath)
exit(0)