-
Notifications
You must be signed in to change notification settings - Fork 426
/
rbac-check.py
30 lines (25 loc) · 986 Bytes
/
rbac-check.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
import os
import sys
from yaml import load, CSafeLoader
from deepdiff import DeepDiff
def compare_two_yaml(yaml1, yaml2):
diff = DeepDiff(yaml1['rules'], yaml2['rules'])
if diff:
print(diff)
return not diff
if __name__ == "__main__":
curr_dir_path = os.path.dirname(os.path.realpath(__file__))
helm_rbac_dir = curr_dir_path + '/tmp/'
kustomize_rbac_dir = curr_dir_path + '/../ray-operator/config/rbac/'
os.system(f"{curr_dir_path}/helm-render-yaml.sh")
files = os.listdir(helm_rbac_dir)
diff_files = []
for f in files:
yaml1 = load(open(helm_rbac_dir + f, 'r'), Loader=CSafeLoader)
yaml2 = load(open(kustomize_rbac_dir + f, 'r'), Loader=CSafeLoader)
if not compare_two_yaml(yaml1, yaml2):
diff_files.append(f)
if diff_files:
sys.exit(f"{diff_files} are out of synchronization! RBAC YAML files in" +
"\'helm-chart/kuberay-operator/templates\' and \'ray-operator/config/rbac\'" +
"should be synchronized manually. See DEVELOPMENT.md for more details.")