Files
factorio/tests/validate.py
T

25 lines
1.4 KiB
Python
Raw Normal View History

import json,sys,yaml
from pathlib import Path
resources=list(yaml.safe_load_all(Path(sys.argv[1]).read_text()))
assert len({(d['kind'],d['metadata'].get('namespace'),d['metadata']['name']) for d in resources})==len(resources)
d=next(d for d in resources if d['kind']=='Deployment')
assert d['spec']['strategy']['type']=='Recreate'
assert d['spec']['replicas']==1
spec=d['spec']['template']['spec']
assert not spec['automountServiceAccountToken']
for c in spec['containers']:
2026-10-27 07:16:05 +01:00
assert all(p in c for p in ('startupProbe','readinessProbe','livenessProbe')), c['name']
if 'resources' in c:
assert isinstance(c['resources'], dict), c['name']
assert ':' in c['image'] and not c['image'].endswith(':latest')
2026-10-27 07:16:05 +01:00
assert 'affinity' not in spec
assert 'tolerations' not in spec
for service in (d for d in resources if d['kind']=='Service'):
assert all(p['port']!=27015 for p in service['spec']['ports'])
2026-10-27 07:16:05 +01:00
funkfeuer=next(s for s in resources if s['kind']=='Service' and s['metadata']['name']=='factorio-funkfeuer')
assert 'externalIPs' not in funkfeuer['spec']
assert 'loadBalancerIP' not in next(s for s in resources if s['kind']=='Service' and s['metadata']['name']=='factorio')['spec']
for cm in (d for d in resources if d['kind']=='ConfigMap'):
for name,value in cm.get('data',{}).items():
if name.endswith('.json'): json.loads(value)
print(f'Validated {len(resources)} rendered resources')