How harness/smp-installer works
Major Architectural Layers and Components
• CLI / Entrypoint: Represent the main binary found in cmd/main.go and the various resource commands (e.g., harness.go, kubernetes.go, loadbalancer.go, etc.) in cmd/resources. This layer is in charge of parsing the configuration and dispatching resource creation tasks.
• Resource Commands: These implement the Resource interface and simply serve as orchestration controllers to invoke the client logic.
• Client Layer: In pkg/client, each resource has its own client (for example, pkg/client/dns.go, pkg/client/kubernetes.go, etc.) that abstracts the resource-specific logic, implementing methods like PreExec, Exec, and PostExec.
• Tofu Modules: Under pkg/tofu, the project contains modules for AWS resource provisioning (e.g., aws/dns, aws/kubernetes, aws/loadbalancer, etc.). These modules use templated or direct Terraform/OpenTofu files (*.tf, tf.vars) to generate the actual IaC output.
• Profiles & Configuration Overrides: The pkg/profiles and the profiles/ directory provide configuration overrides for different deployment profiles (e.g., “small” and “pov”). They represent parameters that tailor the installation to different scale or resource requirements.
• Rendering & Store: The pkg/render (template logic) and pkg/store (in-memory or persistent state storage) components handle dynamic configuration generation and storing the intermediate outputs produced by resource clients.
Break Down Relationships and Interactions
• The CLI (cmd/main.go) is the starting point that reads the configuration (example.yaml) and invokes relevant resource commands.
• Each resource command (inside cmd/resources) calls its respective client from pkg/client.
• The client layer executes a series of steps (PreExec, Exec, PostExec) and interacts with the tofu modules (in pkg/tofu) to generate the infrastructure files.
• The rendered templates (via pkg/render/template.go) and the state storage (via pkg/store) are updated through these interactions.
• The configuration profiles (from pkg/profiles or profiles/ folder) feed custom parameters into the templating and execution steps.
• Finally, all outputs (resources created such as EKS clusters, ALBs, VPCs, etc.) are consolidated and stored, with outputs potentially influencing further stages (e.g., monitoring and helm chart installation).
Architectural Patterns and Design Principles
• Modular Design: Notice how each functional area is broken down (resource commands, clients, tofu modules) to provide separation of concerns.
• Template-driven Code Generation: The use of templating (pkg/render) with built-in objects (.Config, .Output, .Self) is a key architectural principle.
• Inversion of Control: The orchestration follows the command pattern where specific resource commands trigger client actions.
• Extensibility: The structure clearly shows extension points (for adding new resources) following consistent patterns – a new file in cmd/resources, client in pkg/client, and tofu module under pkg/tofu.