runs

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// StoryRunFinalizer is the finalizer for StoryRun resources
	StoryRunFinalizer = "storyrun.bubustack.io/finalizer"
	// DefaultMaxInlineInputsSize is the default maximum size for inline inputs (5 KB).
	// This provides a safe fallback if webhooks are disabled and no operator config is set.
	// It's a balance between preventing etcd bloat and allowing reasonable input sizes.
	DefaultMaxInlineInputsSize = 5 * 1024
)

formatDuration formats a duration in a human-readable way e.g., "10m 13s" instead of "10m13.972016716s"

View Source
const (
	// StepRunFinalizer is the finalizer for StepRun resources
	StepRunFinalizer = "steprun.bubustack.io/finalizer"
)

Variables

This section is empty.

Functions

func UpdateTimeoutAndRetry added in v0.1.4

func UpdateTimeoutAndRetry(
	stepRun *runsv1alpha1.StepRun,
	timeout string,
	retry *bubuv1alpha1.RetryPolicy,
) (timeoutChanged, retryChanged bool)

UpdateTimeoutAndRetry mutates the StepRun spec with the provided timeout and retry settings. It returns booleans indicating whether each field changed.

Types

type DAGReconciler

type DAGReconciler struct {
	client.Client
	TemplateEvaluator *templating.Evaluator
	StepExecutor      *StepExecutor
	ConfigResolver    *config.Resolver
}

DAGReconciler is responsible for the core workflow orchestration of a StoryRun.

func NewDAGReconciler

func NewDAGReconciler(deps DAGReconcilerDeps) *DAGReconciler

NewDAGReconciler returns a DAGReconciler backed by the controller-runtime client, Template evaluator, StepExecutor, and config resolver supplied by SetupWithManager (internal/controller/runs/dag.go:47-63; internal/controller/runs/storyrun_controller.go:536-549). Behavior:

  • Reuses the manager client so DAG helpers can List/Get StepRuns via the cache.
  • Shares the StepExecutor and template evaluator with StoryRun reconciliation to keep execution semantics aligned.

Arguments:

  • deps DAGReconcilerDeps: groups the cache-aware client, template evaluator, StepExecutor, and config resolver.

Returns:

  • *DAGReconciler ready for registration via `SetupWithManager`.

Side Effects:

  • None; simply packages existing collaborators.

Notes / Gotchas:

  • All arguments should be non-nil; nil collaborators will panic when DAG reconciliation dereferences them.

func (*DAGReconciler) Reconcile

func (r *DAGReconciler) Reconcile(ctx context.Context, srun *runsv1alpha1.StoryRun, story *bubuv1alpha1.Story) (ctrl.Result, error)

Reconcile orchestrates the execution of the StoryRun's DAG.

Behavior:

  • Initializes StepStates map if nil.
  • Syncs StepRun phases into StoryRun.Status.StepStates.
  • Collects prior step outputs for template evaluation.
  • Iterates the DAG: refreshes sub-stories, checks completion/failure, persists state, and launches ready steps until no progress is made.
  • Updates running duration and requeues while the StoryRun is active.

Arguments:

  • ctx context.Context: propagated to all client calls and helpers.
  • srun *runsv1alpha1.StoryRun: the StoryRun being orchestrated.
  • story *bubuv1alpha1.Story: the Story definition containing step DAG.

Returns:

  • ctrl.Result: contains RequeueAfter when StoryRun is still running.
  • error: non-nil on sync/launch/persist failures.

Side Effects:

  • Creates/updates StepRuns via StepExecutor.
  • Patches StoryRun status (StepStates, Duration, Phase).
  • Emits DAG iteration metrics.

type DAGReconcilerDeps added in v0.1.4

type DAGReconcilerDeps struct {
	Client            client.Client
	TemplateEvaluator *templating.Evaluator
	StepExecutor      *StepExecutor
	ConfigResolver    *config.Resolver
}

DAGReconcilerDeps bundles the collaborators required to construct a DAGReconciler.

type EffectClaimReconciler added in v0.1.4

type EffectClaimReconciler struct {
	client.Client
	APIReader client.Reader
	Scheme    *runtime.Scheme
}

EffectClaimReconciler reconciles an EffectClaim object.

func (*EffectClaimReconciler) Reconcile added in v0.1.4

func (r *EffectClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile keeps EffectClaim status canonical and ties retention to the owning StepRun.

func (*EffectClaimReconciler) SetupWithManager added in v0.1.4

func (r *EffectClaimReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error

SetupWithManager sets up the controller with the Manager.

type RBACManager

type RBACManager struct {
	client.Client
	Scheme   *runtime.Scheme
	Recorder events.EventRecorder
}

RBACManager handles the reconciliation of RBAC resources for a StoryRun.

func NewRBACManager

func NewRBACManager(k8sClient client.Client, scheme *runtime.Scheme) *RBACManager

NewRBACManager creates a new RBACManager.

Behavior:

  • Wraps the provided client and scheme for RBAC resource management.

Arguments:

  • k8sClient client.Client: Kubernetes client for CRUD operations.
  • scheme *runtime.Scheme: scheme for owner reference handling.

Returns:

  • *RBACManager: ready for RBAC reconciliation.

func (*RBACManager) Reconcile

func (r *RBACManager) Reconcile(ctx context.Context, storyRun *runsv1alpha1.StoryRun) error

Reconcile ensures the necessary ServiceAccount, Role, and RoleBinding exist for the StoryRun.

Behavior:

  • Fetches the parent Story for storage annotations (ignores NotFound).
  • Reconciles ServiceAccount, Role, and RoleBinding with StoryRun as owner.
  • Reconciles additional RoleBindings requested by Engram templates/overrides.

Arguments:

  • ctx context.Context: propagated to all client operations.
  • storyRun *runsv1alpha1.StoryRun: the StoryRun requiring RBAC.

Returns:

  • error: nil on success, or first encountered error.

Side Effects:

  • Creates/updates SA, Role, and RoleBinding in StoryRun namespace.
  • Logs operations and emits Kubernetes events.

type StepExecutor

type StepExecutor struct {
	client.Client
	Scheme            *runtime.Scheme
	TemplateEvaluator *templating.Evaluator
	ConfigResolver    *config.Resolver
	Recorder          events.EventRecorder
}

StepExecutor is responsible for executing individual steps in a StoryRun.

func NewStepExecutor

func NewStepExecutor(k8sClient client.Client, scheme *runtime.Scheme, templateEval *templating.Evaluator, cfgResolver *config.Resolver, recorder events.EventRecorder) *StepExecutor

NewStepExecutor creates a new StepExecutor.

Behavior:

  • Wraps the provided dependencies for step execution.

Arguments:

  • k8sClient client.Client: Kubernetes client for CRUD operations.
  • scheme *runtime.Scheme: scheme for owner references.
  • templateEval *templating.Evaluator: template evaluator for expression resolution.
  • cfgResolver *config.Resolver: configuration resolver.
  • recorder events.EventRecorder: event recorder for emitting events.

Returns:

  • *StepExecutor: ready for step execution.

func (*StepExecutor) Execute

func (e *StepExecutor) Execute(ctx context.Context, srun *runsv1alpha1.StoryRun, story *bubuv1alpha1.Story, step *bubuv1alpha1.Step, vars map[string]any) (err error)

Execute determines the step type and calls the appropriate execution method.

Behavior:

  • Initializes StepStates if needed.
  • Dispatches to type-specific executors based on step.Type or step.Ref.
  • Traces execution with OpenTelemetry spans.

Arguments:

  • ctx context.Context: propagated to all operations.
  • srun *runsv1alpha1.StoryRun: the parent StoryRun.
  • story *bubuv1alpha1.Story: the Story definition.
  • step *bubuv1alpha1.Step: the step to execute.
  • vars map[string]any: variable context for template evaluation.

Returns:

  • error: nil on success, or execution errors.

Side Effects:

  • Creates/updates StepRuns based on step type.
  • Updates srun.Status.StepStates for primitive steps.

type StepRunReconciler

type StepRunReconciler struct {
	config.ControllerDependencies
	Recorder events.EventRecorder
}

StepRunReconciler reconciles a StepRun object

func (*StepRunReconciler) Reconcile

func (r *StepRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error)

Reconcile is the main entry point for StepRun reconciliation. For more details, check Reconcile and its Result here: - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.23.0/pkg/reconcile

Behavior:

  • Applies optional reconcile timeout from operator config.
  • Fetches StepRun and ignores NotFound.
  • Handles deletion if DeletionTimestamp set.
  • Ensures finalizer is present.
  • Routes to reconcileNormal for non-terminal phases.

Arguments:

  • ctx context.Context: for API calls and cancellation.
  • req ctrl.Request: the reconcile request with StepRun name.

Returns:

  • ctrl.Result: may include requeue or delay.
  • error: non-nil on failures.

func (*StepRunReconciler) SetupWithManager

func (r *StepRunReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error

SetupWithManager configures the controller with watches and predicates.

Behavior:

  • Watches StepRun, Job, Deployment, Service, TransportBinding.
  • Maps Engram and EngramTemplate changes to affected StepRuns.

Arguments:

  • mgr ctrl.Manager: the controller-runtime manager.
  • opts controller.Options: controller options.

Returns:

  • error: non-nil on setup failure.

type StoryRunReconciler

type StoryRunReconciler struct {
	config.ControllerDependencies

	Recorder events.EventRecorder
	// contains filtered or unexported fields
}

StoryRunReconciler reconciles a StoryRun object

func (*StoryRunReconciler) Reconcile

func (r *StoryRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error)

Reconcile is the main entry point for StoryRun reconciliation. For more details, check Reconcile and its Result here: - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.23.0/pkg/reconcile

Behavior:

  • Applies optional reconcile timeout from operator config.
  • Guards against oversized inputs.
  • Handles deletion if needed.
  • Ensures finalizer and RBAC are configured.
  • Routes to DAG reconciliation for non-terminal phases.

Arguments:

  • ctx context.Context: for API calls and cancellation.
  • req ctrl.Request: the reconcile request.

Returns:

  • ctrl.Result: reconcile result with possible requeue.
  • error: non-nil on failures.

func (*StoryRunReconciler) SetupWithManager

func (r *StoryRunReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error

SetupWithManager configures the controller with watches and predicates.

Behavior:

  • Initializes RBAC manager, step executor, and DAG reconciler.
  • Watches StoryRun and owned StepRun resources.

Arguments:

  • mgr ctrl.Manager: the controller-runtime manager.
  • opts controller.Options: controller options.

Returns:

  • error: non-nil on setup failure.

type StoryTriggerReconciler added in v0.1.4

type StoryTriggerReconciler struct {
	client.Client
	APIReader      client.Reader
	Scheme         *runtime.Scheme
	ConfigResolver *config.Resolver
}

StoryTriggerReconciler reconciles a StoryTrigger object

func (*StoryTriggerReconciler) Reconcile added in v0.1.4

func (r *StoryTriggerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is part of the main kubernetes reconciliation loop which aims to move the current state of the cluster closer to the desired state.

func (*StoryTriggerReconciler) SetupWithManager added in v0.1.4

func (r *StoryTriggerReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error

SetupWithManager sets up the controller with the Manager.

Jump to

Keyboard shortcuts

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