How eda-labs/clab-connector works
Project type and purpose
• This is a Python-based CLI connector tool (“clab-connector”) that automates the onboarding and offboarding of Containerlab topologies into an Event-Driven Automation (EDA) system running in Kubernetes.
• It provides subcommands (integrate, remove, export-lab, generate-crs) to read a Containerlab topology JSON, render Kubernetes CR YAML via Jinja2 templates, and apply or delete those resources against an EDA cluster (using HTTP calls and kubectl).
High-level architecture from the file tree
• Top-level module: clab_connector/
• cli/ – entrypoint & argument parsing (main.py)
• services/ – business logic for each subcommand: integration, removal, export, manifest generation
• models/ – domain models for Network Topology, Nodes, Links, plus a factory for node types
• clients/ – adapters for external systems:
– eda/http_client.py for direct HTTP API calls to EDA (Keycloak & EDA CRD)
– kubernetes/client.py wrapping kubectl apply/delete
• templates/ – Jinja2 templates for CR YAML artifacts, init, interfaces, profiles, etc.
• utils/ – shared helpers: YAML processing, constants, exception types, logging configuration
1. CLI Layer
– Input: command + flags + topology-data.json file
– Component: clab_connector/cli/main.py
2. Service Layer
– IntegrationService, RemovalService, ExportService, ManifestGeneratorService
3. Domain Layer
– Topology, Node, Link, NodeFactory (in models/)
4. Adapter Layer
a. EDA HTTP Client (Keycloak & EDA CRDs)
b. Kubernetes Client (invokes kubectl)
5. Template Engine
– Jinja2 runtime rendering of YAML from templates in templates/
6. External Systems
– Containerlab (source of topology-data.json)
– Kubernetes Cluster running EDA + Keycloak
1. CLI → Service: pass parsed options & path to JSON
2. Service → Domain: construct in-memory Topology object via models & node factory
3. Service → Template Engine: render CR YAML snippets for each domain object
4. Service → Adapter:
• Kubernetes Client: kubectl apply/delete of rendered YAML
• HTTP Client: token retrieval from Keycloak & direct EDA API calls (optional)
5. Adapters → External Systems: Kubernetes API server & EDA HTTP endpoints
C. Architectural patterns & design principles
• Layered (Presentation/Service/Domain/Infrastructure) or Hexagonal (Ports & Adapters)
• Single Responsibility per module: CLI only parses, Services only orchestrate, Models only define data, Clients only communicate externally
• Template-driven manifest generation (separation of concerns)
• Use of factory pattern for instantiating different node types
D. Key technologies & libraries
• Python 3.x, uv for packaging
• Jinja2 for templating
• YAML processor (ruamel.yaml or PyYAML in utils)
• HTTP (requests or httpx) for EDA API
• Subprocess or Python client for kubectl
• Logging config via logging module
Final advice
• Break the system into all logical components you see in the file tree (CLI, models, services, clients, templates, utils).