conditional

package
v1.16.1 Latest Latest
Warning

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

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

README

pkg/provisioners/conditional

Intention

pkg/provisioners/conditional is a small provisioner combinator for optional subordinate resources. It gates a child provisioner behind a predicate, but the key behavior is stronger than simple skipping: when the predicate is false, the child is actively deprovisioned.

This makes the package useful for feature- or capability-dependent child provisioners where the desired state is binary:

  • predicate true: the child should exist
  • predicate false: the child should not exist

Invariants And Guard Rails

  • Provision(ctx) does not mean "try to provision if enabled and otherwise do nothing". It means "drive the child to the desired existence state for the current predicate value."
  • If the predicate is true, Provision(ctx) delegates to the child provisioner's Provision(ctx).
  • If the predicate is false, Provision(ctx) delegates to the child provisioner's Deprovision(ctx).
  • Deprovision(ctx) always delegates to the child provisioner's Deprovision(ctx), regardless of predicate value, so cleanup still happens during parent teardown even when the child was conditionally disabled.
  • This combinator is appropriate when predicate false really means the child resource must not exist.

Caveats

  • The predicate is just func() bool. It carries no context, error handling, or structured explanation of why the child is enabled or disabled.
  • This package encodes removal semantics, not skip semantics. If a caller wants "disabled for now, but preserve existing child state," this is the wrong abstraction.
  • Because false maps to deprovision, callers must be deliberate about using predicates that can flap.
  • The package is intentionally tiny and does not add lifecycle policy beyond delegating to the child provisioner based on the predicate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provisioner

type Provisioner struct {
	provisioners.Metadata
	// contains filtered or unexported fields
}

func New

func New(name string, condition func() bool, provisioner provisioners.Provisioner) *Provisioner

func (*Provisioner) Deprovision

func (p *Provisioner) Deprovision(ctx context.Context) error

Deprovision implements the Provision interface.

func (*Provisioner) Provision

func (p *Provisioner) Provision(ctx context.Context) error

Provision implements the Provision interface.

Jump to

Keyboard shortcuts

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