Documentation
¶
Overview ¶
Copyright 2025 Victor Palma <victor.palma@rackspace.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law of a agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cmd defines the Cobra command tree and the user-facing orchestration layer for opencenter.
ExecuteWithContext in root.go is the primary wiring boundary. It builds the typed application graph, places it in the command context, registers the root commands, and discovers external command plugins. Individual command files should remain responsible for argument handling, prompts, terminal output, and sequencing calls into lower-level packages.
Reusable configuration, cluster lifecycle, provider, GitOps, secrets, and validation behavior belongs in a specifically named package under internal. Do not add domain logic to a Cobra Run or RunE function when it can be tested independently behind a focused service API. Conversely, keep command-only presentation policy here instead of leaking it into reusable packages.
Index ¶
- Constants
- Variables
- func ExecuteWithContext(ctx context.Context, version string) error
- func ExitCode(err error) int
- func GetApp(ctx context.Context) (*di.App, error)
- func GetContainer(ctx context.Context) (di.Container, error)
- func GetRootCmd() *cobra.Command
- func NewBuiltinRootCmd() *cobra.Command
- func NewClusterCmd() *cobra.Command
- func NewPluginsCmd() *cobra.Command
- func NewSecretsCmd() *cobra.Command
- func NewSecretsKeysCmd() *cobra.Command
- func NewSettingsCmd() *cobra.Command
- func NewShellInitCmd() *cobra.Command
- func NewVersionCmd() *cobra.Command
- type ClusterMetadata
- type ClusterSelectOutput
- type CreationRule
- type ExitError
- type FluxKustomization
- type GitOpsInfo
- type GlobalFlags
- type GlobalOptions
- type LockAcquisitionResult
- type OutputFormat
- type SOPSConfig
- type SOPSPathMatcher
- type SOPSPathRule
- type ServiceOption
- type ServiceSyncResult
- type SyncStatusResult
Constants ¶
const ( AppKey contextKey = "app" ContainerKey contextKey = "container" )
Variables ¶
var ( // Version is the semantic version (e.g., "1.0.0" or "0.0.1") Version = "dev" // GitCommit is the git commit SHA GitCommit = "unknown" // GitBranch is the git branch name GitBranch = "unknown" // GitTag is the git tag (if building from a tag) GitTag = "" // BuildDate is the build timestamp BuildDate = "unknown" )
Build information variables set at compile time via ldflags
Functions ¶
func ExecuteWithContext ¶
ExecuteWithContext runs the root command with a context containing the DI container.
Inputs:
- ctx: Context containing the DI container
- version: The version string for the application.
Outputs:
- error: An error if one occurred during execution.
func GetContainer ¶
GetContainer retrieves the DI container from the context
func NewBuiltinRootCmd ¶
NewBuiltinRootCmd returns a fresh, deterministic command tree containing only commands built into the CLI. Production adds external plugins separately.
func NewClusterCmd ¶
NewClusterCmd creates the top-level "cluster" command. It has several subcommands defined in separate files. Running "opencenter cluster" without subcommand prints help.
func NewPluginsCmd ¶
func NewSecretsCmd ¶
func NewSecretsKeysCmd ¶
NewSecretsKeysCmd creates the keys subcommand group for secrets management
func NewSettingsCmd ¶
NewSettingsCmd creates the top-level "settings" command for CLI settings management. It provides subcommands for viewing, setting, getting, resetting, and locating the CLI settings file.
func NewShellInitCmd ¶
Types ¶
type ClusterMetadata ¶
type ClusterMetadata struct {
Name string `yaml:"name"`
Environment string `yaml:"env"`
Region string `yaml:"region"`
Status string `yaml:"status"`
Organization string `yaml:"organization"`
}
ClusterMetadata represents cluster metadata for display in cluster use.
type ClusterSelectOutput ¶
type ClusterSelectOutput struct {
Metadata ClusterMetadata
Paths *paths.ClusterPaths
ExportCommands []string
GitOpsInfo GitOpsInfo
Shell string
}
ClusterSelectOutput represents the complete output for cluster use command.
type CreationRule ¶
type CreationRule struct {
PathRegex string `yaml:"path_regex,omitempty"`
EncryptedRegex string `yaml:"encrypted_regex,omitempty"`
Age string `yaml:"age,omitempty"`
PGP string `yaml:"pgp,omitempty"`
KMS string `yaml:"kms,omitempty"`
AzureKV string `yaml:"azure_kv,omitempty"`
GCPKMS string `yaml:"gcp_kms,omitempty"`
HashiCorpVault string `yaml:"hc_vault,omitempty"`
}
CreationRule represents a SOPS creation rule
type FluxKustomization ¶
FluxKustomization represents a Flux Kustomization resource
type GitOpsInfo ¶
type GitOpsInfo struct {
GitDir string
ApplicationsDir string
InfrastructureDir string
SecretsDir string
}
GitOpsInfo represents GitOps repository information.
type GlobalFlags ¶
type GlobalFlags struct {
Config string // legacy alternative cluster configuration file path
DryRun bool // --dry-run: enable dry-run mode
LogLevel string // --log-level: set log level explicitly
Set []string // legacy configuration overrides using dot notation
ShowActive bool // legacy active-cluster display toggle
BreakLock bool // --break-lock: force removal of existing lock before operation
}
GlobalFlags represents the global flags available across all commands.
type GlobalOptions ¶
type LockAcquisitionResult ¶
type LockAcquisitionResult struct {
Lock resilience.Lock
LockManager resilience.LockManager
ExistingLock *resilience.LockState
WasBroken bool
UserConfirmed bool
}
LockAcquisitionResult contains the result of attempting to acquire a lock
func AcquireLockWithPrompt ¶
func AcquireLockWithPrompt(ctx context.Context, cmd *cobra.Command, resource string, operation string, ttl time.Duration, metadata map[string]string) (*LockAcquisitionResult, error)
AcquireLockWithPrompt attempts to acquire a lock on a cluster resource. If a lock already exists, it checks the --break-lock flag or prompts the user for confirmation before breaking the lock.
Parameters:
- ctx: Context for the operation
- cmd: The cobra command (for flags and I/O)
- resource: The resource name to lock (typically cluster name)
- operation: Description of the operation (e.g., "destroy", "bootstrap")
- ttl: Time-to-live for the lock
- metadata: Additional metadata to store with the lock
Returns:
- *LockAcquisitionResult: Contains the acquired lock and related info
- error: An error if lock acquisition fails
type OutputFormat ¶
type OutputFormat string
const ( OutputText OutputFormat = "text" OutputJSON OutputFormat = "json" OutputYAML OutputFormat = "yaml" )
type SOPSConfig ¶
type SOPSConfig struct {
CreationRules []CreationRule `yaml:"creation_rules"`
}
SOPSConfig represents the structure of .sops.yaml
type SOPSPathMatcher ¶
type SOPSPathMatcher struct {
// contains filtered or unexported fields
}
SOPSPathMatcher handles path matching based on SOPS configuration
func NewSOPSPathMatcher ¶
func NewSOPSPathMatcher(configPath string) (*SOPSPathMatcher, error)
NewSOPSPathMatcher creates a new path matcher from SOPS configuration
func (*SOPSPathMatcher) ShouldEncryptPath ¶
func (m *SOPSPathMatcher) ShouldEncryptPath(path string) bool
ShouldEncryptPath checks if a path should be encrypted based on SOPS rules
func (*SOPSPathMatcher) ShouldSkipPath ¶
func (m *SOPSPathMatcher) ShouldSkipPath(path string) bool
ShouldSkipPath checks if a path should be skipped (excluded from encryption)
type SOPSPathRule ¶
type SOPSPathRule struct {
// contains filtered or unexported fields
}
SOPSPathRule represents a compiled SOPS creation rule
type ServiceOption ¶
ServiceOption represents a configuration option for a service
type ServiceSyncResult ¶
type ServiceSyncResult struct {
Name string `json:"name"`
OldStatus string `json:"old_status"`
NewStatus string `json:"new_status"`
Changed bool `json:"changed"`
Error string `json:"error,omitempty"`
}
ServiceSyncResult holds the result of syncing a single service's status.
type SyncStatusResult ¶
type SyncStatusResult struct {
ClusterName string `json:"cluster_name"`
ServicesTotal int `json:"services_total"`
Servicessynced int `json:"services_synced"`
ServicesFailed int `json:"services_failed"`
Results []ServiceSyncResult `json:"results"`
}
SyncStatusResult holds the overall result of the sync-status operation.
Source Files
¶
- cluster.go
- cluster_active.go
- cluster_backup.go
- cluster_check_keys.go
- cluster_configure.go
- cluster_deploy.go
- cluster_deploy_plan.go
- cluster_describe.go
- cluster_destroy.go
- cluster_doctor.go
- cluster_drift.go
- cluster_edit.go
- cluster_env.go
- cluster_export.go
- cluster_generate.go
- cluster_import.go
- cluster_init.go
- cluster_list.go
- cluster_lock.go
- cluster_migrate_layout.go
- cluster_normalize.go
- cluster_observe.go
- cluster_pool.go
- cluster_promotion.go
- cluster_provider.go
- cluster_provider_openstack.go
- cluster_render.go
- cluster_revoke_key.go
- cluster_rotate_keys.go
- cluster_service.go
- cluster_service_storage.go
- cluster_set.go
- cluster_status.go
- cluster_status_inventory.go
- cluster_status_readiness.go
- cluster_sync_status.go
- cluster_template.go
- cluster_use.go
- cluster_validate.go
- cluster_validate_manifests.go
- config.go
- config_assignment.go
- config_edit.go
- config_explain.go
- config_helpers.go
- config_ide.go
- deploy_prerequisites.go
- doc.go
- exit_codes.go
- global_options.go
- output_helpers.go
- plugins.go
- provider_availability.go
- root.go
- secrets.go
- secrets_file_backend.go
- secrets_helpers.go
- secrets_keys.go
- secrets_keys_ops.go
- secrets_keys_reconcile.go
- secrets_keys_set_primary.go
- secrets_login.go
- secrets_router.go
- secrets_sops.go
- secrets_sops_helpers.go
- secrets_sync.go
- secrets_validate.go
- shell_init.go
- version.go