How michielvha/edgectl works
Project type and purpose
• This is an open-source, Go-based CLI tool (“edge-cli”) built with Cobra/Viper.
• Its primary role is to automate the lifecycle of “edge cloud” Kubernetes clusters (powered by RKE2), manage secrets via HashiCorp Vault, and bootstrap additional tools (e.g. ArgoCD/Helm).
Key architectural components
a. CLI layer (entry point)
• main.go + cmd/ → Cobra commands and subcommands (rke2.{agent,server,lb,system}, vault, version)
• Flags & config via Viper (global flags, env vars, config file)
b. Core libraries (pkg/)
• pkg/common: shared helpers, embedded resources, shell-script wrappers (rke2-bash.sh, rke2-purge.sh, etc.)
• pkg/logger: zerolog wrapper for logging levels
• pkg/lb: load-balancer specific logic
• pkg/rke2: installation and orchestration logic for agent/server
• pkg/vault: abstraction over Vault API (generic, kubeconfig, load-balancer, server, token)
c. External scripts & manifests
• manifests/*.yml: Kubernetes manifests for debugging
• pkg/common/scripts/*.sh: low-level install/status/purge scripts
d. External systems & services
• RKE2 Kubernetes clusters (agent nodes, server nodes, load-balancer)
• HashiCorp Vault (secret storage/management)
• Helm/ArgoCD for GitOps bootstrapping
• GitVersion & Goreleaser for CI/CD (see .github/workflows, gitversion.yml, goreleaser.yml)
Interactions & data flow
• User runs edgectl <command> → Cobra parses command → delegates to a pkg/* handler
• Handler may:
• Invoke pkg/common/scripts/*.sh to install RKE2 binaries and systemd units on remote hosts
• Call pkg/rke2 code to configure and start RKE2 nodes (agent/server)
• Use pkg/vault to store or fetch cluster tokens and kubeconfig in Vault
• Fetch generated kubeconfig and merge it into local kubeconfig context
• Optionally commit or push Helm charts for ArgoCD integration
• CI/CD pipelines detect code changes → run tests (future), build binaries via Goreleaser, tag releases via GitVersion → publish artifacts
Architectural patterns & design principles
• Layered architecture: cmd/ (presentation) → pkg/ (domain logic) → external dependencies (Vault, RKE2 CLI, shell scripts)
• Adapter pattern for secret management (pkg/vault implements a Vault interface; future “bring your own” backends)
• Modular command structure via Cobra for easy extensibility
• Single responsibility: each pkg/* focuses on one integration or concern
• edgectl → pkg/rke2 (install/configure cluster)
• edgectl → pkg/vault (store/fetch secrets)
• pkg/rke2 → pkg/common/scripts (invoke shell scripts)
• pkg/vault ↔ Vault service (HTTPS API calls)
• edgectl → Kubernetes cluster (via kubeconfig, kubectl)
• edgectl → Git repository (Helm chart commits, ArgoCD bootstrap)
• CI/CD pipeline → edgectl repo (on push/tag) → builds → releases