feature

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package feature provides gating mechanisms for conditional mutations and resource lifecycle control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gate added in v0.3.0

type Gate interface {
	Enabled() (bool, error)
}

Gate is an optional gate for a Mutation or resource. If Enabled returns false, the associated mutation is not applied, or the associated resource is marked for deletion.

type Mutation

type Mutation[T any] struct {
	// Name is a human-readable identifier used for error reporting.
	Name string
	// Feature gates this mutation. If nil, the mutation is applied unconditionally.
	Feature Gate
	// Mutate is the function that applies the changes to the object.
	Mutate func(T) error
}

Mutation defines a conditional mutation applied to an object of type T.

If Feature is nil the mutation is applied unconditionally on every reconciliation. If Feature is non-nil the mutation is applied only when Feature.Enabled() returns true.

func (*Mutation[T]) ApplyIntent

func (m *Mutation[T]) ApplyIntent(obj T) error

ApplyIntent applies the mutation to obj.

If Feature is nil the mutation is applied unconditionally. If Feature is non-nil and disabled, ApplyIntent returns nil without performing any action. If the mutation would be applied but Mutate is nil, it returns an error.

type VersionConstraint

type VersionConstraint interface {
	// Enabled reports whether the constraint is satisfied for the given version string.
	Enabled(version string) (bool, error)
}

VersionConstraint defines a condition based on a semantic version. Implementations should report whether the constraint is satisfied for the given version string.

type VersionGate added in v0.3.0

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

VersionGate is a Gate implementation that combines semantic version constraints with boolean conditions.

A VersionGate is enabled only when all registered semver constraints match the current version and all additional truth conditions added via When are true.

func NewVersionGate added in v0.3.0

func NewVersionGate(currentVersion string, versionConstraints []VersionConstraint) *VersionGate

NewVersionGate creates a new VersionGate for the given current version and semver constraints.

Nil constraints are ignored.

func (*VersionGate) Enabled added in v0.3.0

func (v *VersionGate) Enabled() (bool, error)

Enabled reports whether the gate is enabled.

The gate is enabled only if:

  • all When conditions are true
  • all version constraints match the current version.

func (*VersionGate) When added in v0.3.0

func (v *VersionGate) When(truth bool) *VersionGate

When adds a boolean condition that must be true for the gate to be enabled.

Calls are additive: all values passed through When must be true for Enabled() to return true.

Jump to

Keyboard shortcuts

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