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']: 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') 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']) 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')