How litmuschaos/litmusctl works
Project type and purpose
• Project type: a Go-based command-line “open-source tool” (CLI) for managing LitmusChaos agents and Chaos Center resources.
• Purpose: expose subcommands (connect, create, get, delete, etc.) to end-users, interact with Kubernetes (via kubeconfig + kubectl under the hood), and call remote Chaos Center APIs to orchestrate chaos experiments, environments, probes, etc.
File structure
Top-level directories:
• pkg/cmd – Cobra-based command definitions & dispatch (“frontend” of the CLI).
• pkg/apis – HTTP API clients for Chaos Center (auth, project, experiment, probe, infra, upgrade).
• pkg/k8s – wrappers around kubectl or client-go to apply/manipulate manifests.
• pkg/config – logic to store/load CLI config (accounts, contexts).
• pkg/infra_ops – logic to provision infrastructure (delegates) on cloud/K8s.
• pkg/types – shared data structures (API request/response, config types).
• pkg/utils – common helpers (constants, readers, compatibility checks).
Other files: main.go (root of CLI), go.mod/sum, Makefile, CI workflows, DEVELOPMENT.md.
README for additional insights
• Emphasizes that litmusctl uses kubeconfig + kubectl under the hood.
• Enumerates high-level operations (connect/disconnect delegates, create projects/environments/experiments).
• Lists external requirements: kubeconfig, kubectl, target Chaos Center endpoint.
Detail
– Capture each sublayer (Config Manager vs. Command Parser vs. HTTP client vs. K8s client).
– Show local file I/O (reading kubeconfig and litmusctl config files).
– Illustrate error/response flows (e.g., APIClient receives JSON → maps to types in pkg/types → passed back to CLI for output).
[User Shell]
↓
[CLI Binary: pkg/cmd (root + subcommands)]
→ reads/writes [Config Manager: pkg/config]
→ invokes [API Client Layer: pkg/apis/*] → → [Chaos Center REST API]
→ invokes [K8s Client: pkg/k8s (kubectl)] → → [K8s API Server]
→ invokes [Infra Ops: pkg/infra_ops] → → [Cloud Provider APIs or K8s]
Shared Libraries: pkg/types, pkg/utils