forked from mtusi2026/mtusi2026lab3
feat:level4
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/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']
|
||||
|
||||
for svc in ('api1', 'api2'):
|
||||
check(svc in services, 'сервис %s отсутствует' % svc)
|
||||
ports = services[svc].get('ports', [])
|
||||
check(not ports, '%s публикует порты наружу: %r — должно быть только через LB'
|
||||
% (svc, ports))
|
||||
deploy = services[svc].get('deploy', {})
|
||||
res = deploy.get('resources', {}).get('limits', {})
|
||||
check('cpus' in res and 'memory' in res,
|
||||
'%s без deploy.resources.limits cpus/memory: %r' % (svc, res))
|
||||
|
||||
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)
|
||||
|
||||
check('container_name' not in services.get('api1', {}),
|
||||
'api1 задаёт container_name — ломает масштабирование')
|
||||
check('container_name' not in services.get('api2', {}),
|
||||
'api2 задаёт container_name — ломает масштабирование')
|
||||
|
||||
print_pass('limits & topology')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except Failure as e:
|
||||
print('FAIL:', e)
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user