phase

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package phase provides phase constants and state machine logic for WorkflowExecution. Phase constants are re-exported from the API package (api/workflowexecution/v1alpha1) following the Viceversa Pattern from RemediationOrchestrator.

This package provides: - Phase type alias for internal convenience - Re-exported phase constants - IsTerminal() function (P1 - Terminal State Logic pattern) - State machine logic with ValidTransitions map (P0 - Phase State Machine pattern)

Per Controller Refactoring Pattern Library: - P1: Terminal State Logic - Prevents unnecessary reconciliation - P0: Phase State Machine - Prevents invalid transitions

Reference: docs/architecture/patterns/CONTROLLER_REFACTORING_PATTERN_LIBRARY.md

Index

Constants

This section is empty.

Variables

View Source
var ValidTransitions = map[Phase][]Phase{
	Pending: {Running, Failed},
	Running: {Completed, Failed},

	Completed: {},
	Failed:    {},
}

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

Workflow Execution Flow: 1. Pending → Running (PipelineRun created) 2. Running → Completed (PipelineRun succeeded) 3. Running → Failed (PipelineRun failed or timed out)

Terminal states (Completed, Failed) have no valid transitions.

Functions

func CanTransition

func CanTransition(current, target Phase) bool

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

Example:

if phase.CanTransition(phase.Pending, phase.Running) {
    // Valid transition
}

func IsTerminal

func IsTerminal(p Phase) bool

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

Terminal phases: - Completed: Workflow executed successfully - Failed: Workflow execution failed

Non-terminal phases: - Pending: Waiting for PipelineRun creation - Running: PipelineRun actively executing

func Validate

func Validate(p Phase) error

Validate checks if a phase value is valid. Returns an error if the phase is not one of the defined constants.

Types

type Manager

type Manager struct{}

Manager implements phase state machine logic. Per Controller Refactoring Pattern Library (P0: Phase State Machine)

Reference: docs/architecture/patterns/CONTROLLER_REFACTORING_PATTERN_LIBRARY.md lines 180-221

func NewManager

func NewManager() *Manager

NewManager creates a new phase manager.

func (*Manager) CurrentPhase

CurrentPhase returns the current phase. Returns Pending if phase is empty (initial state).

func (*Manager) TransitionTo

func (m *Manager) TransitionTo(obj *workflowexecutionv1alpha1.WorkflowExecution, target Phase) error

TransitionTo transitions to the target phase. Returns an error if the transition is invalid per the state machine.

Special case: If already in target phase, this is a no-op (returns nil). This handles cases where phase is empty ("") which maps to Pending.

Example usage:

if err := phaseManager.TransitionTo(wfe, phase.Running); err != nil {
    logger.Error(err, "Invalid phase transition")
    return ctrl.Result{}, err
}

type Phase

type Phase string

Phase is an alias for the string type used in the API. This allows internal WE code to use `phase.Phase` for type safety.

🏛️ Single Source of Truth: api/workflowexecution/v1alpha1 phase constants

const (
	// Pending - Initial state when WorkflowExecution is first created
	Pending Phase = workflowexecutionv1alpha1.PhasePending

	// Running - PipelineRun is actively executing
	Running Phase = workflowexecutionv1alpha1.PhaseRunning

	// Completed - Workflow executed successfully (terminal state)
	Completed Phase = workflowexecutionv1alpha1.PhaseCompleted

	// Failed - Workflow execution failed (terminal state)
	Failed Phase = workflowexecutionv1alpha1.PhaseFailed
)

Re-export API constants for internal WE convenience. External consumers should use api/workflowexecution/v1alpha1 constants directly.

Jump to

Keyboard shortcuts

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