phase

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package phase provides phase constants and state machine logic for SignalProcessing. Phase constants are exported from the API package (api/signalprocessing/v1alpha1) for external consumer usage per the Viceversa Pattern.

This package re-exports them for internal SP convenience and provides state machine logic (IsTerminal, CanTransition, Validate).

Reference: CONTROLLER_REFACTORING_PATTERN_LIBRARY.md - Pattern 1 (Phase State Machine)

Index

Constants

View Source
const (
	// Pending is the initial state when SignalProcessing is created.
	Pending = signalprocessingv1alpha1.PhasePending

	// Enriching is when K8s context enrichment is in progress.
	// Business Requirements: BR-SP-001 (K8s Context), BR-SP-100 (Owner Chain)
	Enriching = signalprocessingv1alpha1.PhaseEnriching

	// Classifying is when environment/priority classification is in progress.
	// Business Requirements: BR-SP-051-053 (Environment), BR-SP-070-072 (Priority)
	Classifying = signalprocessingv1alpha1.PhaseClassifying

	// Categorizing is when business categorization is in progress.
	// Business Requirements: BR-SP-002, BR-SP-080, BR-SP-081
	Categorizing = signalprocessingv1alpha1.PhaseCategorizing

	// Completed is the terminal success state.
	Completed = signalprocessingv1alpha1.PhaseCompleted

	// Failed is the terminal error state.
	Failed = signalprocessingv1alpha1.PhaseFailed
)

Re-export API constants for internal SP convenience. External consumers should import from api/signalprocessing/v1alpha1 directly.

Variables

ValidTransitions defines the state machine. Key: current phase, Value: list of valid target phases

State Machine Flow:

Pending → Enriching → Classifying → Categorizing → Completed
               ↓            ↓             ↓
             Failed       Failed        Failed

Reference: CONTROLLER_REFACTORING_PATTERN_LIBRARY.md - Pattern 1 (Phase State Machine)

Functions

func CanTransition

func CanTransition(current, target Phase) bool

CanTransition checks if transition from current to target is valid. Returns true if the transition is allowed by the state machine, false otherwise.

Example:

phase.CanTransition(phase.Pending, phase.Enriching)      // true
phase.CanTransition(phase.Pending, phase.Classifying)    // false (skip not allowed)
phase.CanTransition(phase.Completed, phase.Enriching)    // false (terminal state)

func IsTerminal

func IsTerminal(p Phase) bool

IsTerminal returns true if the phase is a terminal state. Terminal states prevent further reconciliation.

Reference: CONTROLLER_REFACTORING_PATTERN_LIBRARY.md - Pattern 2 (Terminal State Logic)

func Validate

func Validate(p Phase) error

Validate checks if a phase value is valid. Returns an error if the phase is not recognized.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages phase transitions with validation. Reference: CONTROLLER_REFACTORING_PATTERN_LIBRARY.md - Pattern 1 (Phase State Machine)

TODO: Complete phase manager implementation (Phase 2 refactoring) - Implement TransitionTo with state machine validation - Add atomic status update integration - Add phase transition audit event recording - Update controller to use Manager.TransitionTo instead of direct status updates - Add comprehensive unit tests for all phase transitions

Estimated effort: 1-2 days Expected benefits: Centralized phase transition logic, runtime validation, audit integration

func NewManager

func NewManager(client client.Client, scheme *runtime.Scheme) *Manager

NewManager creates a new phase manager.

func (*Manager) CurrentPhase

CurrentPhase returns the current phase of the SignalProcessing.

func (*Manager) TransitionTo

func (m *Manager) TransitionTo(
	ctx context.Context,
	sp *signalprocessingv1alpha1.SignalProcessing,
	targetPhase Phase,
	reason, message string,
) error

TransitionTo transitions the SignalProcessing to a new phase with validation. Returns an error if the transition is invalid or the status update fails.

TODO: Complete implementation - Validate transition using CanTransition() - Update status.Phase atomically - Record phase transition audit event - Update lastTransitionTime - Set appropriate conditions

Example usage:

err := m.TransitionTo(ctx, sp, phase.Enriching, "EnrichmentStarted", "K8s context enrichment initiated")

type Phase

Phase is an alias for the API-exported SignalProcessingPhase type. This allows internal SP code to continue using `phase.Phase` without changes.

🏛️ Single Source of Truth: api/signalprocessing/v1alpha1/SignalProcessingPhase

Jump to

Keyboard shortcuts

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