forked from shikanon/kubeflow-manifests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-install.py
32 lines (27 loc) · 874 Bytes
/
pre-install.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
#!/bin/python
#coding:utf-8
import os
import shlex
import yaml
from yaml import CLoader
from replace import replaceImage
import subprocess
mainfile = "kustomization.yaml"
with open(mainfile, "r") as fr:
kustomizefile = yaml.load(fr,Loader=CLoader)
n = 0
for path in kustomizefile['resources']:
n = n + 1
abspath = os.path.abspath(path)
abspath = abspath.replace("\\","/")
filename = "-".join([path.split("/")[2]]+path.split("/")[-2:])
cmd = "kustomize build --load_restrictor=none {path}".format(path=path)
print(cmd)
p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
out = p.stdout.read()
if out == "":
raise ValueError(cmd)
filename = str(n).zfill(3) + "-" + filename +".yaml"
out = replaceImage(out.decode("utf-8"))
with open("file/"+ filename, "w", encoding="utf-8") as fw:
fw.write(out)