task

package
v0.7.1 Latest Latest
Warning

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

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

Documentation

Overview

Package task provides an unstructured resource primitive for Kubernetes objects that run to completion, requiring completion status tracking and suspension support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is a configuration helper for creating and customizing an unstructured task Resource.

It provides a fluent API for registering mutations, status handlers, and data extractors. The converging status handler is required; all other handlers default to safe no-ops when omitted.

func NewBuilder

func NewBuilder(obj *uns.Unstructured) *Builder

NewBuilder initializes a new Builder with the provided unstructured object.

The object serves as the desired base state. The converging status handler must be set via WithCustomConvergeStatus before Build(). All other handlers are optional.

func (*Builder) Build

func (b *Builder) Build() (*Resource, error)

Build validates the configuration and returns the initialized Resource.

It returns an error if the converging status handler has not been set.

func (*Builder) MarkClusterScoped

func (b *Builder) MarkClusterScoped() *Builder

MarkClusterScoped marks the resource as cluster-scoped.

func (*Builder) WithCustomConvergeStatus

func (b *Builder) WithCustomConvergeStatus(
	handler func(concepts.ConvergingOperation, *uns.Unstructured) (concepts.CompletionStatusWithReason, error),
) *Builder

WithCustomConvergeStatus sets the handler that evaluates whether the resource has completed. This handler is required.

func (*Builder) WithCustomSuspendDeletionDecision

func (b *Builder) WithCustomSuspendDeletionDecision(
	handler func(*uns.Unstructured) bool,
) *Builder

WithCustomSuspendDeletionDecision overrides the default delete-on-suspend decision. The default returns false (keep the resource).

func (*Builder) WithCustomSuspendMutation

func (b *Builder) WithCustomSuspendMutation(
	handler func(*unstruct.Mutator) error,
) *Builder

WithCustomSuspendMutation overrides the default suspension mutation handler. The default is a no-op.

func (*Builder) WithCustomSuspendStatus

func (b *Builder) WithCustomSuspendStatus(
	handler func(*uns.Unstructured) (concepts.SuspensionStatusWithReason, error),
) *Builder

WithCustomSuspendStatus overrides the default suspension status handler. The default reports Suspended immediately.

func (*Builder) WithDataExtractor

func (b *Builder) WithDataExtractor(extractor func(uns.Unstructured) error) *Builder

WithDataExtractor registers a function to read values from the object after it has been successfully reconciled.

func (*Builder) WithGuard added in v0.4.0

func (b *Builder) WithGuard(guard func(uns.Unstructured) (concepts.GuardStatusWithReason, error)) *Builder

WithGuard registers a guard precondition that is evaluated before the object is applied during reconciliation. If the guard returns Blocked, the object and all resources registered after it are skipped until the guard clears. Passing nil clears any previously registered guard.

func (*Builder) WithMutation

func (b *Builder) WithMutation(m unstruct.Mutation) *Builder

WithMutation registers a mutation for the unstructured object.

type Resource

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

Resource is a high-level abstraction for managing an unstructured Kubernetes task object within a controller's reconciliation loop.

It implements the following interfaces:

  • component.Resource: for basic identity and mutation behaviour.
  • concepts.Completable: for completion status tracking.
  • concepts.Suspendable: for graceful deactivation.
  • concepts.Guardable: for conditional reconciliation based on a guard precondition.
  • concepts.DataExtractable: for exporting values after successful reconciliation.

The converging status handler is required; all other handlers default to safe no-ops when omitted.

func (*Resource) ConvergingStatus

ConvergingStatus reports the resource's completion status.

func (*Resource) DeleteOnSuspend

func (r *Resource) DeleteOnSuspend() bool

DeleteOnSuspend determines whether the resource should be deleted from the cluster when the parent component is suspended.

func (*Resource) ExtractData

func (r *Resource) ExtractData() error

ExtractData executes all registered data extractor functions against a deep copy of the reconciled object.

func (*Resource) GuardStatus added in v0.4.0

func (r *Resource) GuardStatus() (concepts.GuardStatusWithReason, error)

GuardStatus evaluates the resource's guard precondition. If no guard was registered, the resource is unconditionally unblocked.

func (*Resource) Identity

func (r *Resource) Identity() string

Identity returns a unique identifier for the resource derived from its GVK, namespace, and name.

func (*Resource) Mutate

func (r *Resource) Mutate(current client.Object) error

Mutate transforms the current state of the unstructured object into the desired state by applying all registered feature mutations and any active suspension mutation.

func (*Resource) Object

func (r *Resource) Object() (client.Object, error)

Object returns a deep copy of the underlying unstructured Kubernetes object.

func (*Resource) PreviewObject added in v0.6.0

func (r *Resource) PreviewObject() (*uns.Unstructured, error)

PreviewObject returns the object as it would appear after feature mutations have been applied, without modifying the resource's internal state.

Suspension mutations are not applied; the preview reflects content state only.

func (*Resource) Suspend

func (r *Resource) Suspend() error

Suspend triggers the deactivation of the resource by registering a mutation that will be executed during the next Mutate call.

func (*Resource) SuspensionStatus

func (r *Resource) SuspensionStatus() (concepts.SuspensionStatusWithReason, error)

SuspensionStatus monitors the progress of the suspension process.

Jump to

Keyboard shortcuts

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