Documentation
¶
Overview ¶
Package rollback provides automatic and manual rollback functionality for rotation operations.
Index ¶
- Constants
- Variables
- type Config
- type Manager
- func (m *Manager) GetState(service, environment string) *StateInfo
- func (m *Manager) ManualRollback(ctx context.Context, req RollbackRequest) (*RollbackResult, error)
- func (m *Manager) Reset(service, environment string)
- func (m *Manager) TriggerRollback(ctx context.Context, req RollbackRequest) (*RollbackResult, error)
- type RollbackRequest
- type RollbackResult
- type State
- type StateInfo
- type Transition
Constants ¶
const ( // DefaultTimeout is the default timeout for rollback operations. DefaultTimeout = 30 * time.Second // DefaultMaxRetries is the default number of retry attempts for failed rollbacks. DefaultMaxRetries = 2 )
Variables ¶
var ValidTransitions = map[State][]State{ StateIdle: {StateTriggered}, StateTriggered: {StateInProgress, StateFailed}, StateInProgress: {StateVerifying, StateFailed}, StateVerifying: {StateCompleted, StateFailed}, StateCompleted: {StateIdle}, StateFailed: {StateIdle, StateTriggered}, }
ValidTransitions defines allowed state transitions.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Automatic enables automatic rollback on verification failure.
Automatic bool
// OnVerificationFailure triggers rollback when verification fails.
OnVerificationFailure bool
// OnHealthCheckFailure triggers rollback when health checks fail.
OnHealthCheckFailure bool
// Timeout is the maximum time for rollback operation.
Timeout time.Duration
// MaxRetries is the number of times to retry rollback if it fails.
MaxRetries int
// Notifications lists notification channels for rollback events.
Notifications []string
}
Config holds configuration for rollback behavior.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with default values.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates rollback operations for rotation failures.
func NewManager ¶
func NewManager(config Config, notifier *notifications.Manager) *Manager
NewManager creates a new rollback manager with the given configuration.
func (*Manager) ManualRollback ¶
func (m *Manager) ManualRollback(ctx context.Context, req RollbackRequest) (*RollbackResult, error)
ManualRollback initiates a manual rollback operation. This bypasses the automatic rollback check.
func (*Manager) Reset ¶
Reset clears the rollback state for a service/environment. This should be called after a successful rotation.
func (*Manager) TriggerRollback ¶
func (m *Manager) TriggerRollback(ctx context.Context, req RollbackRequest) (*RollbackResult, error)
TriggerRollback initiates an automatic rollback operation. This is called when verification fails after rotation.
type RollbackRequest ¶
type RollbackRequest struct {
// Service is the service to rollback.
Service string
// Environment is the environment.
Environment string
// Reason explains why rollback was triggered.
Reason string
// PreviousVersion is the version to rollback to.
PreviousVersion string
// FailedVersion is the version that failed.
FailedVersion string
// RestoreFunc is the function that restores the previous secret.
// It should return nil on success or an error on failure.
RestoreFunc func(ctx context.Context) error
// VerifyFunc is the function that verifies the restored secret works.
// It should return nil on success or an error on failure.
VerifyFunc func(ctx context.Context) error
// InitiatedBy indicates who or what initiated the rollback.
InitiatedBy string
}
RollbackRequest contains information needed to perform a rollback.
type RollbackResult ¶
type RollbackResult struct {
// Success indicates whether the rollback succeeded.
Success bool
// State is the final rollback state.
State State
// Duration is how long the rollback took.
Duration time.Duration
// Attempts is the number of attempts made.
Attempts int
// Error is the error if rollback failed.
Error error
}
RollbackResult contains the outcome of a rollback operation.
type State ¶
type State string
State represents the current state of a rollback operation.
const ( // StateIdle indicates no rollback is in progress. StateIdle State = "idle" // StateTriggered indicates a rollback has been triggered but not yet started. StateTriggered State = "triggered" // StateInProgress indicates rollback is currently executing. StateInProgress State = "in_progress" // StateVerifying indicates rollback is verifying the restored secret. StateVerifying State = "verifying" // StateCompleted indicates rollback completed successfully. StateCompleted State = "completed" // StateFailed indicates rollback failed. StateFailed State = "failed" )
func (State) CanTransitionTo ¶
CanTransitionTo checks if a transition from current state to new state is valid.
func (State) IsTerminal ¶
IsTerminal returns true if this is a terminal state (completed or failed).
type StateInfo ¶
type StateInfo struct {
// Current is the current state.
Current State
// Service is the service being rolled back.
Service string
// Environment is the environment.
Environment string
// StartedAt is when the rollback was triggered.
StartedAt time.Time
// CompletedAt is when the rollback completed (success or failure).
CompletedAt time.Time
// Reason is why the rollback was triggered.
Reason string
// Error is the error if rollback failed.
Error error
// PreviousVersion is the version being rolled back to.
PreviousVersion string
// FailedVersion is the version that failed.
FailedVersion string
// Transitions is the history of state transitions.
Transitions []Transition
// Attempts is the number of rollback attempts.
Attempts int
// contains filtered or unexported fields
}
StateInfo holds information about the current rollback state.
func NewStateInfo ¶
NewStateInfo creates a new StateInfo with initial values.
func (*StateInfo) Duration ¶
Duration returns the duration of the rollback operation. Returns 0 if the rollback has not completed.
func (*StateInfo) GetAttempts ¶
GetAttempts returns the number of attempts (thread-safe).
func (*StateInfo) GetCurrent ¶
GetCurrent returns the current state (thread-safe).
func (*StateInfo) SetVersionInfo ¶
SetVersionInfo sets version-related fields (thread-safe).