forked from mtusi2026/mtusi2026lab3
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Проверяет, что контейнеры имеют CPU/RAM лимиты и api не публикует порт."""
|
|
import json
|
|
|
|
from common import Failure, check, compose, print_pass
|
|
|
|
|
|
def main():
|
|
raw = compose('config', '--format', 'json').stdout
|
|
cfg = json.loads(raw)
|
|
services = cfg['services']
|
|
|
|
check('api' in services, 'сервис api отсутствует')
|
|
api = services['api']
|
|
check(not api.get('ports'),
|
|
'api публикует порты наружу: %r — должно быть только через lb' % api.get('ports'))
|
|
deploy = api.get('deploy', {})
|
|
res = deploy.get('resources', {}).get('limits', {})
|
|
check('cpus' in res and 'memory' in res,
|
|
'api без deploy.resources.limits cpus/memory: %r' % res)
|
|
check('container_name' not in api,
|
|
'api задаёт container_name — ломает deploy.replicas')
|
|
|
|
check('lb' in services, 'нет сервиса lb')
|
|
lb_ports = services['lb'].get('ports', [])
|
|
check(any('8080' in str(p) for p in lb_ports),
|
|
'lb не публикует 8080: %r' % lb_ports)
|
|
|
|
print_pass('limits & topology')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except Failure as e:
|
|
print('FAIL:', e)
|
|
raise SystemExit(1) |