feat: добавлена поддержка создания и удаления контейнеров из пресета
Some checks failed
Ansible Testing / lint (push) Has been cancelled
Ansible Testing / test (default) (push) Has been cancelled
Ansible Testing / test (minimal) (push) Has been cancelled
Ansible Testing / test (performance) (push) Has been cancelled
Ansible Testing / deploy-check (push) Has been cancelled

- Добавлено создание контейнеров из секции hosts в create_k8s_cluster.py
- Добавлено удаление контейнеров в команде make k8s destroy
- Создан скрипт scripts/delete_hosts.py для удаления контейнеров
- Контейнеры автоматически создаются в Docker сети из пресета
- Контейнеры удаляются вместе с Kind кластером при make k8s destroy
This commit is contained in:
Сергей Антропов
2025-10-26 08:23:43 +03:00
parent 60c2623fbc
commit 4ed9c2e0eb
7 changed files with 127 additions and 438 deletions

44
scripts/delete_hosts.py Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""
Скрипт для удаления контейнеров из секции hosts пресета
Автор: Сергей Антропов
Сайт: https://devops.org.ru
"""
import sys
import yaml
import subprocess
def main():
if len(sys.argv) < 2:
print("Usage: delete_hosts.py <preset_file>")
sys.exit(1)
preset_file = sys.argv[1]
print(f"📋 Читаю пресет: {preset_file}")
with open(preset_file, 'r') as f:
preset = yaml.safe_load(f)
hosts = preset.get('hosts', [])
if not hosts:
print("⚠️ В пресете нет контейнеров для удаления")
sys.exit(0)
print(f"🗑️ Удаление контейнеров (всего: {len(hosts)})")
for host in hosts:
host_name = host['name']
# Проверяем существование контейнера
result = subprocess.run(f"docker ps -a --format '{{{{.Names}}}}' | grep -x {host_name}",
shell=True, capture_output=True, text=True)
if result.stdout.strip():
print(f"🗑️ Удаление контейнера: {host_name}")
subprocess.run(f"docker rm -f {host_name}", shell=True, capture_output=True, text=True)
print(f"✅ Контейнер '{host_name}' удален")
else:
print(f"⚠️ Контейнер '{host_name}' не найден")
print("✅ Удаление завершено")
if __name__ == "__main__":
main()