| doc_type | explanation |
|---|---|
| title | Codebase Organization |
| audience | developers |
Purpose: For developers, explains how the openCenter-cli codebase is organized and where to find specific functionality.
openCenter-cli/
├── cmd/ # CLI commands (Cobra)
├── internal/ # Internal packages
├── docs/ # Documentation
├── tests/ # BDD test scenarios
├── schema/ # JSON schema definitions
├── testdata/ # Test fixtures
├── hack/ # Scripts and utilities
├── bin/ # Compiled binaries (gitignored)
├── third-party/ # External dependencies
├── main.go # Entry point
├── go.mod # Go module definition
└── .mise.toml # Build tasks and tool versions
Commands follow the pattern cmd/<command>_<subcommand>.go:
Cluster commands (cluster_*.go):
cluster_init.go- Initialize cluster configurationcluster_validate.go- Validate configurationcluster_setup.go- Generate GitOps repositorycluster_bootstrap.go- Deploy clustercluster_edit.go- Edit configuration interactivelycluster_update.go- Update configuration via flagscluster_list.go- List clusterscluster_select.go- Set active clustercluster_info.go- Show cluster detailscluster_destroy.go- Destroy clustercluster_preflight.go- Run preflight checkscluster_render.go- Render templates without deploying
Secrets commands (secrets_*.go, sops_*.go):
cluster_check_keys.go- Check SOPS key expirationcluster_rotate_keys.go- Rotate SOPS keyscluster_validate_secrets.go- Validate secrets encryptioncluster_sync_secrets.go- Synchronize secrets
Configuration commands (config_*.go):
config_edit.go- Edit global configuration
Utility commands:
version.go- Show version informationshell_init.go- Shell integration setupplugins.go- Plugin management
Command naming convention:
// Function returns *cobra.Command
func newCluster<Action>Cmd() *cobra.Command {
return &cobra.Command{
Use: "action",
Short: "Brief description",
RunE: runClusterAction,
}
}Core configuration management:
config.go- Main Config struct and typesschema.go- JSON schema generationvalidator.go- Validation logic (schema + business rules)loader.go- Configuration loading from YAMLmanager.go- Configuration lifecycle managementpath_resolver.go- Organization-based path resolutionmigrator.go- Schema migration between versionsdefaults/- Default configuration templates per providerv2/- Version 2 configuration structs
Key types:
type Config struct {
OpenCenter OpenCenterConfig
OpenTofu OpenTofuConfig
Deployment DeploymentConfig
Metadata MetadataConfig
Secrets SecretsConfig
}
type OpenCenterConfig struct {
Meta MetaConfig
Secrets SecretsBackendConfig
Infrastructure InfrastructureConfig
Cluster ClusterConfig
GitOps GitOpsConfig
Storage StorageConfig
Services ServicesConfig
}GitOps repository scaffolding:
copy.go- Template copying and rendering logicembed.go- Embedded template management (//go:embed)gitops-base-dir/- Base repository structure (embedded)templates/- Cluster-specific templates (embedded)
Template structure:
gitops-base-dir/
├── applications/
│ └── base/
│ └── services/
│ ├── cert-manager/
│ ├── kyverno/
│ └── ...
└── infrastructure/
└── clusters/
├── openstack/
├── vmware/
└── ...
SOPS and Age key management:
manager.go- SOPS manager interfacekeys.go- Age key generation and storageencrypt.go- Encryption/decryption operationsgit.go- Git integration for encrypted filesvalidator.go- SOPS configuration validation
Cloud provider adapters:
internal/cloud/openstack/- OpenStack preflight checksinternal/provision/- Terraform/OpenTofu provisioninginternal/ansible/- Ansible provisioning (Kubespray)
Security utilities:
input_validator.go- Input validation (path traversal, injection)command_sanitizer.go- Command sanitizationcredential_masker.go- Credential masking in logsaudit_logger.go- Audit logging with HMAC signatures
Shared utility packages:
crypto/- Key generation and managementerrors/- Error handling and aggregationfiles/- File operations (atomic writes, backups)paths/- Path resolution and validationtemplate/- Template engine and validation
internal/ansible/- Kubespray inventory generation from configinternal/barbican/- OpenStack Key Manager (Barbican) clientinternal/benchmarks/- Performance benchmarks for config systeminternal/cluster/- Cluster lifecycle services (init, validate, setup, bootstrap, destroy)internal/core/- Shared path resolution (core/paths) and validation engine (core/validation)internal/credentials/- Cloud credential extraction from configinternal/di/- Dependency injection container (App struct + reflection-based Container)internal/importer/- Live cluster import/scan for existing workloadsinternal/localdev/- Local dev environment (Kind, Gitea, Flux)internal/observability/- Structured logging with credential maskinginternal/operations/- Drift detection, backup, disaster recoveryinternal/plugins/- External CLI plugin discovery and checksum verificationinternal/resilience/- Retry, circuit breaker, distributed locksinternal/secrets/- Multi-cluster secrets management (rotation, registry, hooks, revocation)internal/services/- Platform service plugin registry with dependency resolutioninternal/template/- Template engine with caching, validation, sandboxinginternal/testenv/- Test environment helpers (isolated CLI config/state)internal/testing/- Shared test utilities (helpers, mocks, generators, benchmarks)internal/tofu/- OpenTofu/Terraform provisioning executioninternal/ui/- Prompts, error formatting, guided flows
BDD tests using Cucumber/Gherkin:
tests/
└── features/
├── workflow.feature
├── cluster_init.feature
├── validation.feature
└── steps/
├── cluster_steps.go
├── config_steps.go
└── test_suite.go
Tag convention:
@wip- Work in progress scenarios@priority1- High priority tests@priority2- Medium priority tests
User configurations stored in organization-based structure:
~/.config/opencenter/clusters/
└── <organization>/
├── <cluster>/
│ └── .<cluster>-config.yaml
├── secrets/
│ ├── age/
│ │ └── <cluster>-key.txt
│ └── ssh/
│ └── <cluster>-<env>-<region>
└── gitops/
├── applications/
└── infrastructure/
Each package has a single, well-defined responsibility:
cmd/- CLI interface and user interactioninternal/config/- Configuration managementinternal/gitops/- GitOps repository generationinternal/sops/- Secrets encryptioninternal/cloud/- Provider-specific logic
Avoid global state, pass dependencies explicitly:
// Good: Dependencies injected
func NewValidator(schema *jsonschema.Schema) *Validator {
return &Validator{schema: schema}
}
// Bad: Global state
var globalSchema *jsonschema.SchemaDefine interfaces in consumer packages:
// internal/config/interfaces.go
type SecretManager interface {
Encrypt(data []byte) ([]byte, error)
Decrypt(data []byte) ([]byte, error)
}
// internal/sops/manager.go implements SecretManagerTemplates and defaults embedded in binary via //go:embed:
//go:embed gitops-base-dir
var gitopsBaseFS embed.FS
//go:embed templates
var templatesFS embed.FSUse fmt.Errorf with %w for error context:
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}- Commands:
<noun>_<verb>.go(e.g.,cluster_init.go) - Tests:
<name>_test.go(unit),<name>_property_test.go(property) - Interfaces:
interfaces.goin each package - Documentation:
doc.gofor package documentation
To add a new command:
- Create
cmd/cluster_<action>.go - Implement
newCluster<Action>Cmd() - Register in
cmd/cluster.go
To modify configuration:
- Update
internal/config/config.go(structs) - Update
internal/config/schema.go(JSON schema) - Update
internal/config/defaults.go(defaults)
To add a provider:
- Create
internal/cloud/<provider>/preflight.go - Add defaults in
internal/config/defaults.go - Register in
cmd/cluster_preflight.go
To add a service:
- Add defaults in
internal/config/defaults.go - Create templates in
internal/gitops/gitops-base-dir/ - Add validation in
internal/config/service_validator.go
To add validation:
- Update
internal/config/validator.go(business rules) - Update
internal/config/schema.go(schema constraints) - Add provider-specific validation in
internal/config/<provider>_validator.go
- Total lines: 147,952 LOC
- Go files: 628 files
- Test files: 276 files
- Internal packages: 25 packages
- Commands: 70+ command files
- Dependencies: 19 direct dependencies
Commands encapsulate operations:
type Command interface {
Execute() error
}Configuration storage abstracted:
type ConfigRepository interface {
Load(path string) (*Config, error)
Save(path string, cfg *Config) error
}Base template with provider-specific overrides:
func GenerateInfrastructure(provider string) error {
// Common steps
loadConfig()
validateConfig()
// Provider-specific
switch provider {
case "openstack":
generateOpenStackTerraform()
case "aws":
generateAWSTerraform()
}
// Common steps
writeFiles()
}This documentation is based on the following repository files:
- Project structure:
.kiro/steering/structure.md:1-128 - Command layer:
cmd/directory (70+ files) - Internal packages:
internal/directory (25 packages) - Configuration:
internal/config/directory - GitOps:
internal/gitops/directory - Testing:
tests/features/directory - Code metrics: Session 1 summary (A1)
- Organization principles:
.kiro/steering/structure.md:130-145