cmd

package
v1.0.0-rc07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 74 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	AppKey       contextKey = "app"
	ContainerKey contextKey = "container"
)

Variables

View Source
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

func ExecuteWithContext(ctx context.Context, version string) error

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 ExitCode

func ExitCode(err error) int

ExitCode maps command errors to the CLI process contract.

func GetApp

func GetApp(ctx context.Context) (*di.App, error)

GetApp retrieves the typed application graph from the context.

func GetContainer

func GetContainer(ctx context.Context) (di.Container, error)

GetContainer retrieves the DI container from the context

func GetRootCmd

func GetRootCmd() *cobra.Command

GetRootCmd returns the root cobra command.

func NewBuiltinRootCmd

func NewBuiltinRootCmd() *cobra.Command

NewBuiltinRootCmd returns a fresh, deterministic command tree containing only commands built into the CLI. Production adds external plugins separately.

func NewClusterCmd

func NewClusterCmd() *cobra.Command

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 NewPluginsCmd() *cobra.Command

func NewSecretsCmd

func NewSecretsCmd() *cobra.Command

func NewSecretsKeysCmd

func NewSecretsKeysCmd() *cobra.Command

NewSecretsKeysCmd creates the keys subcommand group for secrets management

func NewSettingsCmd

func NewSettingsCmd() *cobra.Command

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

func NewShellInitCmd() *cobra.Command

func NewVersionCmd

func NewVersionCmd() *cobra.Command

NewVersionCmd creates the version command

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 ExitError

type ExitError struct {
	Code    int
	Message string
	Err     error
}

ExitError carries a user-facing error category and its process exit code.

func NewExitError

func NewExitError(code int, message string, cause error) *ExitError

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type FluxKustomization

type FluxKustomization struct {
	Name      string
	Namespace string
	Ready     bool
	Message   string
}

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 GlobalOptions struct {
	ConfigDir string
	LogLevel  string
	Output    OutputFormat
	Quiet     bool
	Yes       bool
	DryRun    bool
}

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

type ServiceOption struct {
	Name        string
	Type        string
	Description string
	Required    bool
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL