feature

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package feature provides mechanisms for version-gated feature mutations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 MutationFeature
	// 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 MutationFeature added in v0.2.0

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

MutationFeature is an optional feature gate for a Mutation. If Enabled returns false, the mutation is not applied.

type ResourceFeature

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

ResourceFeature represents the conditions under which a feature mutation applies.

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

func NewResourceFeature

func NewResourceFeature(currentVersion string, versionConstraints []VersionConstraint) *ResourceFeature

NewResourceFeature creates a new ResourceFeature for the given current version and semver constraints.

Nil constraints are ignored.

func (*ResourceFeature) Enabled

func (f *ResourceFeature) Enabled() (bool, error)

Enabled reports whether the feature should apply.

A feature is enabled only if: - all When conditions are true - all version constraints match the current version.

func (*ResourceFeature) When

func (f *ResourceFeature) When(truth bool) *ResourceFeature

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

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

type VersionConstraint

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

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

Jump to

Keyboard shortcuts

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